cluster.go 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  1. package types
  2. import (
  3. "github.com/porter-dev/porter/internal/kubernetes/prometheus"
  4. v1 "k8s.io/api/core/v1"
  5. )
  6. const (
  7. URLParamCandidateID URLParam = "candidate_id"
  8. URLParamNodeName URLParam = "node_name"
  9. )
  10. type Cluster struct {
  11. ID uint `json:"id"`
  12. // The project that this integration belongs to
  13. ProjectID uint `json:"project_id"`
  14. // Name of the cluster
  15. Name string `json:"name"`
  16. // Server endpoint for the cluster
  17. Server string `json:"server"`
  18. // The integration service for this cluster
  19. Service ClusterService `json:"service"`
  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. }
  25. type ClusterCandidate struct {
  26. ID uint `json:"id"`
  27. // The project that this integration belongs to
  28. ProjectID uint `json:"project_id"`
  29. // CreatedClusterID is the ID of the cluster that's eventually
  30. // created
  31. CreatedClusterID uint `json:"created_cluster_id"`
  32. // Name of the cluster
  33. Name string `json:"name"`
  34. // Server endpoint for the cluster
  35. Server string `json:"server"`
  36. // Name of the context that this was created from, if it exists
  37. ContextName string `json:"context_name"`
  38. // Resolvers are the list of resolvers: once all resolvers are "resolved," the
  39. // cluster will be created
  40. Resolvers []ClusterResolver `json:"resolvers"`
  41. // The best-guess for the AWSClusterID, which is required by aws auth mechanisms
  42. // See https://github.com/kubernetes-sigs/aws-iam-authenticator#what-is-a-cluster-id
  43. AWSClusterIDGuess string `json:"aws_cluster_id_guess"`
  44. }
  45. type ClusterResolver struct {
  46. ID uint `json:"id"`
  47. // The ClusterCandidate that this is resolving
  48. ClusterCandidateID uint `json:"cluster_candidate_id"`
  49. // One of the ClusterResolverNames
  50. Name ClusterResolverName `json:"name"`
  51. // Resolved is true if this has been resolved, false otherwise
  52. Resolved bool `json:"resolved"`
  53. // Docs is a link to documentation that helps resolve this manually
  54. Docs string `json:"docs"`
  55. // Fields is a list of fields that must be sent with the resolving request
  56. Fields string `json:"fields"`
  57. // Data is additional data for resolving the action, for example a file name,
  58. // context name, etc
  59. Data ClusterResolverData `json:"data,omitempty"`
  60. }
  61. // ClusterResolverAll is a helper type that contains the fields for
  62. // all possible resolvers, so that raw bytes can be unmarshaled in a single
  63. // read
  64. type ClusterResolverAll struct {
  65. ClusterCAData string `json:"cluster_ca_data,omitempty"`
  66. ClusterHostname string `json:"cluster_hostname,omitempty"`
  67. ClientCertData string `json:"client_cert_data,omitempty"`
  68. ClientKeyData string `json:"client_key_data,omitempty"`
  69. OIDCIssuerCAData string `json:"oidc_idp_issuer_ca_data,omitempty"`
  70. TokenData string `json:"token_data,omitempty"`
  71. GCPKeyData string `json:"gcp_key_data,omitempty"`
  72. AWSAccessKeyID string `json:"aws_access_key_id"`
  73. AWSSecretAccessKey string `json:"aws_secret_access_key"`
  74. AWSClusterID string `json:"aws_cluster_id"`
  75. }
  76. // ClusterResolverInfo contains the information for actions to be
  77. // performed in order to initialize a cluster
  78. type ClusterResolverInfo struct {
  79. // Docs is a link to documentation that helps resolve this manually
  80. Docs string `json:"docs"`
  81. // a comma-separated list of required fields to send in an action request
  82. Fields string `json:"fields"`
  83. }
  84. // ClusterResolverInfos is a map of the information for actions to be
  85. // performed in order to initialize a cluster
  86. var ClusterResolverInfos = map[ClusterResolverName]ClusterResolverInfo{
  87. ClusterCAData: {
  88. Docs: "https://github.com/porter-dev/porter",
  89. Fields: "cluster_ca_data",
  90. },
  91. ClusterLocalhost: {
  92. Docs: "https://github.com/porter-dev/porter",
  93. Fields: "cluster_hostname",
  94. },
  95. ClientCertData: {
  96. Docs: "https://github.com/porter-dev/porter",
  97. Fields: "client_cert_data",
  98. },
  99. ClientKeyData: {
  100. Docs: "https://github.com/porter-dev/porter",
  101. Fields: "client_key_data",
  102. },
  103. OIDCIssuerData: {
  104. Docs: "https://github.com/porter-dev/porter",
  105. Fields: "oidc_idp_issuer_ca_data",
  106. },
  107. TokenData: {
  108. Docs: "https://github.com/porter-dev/porter",
  109. Fields: "token_data",
  110. },
  111. GCPKeyData: {
  112. Docs: "https://github.com/porter-dev/porter",
  113. Fields: "gcp_key_data",
  114. },
  115. AWSData: {
  116. Docs: "https://github.com/porter-dev/porter",
  117. Fields: "aws_access_key_id,aws_secret_access_key,aws_cluster_id",
  118. },
  119. }
  120. // ClusterResolverData is a map of key names to fields, which gets marshaled from
  121. // the raw JSON bytes stored in the ClusterResolver
  122. type ClusterResolverData map[string]string
  123. type ClusterGetResponse struct {
  124. *Cluster
  125. // The NGINX Ingress IP to access the cluster
  126. IngressIP string `json:"ingress_ip"`
  127. // Error displayed in case couldn't get the IP
  128. IngressError error `json:"ingress_error"`
  129. }
  130. type ClusterService string
  131. const (
  132. EKS ClusterService = "eks"
  133. DOKS ClusterService = "doks"
  134. GKE ClusterService = "gke"
  135. Kube ClusterService = "kube"
  136. )
  137. // ClusterResolverName is the name for a cluster resolve
  138. type ClusterResolverName string
  139. // Options for the cluster resolver names
  140. const (
  141. ClusterCAData ClusterResolverName = "upload-cluster-ca-data"
  142. ClusterLocalhost ClusterResolverName = "rewrite-cluster-localhost"
  143. ClientCertData ClusterResolverName = "upload-client-cert-data"
  144. ClientKeyData ClusterResolverName = "upload-client-key-data"
  145. OIDCIssuerData ClusterResolverName = "upload-oidc-idp-issuer-ca-data"
  146. TokenData ClusterResolverName = "upload-token-data"
  147. GCPKeyData ClusterResolverName = "upload-gcp-key-data"
  148. AWSData ClusterResolverName = "upload-aws-data"
  149. )
  150. type ListNamespacesResponse struct {
  151. *v1.NamespaceList
  152. }
  153. type CreateNamespaceRequest struct {
  154. Name string `json:"name" form:"required"`
  155. }
  156. type CreateNamespaceResponse struct {
  157. *v1.Namespace
  158. }
  159. type DeleteNamespaceRequest struct {
  160. Name string `json:"name" form:"required"`
  161. }
  162. type GetTemporaryKubeconfigResponse struct {
  163. Kubeconfig []byte `json:"kubeconfig"`
  164. }
  165. type ListNGINXIngressesResponse []prometheus.SimpleIngress
  166. type GetPodMetricsRequest struct {
  167. prometheus.QueryOpts
  168. }
  169. type GetPodMetricsResponse *string
  170. type GetPodsRequest struct {
  171. Namespace string `schema:"namespace"`
  172. Selectors []string `schema:"selectors"`
  173. }
  174. type CreateClusterManualRequest struct {
  175. Name string `json:"name" form:"required"`
  176. ProjectID uint `json:"project_id" form:"required"`
  177. Server string `json:"server" form:"required"`
  178. GCPIntegrationID uint `json:"gcp_integration_id"`
  179. AWSIntegrationID uint `json:"aws_integration_id"`
  180. CertificateAuthorityData string `json:"certificate_authority_data,omitempty"`
  181. }
  182. type CreateClusterCandidateRequest struct {
  183. ProjectID uint `json:"project_id"`
  184. Kubeconfig string `json:"kubeconfig"`
  185. // Represents whether the auth mechanism should be designated as
  186. // "local": if so, the auth mechanism uses local plugins/mechanisms purely from the
  187. // kubeconfig.
  188. IsLocal bool `json:"is_local"`
  189. }
  190. type UpdateClusterRequest struct {
  191. Name string `json:"name" form:"required"`
  192. }
  193. type ListClusterResponse []*Cluster
  194. type CreateClusterCandidateResponse []*ClusterCandidate
  195. type ListClusterCandidateResponse []*ClusterCandidate