cluster.go 8.3 KB

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