Skip to content

Commit

Permalink
chore: job fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
moshloop committed Nov 20, 2024
1 parent b8744bd commit e895391
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 14 deletions.
13 changes: 9 additions & 4 deletions pkg/health/health_pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,12 @@ func isErrorStatus(s string) bool {
func getContainerStatus(containerStatus corev1.ContainerStatus) (waiting *HealthStatus, terminated *HealthStatus) {
if state := containerStatus.State.Waiting; state != nil {
waiting = &HealthStatus{
Status: HealthStatusCode(state.Reason),
Health: lo.Ternary(isErrorStatus(state.Reason) || containerStatus.RestartCount > 0, HealthUnhealthy, HealthUnknown),
Status: HealthStatusCode(state.Reason),
Health: lo.Ternary(
isErrorStatus(state.Reason) || containerStatus.RestartCount > 0,
HealthUnhealthy,
HealthUnknown,
),
Message: state.Message,
}
}
Expand Down Expand Up @@ -85,7 +89,7 @@ func getCorev1PodHealth(pod *corev1.Pod) (*HealthStatus, error) {
deadline := GetStartDeadline(append(pod.Spec.InitContainers, pod.Spec.Containers...)...)
age := time.Since(pod.CreationTimestamp.Time).Truncate(time.Minute).Abs()
isStarting := age < deadline
var hr = HealthStatus{
hr := HealthStatus{
Health: lo.Ternary(isReady, HealthHealthy, HealthUnhealthy),
}

Expand Down Expand Up @@ -145,7 +149,8 @@ func getCorev1PodHealth(pod *corev1.Pod) (*HealthStatus, error) {

case corev1.PodRunning, corev1.PodPending:
hr = hr.Merge(terminated, waiting)
if terminated != nil && terminated.Health.IsWorseThan(HealthWarning) && hr.Status == HealthStatusCrashLoopBackoff {
if terminated != nil && terminated.Health.IsWorseThan(HealthWarning) &&
hr.Status == HealthStatusCrashLoopBackoff {
hr.Status = terminated.Status
hr.Health = hr.Health.Worst(terminated.Health)
}
Expand Down
8 changes: 0 additions & 8 deletions pkg/health/health_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ func TestHealthCompare(t *testing.T) {
assert.True(t, health.HealthUnhealthy.IsWorseThan(health.HealthWarning))
assert.Equal(t, health.HealthHealthy, health.HealthHealthy.Worst(health.HealthUnknown))
assert.Equal(t, health.HealthUnhealthy, health.HealthHealthy.Worst(health.HealthUnhealthy))

}

func assertAppHealthMsg(
Expand Down Expand Up @@ -502,13 +501,6 @@ func TestCnrmPubSub(t *testing.T) {
assertAppHealthMsg(t, b+"update_in_progress.yaml", "Progressing", health.HealthUnknown, false)
}

func TestJob(t *testing.T) {
assertAppHealthMsg(t, "./testdata/job-running.yaml", health.HealthStatusRunning, health.HealthHealthy, false)
assertAppHealthMsg(t, "./testdata/job-failed.yaml", health.HealthStatusError, health.HealthUnhealthy, true)
assertAppHealthMsg(t, "./testdata/job-succeeded.yaml", health.HealthStatusCompleted, health.HealthHealthy, true)
assertAppHealthMsg(t, "./testdata/job-suspended.yaml", health.HealthStatusSuspended, health.HealthUnknown, false)
}

func TestHPA(t *testing.T) {
assertAppHealthMsg(t, "./testdata/hpa-v2-healthy.yaml", health.HealthStatusHealthy, health.HealthHealthy, true)
assertAppHealthMsg(t, "./testdata/hpa-v2-degraded.yaml", health.HealthStatusDegraded, health.HealthUnhealthy, false)
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ metadata:
job-name: fail
name: fail
namespace: argoci-workflows
annotations:
expected-status: BackoffLimitExceeded
expected-health: unhealthy
resourceVersion: "46534173"
selfLink: /apis/batch/v1/namespaces/argoci-workflows/jobs/fail
uid: 95052288-f609-11e8-aa53-42010a80021b
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ metadata:
job-name: succeed
name: succeed
namespace: argoci-workflows
annotations:
expected-status: Running
expected-health: healthy
expected-ready: "false"
resourceVersion: "46535911"
selfLink: /apis/batch/v1/namespaces/argoci-workflows/jobs/succeed
uid: f3fe3a46-f60a-11e8-aa53-42010a80021b
Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions pkg/health/testdata/Kubernetes/Pod/pod-crashloop-pending.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ metadata:
app: crashloop
pod-template-hash: 6bf9b7b858
namespace: default
annotations:
expected-status: CrashloopBackoff
annotations:
expected-status: PodInitializing
expected-health: unhealthy
generateName: crashloop-deployment-6bf9b7b858-
ownerReferences:
Expand Down

0 comments on commit e895391

Please sign in to comment.