cluster.go 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288
  1. package types
  2. import (
  3. "github.com/porter-dev/porter/internal/kubernetes/prometheus"
  4. )
  5. const (
  6. URLParamCandidateID URLParam = "candidate_id"
  7. URLParamNodeName URLParam = "node_name"
  8. )
  9. type Cluster struct {
  10. ID uint `json:"id"`
  11. // The project that this integration belongs to
  12. ProjectID uint `json:"project_id"`
  13. // Name of the cluster
  14. Name string `json:"name"`
  15. // Server endpoint for the cluster
  16. Server string `json:"server"`
  17. // The integration service for this cluster
  18. Service ClusterService `json:"service"`
  19. // The infra id, if cluster was provisioned with Porter
  20. InfraID uint `json:"infra_id"`
  21. // (optional) The aws integration id, if available
  22. AWSIntegrationID uint `json:"aws_integration_id"`
  23. // (optional) The aws cluster id, if available
  24. AWSClusterID string `json:"aws_cluster_id,omitempty"`
  25. }
  26. type ClusterCandidate struct {
  27. ID uint `json:"id"`
  28. // The project that this integration belongs to
  29. ProjectID uint `json:"project_id"`
  30. // CreatedClusterID is the ID of the cluster that's eventually
  31. // created
  32. CreatedClusterID uint `json:"created_cluster_id"`
  33. // Name of the cluster
  34. Name string `json:"name"`
  35. // Server endpoint for the cluster
  36. Server string `json:"server"`
  37. // Name of the context that this was created from, if it exists
  38. ContextName string `json:"context_name"`
  39. // Resolvers are the list of resolvers: once all resolvers are "resolved," the
  40. // cluster will be created
  41. Resolvers []ClusterResolver `json:"resolvers"`
  42. // The best-guess for the AWSClusterID, which is required by aws auth mechanisms
  43. // See https://github.com/kubernetes-sigs/aws-iam-authenticator#what-is-a-cluster-id
  44. AWSClusterIDGuess string `json:"aws_cluster_id_guess"`
  45. }
  46. type ClusterResolver struct {
  47. ID uint `json:"id"`
  48. // The ClusterCandidate that this is resolving
  49. ClusterCandidateID uint `json:"cluster_candidate_id"`
  50. // One of the ClusterResolverNames
  51. Name ClusterResolverName `json:"name"`
  52. // Resolved is true if this has been resolved, false otherwise
  53. Resolved bool `json:"resolved"`
  54. // Docs is a link to documentation that helps resolve this manually
  55. Docs string `json:"docs"`
  56. // Fields is a list of fields that must be sent with the resolving request
  57. Fields string `json:"fields"`
  58. // Data is additional data for resolving the action, for example a file name,
  59. // context name, etc
  60. Data ClusterResolverData `json:"data,omitempty"`
  61. }
  62. // ClusterResolverAll is a helper type that contains the fields for
  63. // all possible resolvers, so that raw bytes can be unmarshaled in a single
  64. // read
  65. type ClusterResolverAll struct {
  66. ClusterCAData string `json:"cluster_ca_data,omitempty"`
  67. ClusterHostname string `json:"cluster_hostname,omitempty"`
  68. ClientCertData string `json:"client_cert_data,omitempty"`
  69. ClientKeyData string `json:"client_key_data,omitempty"`
  70. OIDCIssuerCAData string `json:"oidc_idp_issuer_ca_data,omitempty"`
  71. TokenData string `json:"token_data,omitempty"`
  72. GCPKeyData string `json:"gcp_key_data,omitempty"`
  73. AWSAccessKeyID string `json:"aws_access_key_id"`
  74. AWSSecretAccessKey string `json:"aws_secret_access_key"`
  75. AWSClusterID string `json:"aws_cluster_id"`
  76. }
  77. // ClusterResolverInfo contains the information for actions to be
  78. // performed in order to initialize a cluster
  79. type ClusterResolverInfo struct {
  80. // Docs is a link to documentation that helps resolve this manually
  81. Docs string `json:"docs"`
  82. // a comma-separated list of required fields to send in an action request
  83. Fields string `json:"fields"`
  84. }
  85. // ClusterResolverInfos is a map of the information for actions to be
  86. // performed in order to initialize a cluster
  87. var ClusterResolverInfos = map[ClusterResolverName]ClusterResolverInfo{
  88. ClusterCAData: {
  89. Docs: "https://github.com/porter-dev/porter",
  90. Fields: "cluster_ca_data",
  91. },
  92. ClusterLocalhost: {
  93. Docs: "https://github.com/porter-dev/porter",
  94. Fields: "cluster_hostname",
  95. },
  96. ClientCertData: {
  97. Docs: "https://github.com/porter-dev/porter",
  98. Fields: "client_cert_data",
  99. },
  100. ClientKeyData: {
  101. Docs: "https://github.com/porter-dev/porter",
  102. Fields: "client_key_data",
  103. },
  104. OIDCIssuerData: {
  105. Docs: "https://github.com/porter-dev/porter",
  106. Fields: "oidc_idp_issuer_ca_data",
  107. },
  108. TokenData: {
  109. Docs: "https://github.com/porter-dev/porter",
  110. Fields: "token_data",
  111. },
  112. GCPKeyData: {
  113. Docs: "https://github.com/porter-dev/porter",
  114. Fields: "gcp_key_data",
  115. },
  116. AWSData: {
  117. Docs: "https://github.com/porter-dev/porter",
  118. Fields: "aws_access_key_id,aws_secret_access_key,aws_cluster_id",
  119. },
  120. }
  121. // ClusterResolverData is a map of key names to fields, which gets marshaled from
  122. // the raw JSON bytes stored in the ClusterResolver
  123. type ClusterResolverData map[string]string
  124. type ClusterGetResponse struct {
  125. *Cluster
  126. // The NGINX Ingress IP to access the cluster
  127. IngressIP string `json:"ingress_ip"`
  128. // Error displayed in case couldn't get the IP
  129. IngressError error `json:"ingress_error"`
  130. }
  131. type ClusterService string
  132. const (
  133. EKS ClusterService = "eks"
  134. DOKS ClusterService = "doks"
  135. GKE ClusterService = "gke"
  136. Kube ClusterService = "kube"
  137. AKS ClusterService = "aks"
  138. )
  139. // ClusterResolverName is the name for a cluster resolve
  140. type ClusterResolverName string
  141. // Options for the cluster resolver names
  142. const (
  143. ClusterCAData ClusterResolverName = "upload-cluster-ca-data"
  144. ClusterLocalhost ClusterResolverName = "rewrite-cluster-localhost"
  145. ClientCertData ClusterResolverName = "upload-client-cert-data"
  146. ClientKeyData ClusterResolverName = "upload-client-key-data"
  147. OIDCIssuerData ClusterResolverName = "upload-oidc-idp-issuer-ca-data"
  148. TokenData ClusterResolverName = "upload-token-data"
  149. GCPKeyData ClusterResolverName = "upload-gcp-key-data"
  150. AWSData ClusterResolverName = "upload-aws-data"
  151. )
  152. // NamespaceResponse represents the response type of requests to the namespace resource
  153. //
  154. // swagger:model
  155. type NamespaceResponse struct {
  156. // the name of the namespace
  157. // example: default
  158. Name string `json:"name" form:"required"`
  159. // the creation timestamp in UTC of the namespace in RFC 1123 format
  160. // example: Mon, 13 Jun 2022 17:49:12 GMT
  161. CreationTimestamp string `json:"creationTimestamp" form:"required"`
  162. // the deletion timestamp in UTC of the namespace in RFC 1123 format, if the namespace is deleted
  163. // example: Mon, 13 Jun 2022 17:49:12 GMT
  164. DeletionTimestamp string `json:"deletionTimestamp,omitempty"`
  165. // the status of the namespace
  166. // enum: active,terminating
  167. // example: active
  168. Status string `json:"status" form:"required"`
  169. }
  170. // ListNamespacesResponse represents the list of all namespaces
  171. //
  172. // swagger:model
  173. type ListNamespacesResponse []*NamespaceResponse
  174. // CreateNamespaceRequest represents the request body to create a namespace
  175. //
  176. // swagger:model
  177. type CreateNamespaceRequest struct {
  178. // the name of the namespace to create
  179. // example: sampleNS
  180. Name string `json:"name" form:"required"`
  181. }
  182. type GetTemporaryKubeconfigResponse struct {
  183. Kubeconfig []byte `json:"kubeconfig"`
  184. }
  185. type ListNGINXIngressesResponse []prometheus.SimpleIngress
  186. type GetPodMetricsRequest struct {
  187. prometheus.QueryOpts
  188. }
  189. type GetPodMetricsResponse *string
  190. type GetPodsRequest struct {
  191. Namespace string `schema:"namespace"`
  192. Selectors []string `schema:"selectors"`
  193. }
  194. type CreateClusterManualRequest struct {
  195. Name string `json:"name" form:"required"`
  196. ProjectID uint `json:"project_id" form:"required"`
  197. Server string `json:"server" form:"required"`
  198. GCPIntegrationID uint `json:"gcp_integration_id"`
  199. AWSIntegrationID uint `json:"aws_integration_id"`
  200. CertificateAuthorityData string `json:"certificate_authority_data,omitempty"`
  201. }
  202. type CreateClusterCandidateRequest struct {
  203. ProjectID uint `json:"project_id"`
  204. Kubeconfig string `json:"kubeconfig"`
  205. // Represents whether the auth mechanism should be designated as
  206. // "local": if so, the auth mechanism uses local plugins/mechanisms purely from the
  207. // kubeconfig.
  208. IsLocal bool `json:"is_local"`
  209. }
  210. type UpdateClusterRequest struct {
  211. Name string `json:"name" form:"required"`
  212. AWSClusterID string `json:"aws_cluster_id"`
  213. }
  214. type ListClusterResponse []*Cluster
  215. type CreateClusterCandidateResponse []*ClusterCandidate
  216. type ListClusterCandidateResponse []*ClusterCandidate
  217. type GetIncidentsRequest struct {
  218. IncidentID string `schema:"incident_id"`
  219. ReleaseName string `schema:"release_name"`
  220. Namespace string `schema:"namespace"`
  221. }
  222. type GetIncidentEventLogsRequest struct {
  223. LogID string `schema:"log_id"`
  224. }
  225. type IncidentNotifyRequest struct {
  226. IncidentID string `json:"incident_id" form:"required"`
  227. }