Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added component replica types #612

Merged
merged 1 commit into from
Apr 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 53 additions & 1 deletion api/deployments/models/component_deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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
Richard87 marked this conversation as resolved.
Show resolved Hide resolved
// 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 {
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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:
Expand Down
14 changes: 14 additions & 0 deletions swaggerui/html/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down