cluster.go 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  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. // 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. AKS ClusterService = "aks"
  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. // NamespaceResponse represents the response type of requests to the namespace resource
  151. //
  152. // swagger:model
  153. type NamespaceResponse struct {
  154. // the name of the namespace
  155. // example: default
  156. Name string `json:"name" form:"required"`
  157. // the creation timestamp in UTC of the namespace in RFC 1123 format
  158. // example: Mon, 13 Jun 2022 17:49:12 GMT
  159. CreationTimestamp string `json:"creationTimestamp" form:"required"`
  160. // the deletion timestamp in UTC of the namespace in RFC 1123 format, if the namespace is deleted
  161. // example: Mon, 13 Jun 2022 17:49:12 GMT
  162. DeletionTimestamp string `json:"deletionTimestamp,omitempty"`
  163. // the status of the namespace
  164. // enum: active,terminating
  165. // example: active
  166. Status string `json:"status" form:"required"`
  167. }
  168. // ListNamespacesResponse represents the list of all namespaces
  169. //
  170. // swagger:model
  171. type ListNamespacesResponse []*NamespaceResponse
  172. // CreateNamespaceRequest represents the request body to create a namespace
  173. //
  174. // swagger:model
  175. type CreateNamespaceRequest struct {
  176. // the name of the namespace to create
  177. // example: sampleNS
  178. Name string `json:"name" form:"required"`
  179. }
  180. type GetTemporaryKubeconfigResponse struct {
  181. Kubeconfig []byte `json:"kubeconfig"`
  182. }
  183. type ListNGINXIngressesResponse []prometheus.SimpleIngress
  184. type GetPodMetricsRequest struct {
  185. prometheus.QueryOpts
  186. }
  187. type GetPodMetricsResponse *string
  188. type GetPodsRequest struct {
  189. Namespace string `schema:"namespace"`
  190. Selectors []string `schema:"selectors"`
  191. }
  192. type CreateClusterManualRequest struct {
  193. Name string `json:"name" form:"required"`
  194. ProjectID uint `json:"project_id" form:"required"`
  195. Server string `json:"server" form:"required"`
  196. GCPIntegrationID uint `json:"gcp_integration_id"`
  197. AWSIntegrationID uint `json:"aws_integration_id"`
  198. CertificateAuthorityData string `json:"certificate_authority_data,omitempty"`
  199. }
  200. type CreateClusterCandidateRequest struct {
  201. ProjectID uint `json:"project_id"`
  202. Kubeconfig string `json:"kubeconfig"`
  203. // Represents whether the auth mechanism should be designated as
  204. // "local": if so, the auth mechanism uses local plugins/mechanisms purely from the
  205. // kubeconfig.
  206. IsLocal bool `json:"is_local"`
  207. }
  208. type UpdateClusterRequest struct {
  209. Name string `json:"name" form:"required"`
  210. }
  211. type ListClusterResponse []*Cluster
  212. type CreateClusterCandidateResponse []*ClusterCandidate
  213. type ListClusterCandidateResponse []*ClusterCandidate
  214. type GetIncidentsRequest struct {
  215. IncidentID string `schema:"incident_id"`
  216. ReleaseName string `schema:"release_name"`
  217. Namespace string `schema:"namespace"`
  218. }
  219. type GetIncidentEventLogsRequest struct {
  220. LogID string `schema:"log_id"`
  221. }
  222. type IncidentNotifyRequest struct {
  223. IncidentID string `json:"incident_id" form:"required"`
  224. }