cluster.go 9.5 KB

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