cluster.go 9.6 KB

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