cluster.go 9.7 KB

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