cluster.go 6.8 KB

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