cluster.go 10.0 KB

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