Skip to content

Commit

Permalink
Improve deduction of workload state.
Browse files Browse the repository at this point in the history
Signed-off-by: Thomas Hallgren <[email protected]>
  • Loading branch information
thallgren committed Feb 11, 2025
1 parent 548a79b commit 1bea6dc
Showing 1 changed file with 42 additions and 10 deletions.
52 changes: 42 additions & 10 deletions pkg/workload/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,54 @@ const (
func deploymentState(d *appsv1.Deployment) State {
conds := d.Status.Conditions
sort.Slice(conds, func(i, j int) bool {
return conds[i].LastTransitionTime.Compare(conds[j].LastTransitionTime.Time) > 0
ci := conds[i]
cj := conds[j]

// Put all false statuses last in the list
if ci.Status == core.ConditionFalse {
return false
}
if cj.Status == core.ConditionFalse {
return true
}

if cmp := ci.LastUpdateTime.Compare(cj.LastUpdateTime.Time); cmp != 0 {
return cmp > 0
}
// Transition time is rounded to seconds, so if they are equal, we need to prioritize
// using the Type. This isn't ideal, but it is what it is.

// Failure beats the rest
if ci.Type == appsv1.DeploymentReplicaFailure {
return true
}
if cj.Type == appsv1.DeploymentReplicaFailure {
return false
}

// Available beats Progressing
if ci.Type == appsv1.DeploymentAvailable {
return true
}
if cj.Type == appsv1.DeploymentAvailable {
return false
}

// Statuses are exactly equal. This shouldn't happen.
return true
})
for _, c := range conds {
if c.Status != core.ConditionTrue {
// Only false will follow after this
break
}
switch c.Type {
case appsv1.DeploymentProgressing:
if c.Status == core.ConditionTrue {
return StateProgressing
}
return StateProgressing
case appsv1.DeploymentAvailable:
if c.Status == core.ConditionTrue {
return StateAvailable
}
return StateAvailable
case appsv1.DeploymentReplicaFailure:
if c.Status == core.ConditionTrue {
return StateFailure
}
return StateFailure
}
}
if len(conds) == 0 {
Expand Down

0 comments on commit 1bea6dc

Please sign in to comment.