Skip to content

Commit

Permalink
Added component replica types
Browse files Browse the repository at this point in the history
  • Loading branch information
satr committed Apr 3, 2024
1 parent 4ed2614 commit 11fd492
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 1 deletion.
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
// 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

0 comments on commit 11fd492

Please sign in to comment.