cluster.go 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380
  1. package types
  2. import (
  3. "time"
  4. "github.com/porter-dev/porter/internal/kubernetes/prometheus"
  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. // (optional) The aws cluster id, if available
  25. AWSClusterID string `json:"aws_cluster_id,omitempty"`
  26. }
  27. type ClusterCandidate struct {
  28. ID uint `json:"id"`
  29. // The project that this integration belongs to
  30. ProjectID uint `json:"project_id"`
  31. // CreatedClusterID is the ID of the cluster that's eventually
  32. // created
  33. CreatedClusterID uint `json:"created_cluster_id"`
  34. // Name of the cluster
  35. Name string `json:"name"`
  36. // Server endpoint for the cluster
  37. Server string `json:"server"`
  38. // Name of the context that this was created from, if it exists
  39. ContextName string `json:"context_name"`
  40. // Resolvers are the list of resolvers: once all resolvers are "resolved," the
  41. // cluster will be created
  42. Resolvers []ClusterResolver `json:"resolvers"`
  43. // The best-guess for the AWSClusterID, which is required by aws auth mechanisms
  44. // See https://github.com/kubernetes-sigs/aws-iam-authenticator#what-is-a-cluster-id
  45. AWSClusterIDGuess string `json:"aws_cluster_id_guess"`
  46. }
  47. type ClusterResolver struct {
  48. ID uint `json:"id"`
  49. // The ClusterCandidate that this is resolving
  50. ClusterCandidateID uint `json:"cluster_candidate_id"`
  51. // One of the ClusterResolverNames
  52. Name ClusterResolverName `json:"name"`
  53. // Resolved is true if this has been resolved, false otherwise
  54. Resolved bool `json:"resolved"`
  55. // Docs is a link to documentation that helps resolve this manually
  56. Docs string `json:"docs"`
  57. // Fields is a list of fields that must be sent with the resolving request
  58. Fields string `json:"fields"`
  59. // Data is additional data for resolving the action, for example a file name,
  60. // context name, etc
  61. Data ClusterResolverData `json:"data,omitempty"`
  62. }
  63. // ClusterResolverAll is a helper type that contains the fields for
  64. // all possible resolvers, so that raw bytes can be unmarshaled in a single
  65. // read
  66. type ClusterResolverAll struct {
  67. ClusterCAData string `json:"cluster_ca_data,omitempty"`
  68. ClusterHostname string `json:"cluster_hostname,omitempty"`
  69. ClientCertData string `json:"client_cert_data,omitempty"`
  70. ClientKeyData string `json:"client_key_data,omitempty"`
  71. OIDCIssuerCAData string `json:"oidc_idp_issuer_ca_data,omitempty"`
  72. TokenData string `json:"token_data,omitempty"`
  73. GCPKeyData string `json:"gcp_key_data,omitempty"`
  74. AWSAccessKeyID string `json:"aws_access_key_id"`
  75. AWSSecretAccessKey string `json:"aws_secret_access_key"`
  76. AWSClusterID string `json:"aws_cluster_id"`
  77. }
  78. // ClusterResolverInfo contains the information for actions to be
  79. // performed in order to initialize a cluster
  80. type ClusterResolverInfo struct {
  81. // Docs is a link to documentation that helps resolve this manually
  82. Docs string `json:"docs"`
  83. // a comma-separated list of required fields to send in an action request
  84. Fields string `json:"fields"`
  85. }
  86. // ClusterResolverInfos is a map of the information for actions to be
  87. // performed in order to initialize a cluster
  88. var ClusterResolverInfos = map[ClusterResolverName]ClusterResolverInfo{
  89. ClusterCAData: {
  90. Docs: "https://github.com/porter-dev/porter",
  91. Fields: "cluster_ca_data",
  92. },
  93. ClusterLocalhost: {
  94. Docs: "https://github.com/porter-dev/porter",
  95. Fields: "cluster_hostname",
  96. },
  97. ClientCertData: {
  98. Docs: "https://github.com/porter-dev/porter",
  99. Fields: "client_cert_data",
  100. },
  101. ClientKeyData: {
  102. Docs: "https://github.com/porter-dev/porter",
  103. Fields: "client_key_data",
  104. },
  105. OIDCIssuerData: {
  106. Docs: "https://github.com/porter-dev/porter",
  107. Fields: "oidc_idp_issuer_ca_data",
  108. },
  109. TokenData: {
  110. Docs: "https://github.com/porter-dev/porter",
  111. Fields: "token_data",
  112. },
  113. GCPKeyData: {
  114. Docs: "https://github.com/porter-dev/porter",
  115. Fields: "gcp_key_data",
  116. },
  117. AWSData: {
  118. Docs: "https://github.com/porter-dev/porter",
  119. Fields: "aws_access_key_id,aws_secret_access_key,aws_cluster_id",
  120. },
  121. }
  122. // ClusterResolverData is a map of key names to fields, which gets marshaled from
  123. // the raw JSON bytes stored in the ClusterResolver
  124. type ClusterResolverData map[string]string
  125. type ClusterGetResponse struct {
  126. *Cluster
  127. // The NGINX Ingress IP to access the cluster
  128. IngressIP string `json:"ingress_ip"`
  129. // Error displayed in case couldn't get the IP
  130. IngressError error `json:"ingress_error"`
  131. }
  132. type ClusterService string
  133. const (
  134. EKS ClusterService = "eks"
  135. DOKS ClusterService = "doks"
  136. GKE ClusterService = "gke"
  137. Kube ClusterService = "kube"
  138. AKS ClusterService = "aks"
  139. )
  140. // ClusterResolverName is the name for a cluster resolve
  141. type ClusterResolverName string
  142. // Options for the cluster resolver names
  143. const (
  144. ClusterCAData ClusterResolverName = "upload-cluster-ca-data"
  145. ClusterLocalhost ClusterResolverName = "rewrite-cluster-localhost"
  146. ClientCertData ClusterResolverName = "upload-client-cert-data"
  147. ClientKeyData ClusterResolverName = "upload-client-key-data"
  148. OIDCIssuerData ClusterResolverName = "upload-oidc-idp-issuer-ca-data"
  149. TokenData ClusterResolverName = "upload-token-data"
  150. GCPKeyData ClusterResolverName = "upload-gcp-key-data"
  151. AWSData ClusterResolverName = "upload-aws-data"
  152. )
  153. // NamespaceResponse represents the response type of requests to the namespace resource
  154. //
  155. // swagger:model
  156. type NamespaceResponse struct {
  157. // the name of the namespace
  158. // example: default
  159. Name string `json:"name" form:"required"`
  160. // the creation timestamp in UTC of the namespace in RFC 1123 format
  161. // example: Mon, 13 Jun 2022 17:49:12 GMT
  162. CreationTimestamp string `json:"creationTimestamp" form:"required"`
  163. // the deletion timestamp in UTC of the namespace in RFC 1123 format, if the namespace is deleted
  164. // example: Mon, 13 Jun 2022 17:49:12 GMT
  165. DeletionTimestamp string `json:"deletionTimestamp,omitempty"`
  166. // the status of the namespace
  167. // enum: active,terminating
  168. // example: active
  169. Status string `json:"status" form:"required"`
  170. }
  171. // ListNamespacesResponse represents the list of all namespaces
  172. //
  173. // swagger:model
  174. type ListNamespacesResponse []*NamespaceResponse
  175. // CreateNamespaceRequest represents the request body to create a namespace
  176. //
  177. // swagger:model
  178. type CreateNamespaceRequest struct {
  179. // the name of the namespace to create
  180. // example: sampleNS
  181. Name string `json:"name" form:"required"`
  182. }
  183. type GetTemporaryKubeconfigResponse struct {
  184. Kubeconfig []byte `json:"kubeconfig"`
  185. }
  186. type ListNGINXIngressesResponse []prometheus.SimpleIngress
  187. type GetPodMetricsRequest struct {
  188. prometheus.QueryOpts
  189. }
  190. type GetPodMetricsResponse *string
  191. type GetPodsRequest struct {
  192. Namespace string `schema:"namespace"`
  193. Selectors []string `schema:"selectors"`
  194. }
  195. type CreateClusterManualRequest struct {
  196. Name string `json:"name" form:"required"`
  197. ProjectID uint `json:"project_id" form:"required"`
  198. Server string `json:"server" form:"required"`
  199. GCPIntegrationID uint `json:"gcp_integration_id"`
  200. AWSIntegrationID uint `json:"aws_integration_id"`
  201. CertificateAuthorityData string `json:"certificate_authority_data,omitempty"`
  202. }
  203. type CreateClusterCandidateRequest struct {
  204. ProjectID uint `json:"project_id"`
  205. Kubeconfig string `json:"kubeconfig"`
  206. // Represents whether the auth mechanism should be designated as
  207. // "local": if so, the auth mechanism uses local plugins/mechanisms purely from the
  208. // kubeconfig.
  209. IsLocal bool `json:"is_local"`
  210. }
  211. type UpdateClusterRequest struct {
  212. Name string `json:"name" form:"required"`
  213. AWSClusterID string `json:"aws_cluster_id"`
  214. }
  215. type ListClusterResponse []*Cluster
  216. type CreateClusterCandidateResponse []*ClusterCandidate
  217. type ListClusterCandidateResponse []*ClusterCandidate
  218. type SeverityType string
  219. const (
  220. SeverityCritical SeverityType = "critical"
  221. SeverityNormal SeverityType = "normal"
  222. )
  223. type InvolvedObjectKind string
  224. const (
  225. InvolvedObjectDeployment InvolvedObjectKind = "deployment"
  226. InvolvedObjectJob InvolvedObjectKind = "job"
  227. InvolvedObjectPod InvolvedObjectKind = "pod"
  228. )
  229. type IncidentStatus string
  230. const (
  231. IncidentStatusResolved IncidentStatus = "resolved"
  232. IncidentStatusActive IncidentStatus = "active"
  233. )
  234. type IncidentMeta struct {
  235. ID string `json:"id" form:"required"`
  236. ReleaseName string `json:"release_name" form:"required"`
  237. ReleaseNamespace string `json:"release_namespace" form:"required"`
  238. ChartName string `json:"chart_name" form:"required"`
  239. CreatedAt time.Time `json:"created_at" form:"required"`
  240. UpdatedAt time.Time `json:"updated_at" form:"required"`
  241. LastSeen *time.Time `json:"last_seen" form:"required"`
  242. Status IncidentStatus `json:"status" form:"required"`
  243. Summary string `json:"summary" form:"required"`
  244. Severity SeverityType `json:"severity" form:"required"`
  245. InvolvedObjectKind InvolvedObjectKind `json:"involved_object_kind" form:"required"`
  246. InvolvedObjectName string `json:"involved_object_name" form:"required"`
  247. InvolvedObjectNamespace string `json:"involved_object_namespace" form:"required"`
  248. }
  249. type PaginationRequest struct {
  250. Page int64 `schema:"page"`
  251. }
  252. type PaginationResponse struct {
  253. NumPages int64 `json:"num_pages" form:"required"`
  254. CurrentPage int64 `json:"current_page" form:"required"`
  255. NextPage int64 `json:"next_page" form:"required"`
  256. }
  257. type ListIncidentsRequest struct {
  258. *PaginationRequest
  259. Status *IncidentStatus `schema:"status"`
  260. ReleaseName *string `schema:"release_name"`
  261. ReleaseNamespace *string `schema:"release_namespace"`
  262. }
  263. type ListIncidentsResponse struct {
  264. Incidents []*IncidentMeta `json:"incidents" form:"required"`
  265. Pagination *PaginationResponse `json:"pagination"`
  266. }
  267. type Incident struct {
  268. *IncidentMeta
  269. Pods []string `json:"pods" form:"required"`
  270. Detail string `json:"detail" form:"required"`
  271. }
  272. type IncidentEvent struct {
  273. ID string `json:"id" form:"required"`
  274. LastSeen *time.Time `json:"last_seen" form:"required"`
  275. PodName string `json:"pod_name" form:"required"`
  276. PodNamespace string `json:"pod_namespace" form:"required"`
  277. Summary string `json:"summary" form:"required"`
  278. Detail string `json:"detail" form:"required"`
  279. }
  280. type ListIncidentEventsRequest struct {
  281. *PaginationRequest
  282. PodName *string `schema:"pod_name"`
  283. PodNamespace *string `schema:"pod_namespace"`
  284. Summary *string `schema:"summary"`
  285. }
  286. type ListIncidentEventsResponse struct {
  287. Events []*IncidentEvent `json:"events" form:"required"`
  288. Pagination *PaginationResponse `json:"pagination"`
  289. }
  290. type GetLogRequest struct {
  291. Limit uint `json:"limit"`
  292. StartRange *time.Time `json:"start_range"`
  293. EndRange *time.Time `json:"end_range"`
  294. Pods []string `json:"pods"`
  295. }
  296. type LogLine struct {
  297. Timestamp *time.Time `json:"timestamp"`
  298. Line string `json:"line"`
  299. }
  300. type GetLogResponse struct {
  301. ContinueTime *time.Time `json:"continue_time"`
  302. Logs []LogLine `json:"logs"`
  303. }