cluster.go 9.6 KB

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