From 5d2214b21d5c5fd156db01a96f7e7fc21ca1166b Mon Sep 17 00:00:00 2001 From: Sergey Smolnikov Date: Mon, 8 Apr 2024 08:58:50 +0200 Subject: [PATCH] Added component replica types (#612) --- .../models/component_deployment.go | 54 ++++++++++++++++++- swaggerui/html/swagger.json | 14 +++++ 2 files changed, 67 insertions(+), 1 deletion(-) diff --git a/api/deployments/models/component_deployment.go b/api/deployments/models/component_deployment.go index 0881323f..7bb8b36a 100644 --- a/api/deployments/models/component_deployment.go +++ b/api/deployments/models/component_deployment.go @@ -7,6 +7,7 @@ import ( radixutils "github.com/equinor/radix-common/utils" "github.com/equinor/radix-common/utils/pointers" + "github.com/equinor/radix-operator/pkg/apis/kube" corev1 "k8s.io/api/core/v1" ) @@ -268,6 +269,29 @@ type ComponentSummary struct { SkipDeployment bool `json:"skipDeployment,omitempty"` } +// ReplicaType The replica type +type ReplicaType int + +const ( + // JobManager Replica of a Radix job-component scheduler + JobManager ReplicaType = iota + // JobManagerAux Replica of a Radix job-component scheduler auxiliary + JobManagerAux + // OAuth2 Replica of a Radix OAuth2 component + OAuth2 + // Undefined Replica without defined type - to be extended + Undefined + numReplicaType +) + +// Convert ReplicaType to a string +func (p ReplicaType) String() string { + if p >= numReplicaType { + return "Unsupported" + } + return [...]string{"JobManager", "JobManagerAux", "OAuth2", "Undefined"}[p] +} + // ReplicaSummary describes condition of a pod // swagger:model ReplicaSummary type ReplicaSummary struct { @@ -277,6 +301,19 @@ type ReplicaSummary struct { // example: server-78fc8857c4-hm76l Name string `json:"name"` + // Pod type + // - ComponentReplica = Replica of a Radix component + // - ScheduledJobReplica = Replica of a Radix job-component + // - JobManager = Replica of a Radix job-component scheduler + // - JobManagerAux = Replica of a Radix job-component scheduler auxiliary + // - OAuth2 = Replica of a Radix OAuth2 component + // - Undefined = Replica without defined type - to be extended + // + // required: false + // enum: ComponentReplica,ScheduledJobReplica,JobManager,JobManagerAux,OAuth2,Undefined + // example: ComponentReplica + Type string `json:"type"` + // Created timestamp // // required: false @@ -421,7 +458,9 @@ type ResourceRequirements struct { } func GetReplicaSummary(pod corev1.Pod, lastEventWarning string) ReplicaSummary { - replicaSummary := ReplicaSummary{} + replicaSummary := ReplicaSummary{ + Type: getReplicaType(pod).String(), + } replicaSummary.Name = pod.GetName() creationTimestamp := pod.GetCreationTimestamp() replicaSummary.Created = radixutils.FormatTimestamp(creationTimestamp.Time) @@ -482,6 +521,19 @@ func GetReplicaSummary(pod corev1.Pod, lastEventWarning string) ReplicaSummary { return replicaSummary } +func getReplicaType(pod corev1.Pod) ReplicaType { + switch { + case pod.GetLabels()[kube.RadixPodIsJobSchedulerLabel] == "true": + return JobManager + case pod.GetLabels()[kube.RadixPodIsJobAuxObjectLabel] == "true": + return JobManagerAux + case pod.GetLabels()[kube.RadixAuxiliaryComponentTypeLabel] == "oauth": + return OAuth2 + default: + return Undefined + } +} + func getReplicaStatusByPodStatus(podPhase corev1.PodPhase) string { switch podPhase { case corev1.PodPending: diff --git a/swaggerui/html/swagger.json b/swaggerui/html/swagger.json index df0324f6..650a2295 100644 --- a/swaggerui/html/swagger.json +++ b/swaggerui/html/swagger.json @@ -7219,6 +7219,20 @@ "description": "StatusMessage provides message describing the status of a component container inside a pod", "type": "string", "x-go-name": "StatusMessage" + }, + "type": { + "description": "Pod type\nComponentReplica = Replica of a Radix component\nScheduledJobReplica = Replica of a Radix job-component\nJobManager = Replica of a Radix job-component scheduler\nJobManagerAux = Replica of a Radix job-component scheduler auxiliary\nOAuth2 = Replica of a Radix OAuth2 component\nUndefined = Replica without defined type - to be extended", + "type": "string", + "enum": [ + "ComponentReplica", + "ScheduledJobReplica", + "JobManager", + "JobManagerAux", + "OAuth2", + "Undefined" + ], + "x-go-name": "Type", + "example": "ComponentReplica" } }, "x-go-package": "github.com/equinor/radix-api/api/deployments/models"