Skip to content

Commit 917f5a0

Browse files
authored
fix: add suspended condition (#484)
Signed-off-by: ashutosh16 <[email protected]> fix: add suspended condition Signed-off-by: ashutosh16 <[email protected]> Signed-off-by: ashutosh16 <[email protected]>
1 parent e284fd7 commit 917f5a0

File tree

3 files changed

+65
-0
lines changed

3 files changed

+65
-0
lines changed

pkg/health/health_job.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package health
22

33
import (
44
"fmt"
5+
corev1 "k8s.io/api/core/v1"
56

67
"github.com/argoproj/gitops-engine/pkg/utils/kube"
78
batchv1 "k8s.io/api/batch/v1"
@@ -29,6 +30,7 @@ func getBatchv1JobHealth(job *batchv1.Job) (*HealthStatus, error) {
2930
var failMsg string
3031
complete := false
3132
var message string
33+
isSuspended := false
3234
for _, condition := range job.Status.Conditions {
3335
switch condition.Type {
3436
case batchv1.JobFailed:
@@ -38,6 +40,12 @@ func getBatchv1JobHealth(job *batchv1.Job) (*HealthStatus, error) {
3840
case batchv1.JobComplete:
3941
complete = true
4042
message = condition.Message
43+
case batchv1.JobSuspended:
44+
complete = true
45+
message = condition.Message
46+
if condition.Status == corev1.ConditionTrue {
47+
isSuspended = true
48+
}
4149
}
4250
}
4351
if !complete {
@@ -50,6 +58,11 @@ func getBatchv1JobHealth(job *batchv1.Job) (*HealthStatus, error) {
5058
Status: HealthStatusDegraded,
5159
Message: failMsg,
5260
}, nil
61+
} else if isSuspended {
62+
return &HealthStatus{
63+
Status: HealthStatusSuspended,
64+
Message: failMsg,
65+
}, nil
5366
} else {
5467
return &HealthStatus{
5568
Status: HealthStatusHealthy,

pkg/health/health_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ func TestJob(t *testing.T) {
7575
assertAppHealth(t, "./testdata/job-running.yaml", HealthStatusProgressing)
7676
assertAppHealth(t, "./testdata/job-failed.yaml", HealthStatusDegraded)
7777
assertAppHealth(t, "./testdata/job-succeeded.yaml", HealthStatusHealthy)
78+
assertAppHealth(t, "./testdata/job-suspended.yaml", HealthStatusSuspended)
7879
}
7980

8081
func TestHPA(t *testing.T) {
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
apiVersion: batch/v1
2+
kind: Job
3+
metadata:
4+
creationTimestamp: 2018-12-02T08:19:13Z
5+
labels:
6+
controller-uid: f3fe3a46-f60a-11e8-aa53-42010a80021b
7+
job-name: succeed
8+
name: succeed
9+
namespace: argoci-workflows
10+
resourceVersion: "46535949"
11+
selfLink: /apis/batch/v1/namespaces/argoci-workflows/jobs/succeed
12+
uid: f3fe3a46-f60a-11e8-aa53-42010a80021b
13+
spec:
14+
backoffLimit: 0
15+
completions: 1
16+
parallelism: 1
17+
selector:
18+
matchLabels:
19+
controller-uid: f3fe3a46-f60a-11e8-aa53-42010a80021b
20+
suspend: true
21+
template:
22+
metadata:
23+
creationTimestamp: null
24+
labels:
25+
controller-uid: f3fe3a46-f60a-11e8-aa53-42010a80021b
26+
job-name: succeed
27+
spec:
28+
containers:
29+
- command:
30+
- sh
31+
- -c
32+
- sleep 10
33+
image: alpine:latest
34+
imagePullPolicy: Always
35+
name: succeed
36+
resources: {}
37+
terminationMessagePath: /dev/termination-log
38+
terminationMessagePolicy: File
39+
dnsPolicy: ClusterFirst
40+
restartPolicy: Never
41+
schedulerName: default-scheduler
42+
securityContext: {}
43+
terminationGracePeriodSeconds: 30
44+
status:
45+
conditions:
46+
- lastProbeTime: "2022-12-08T22:27:20Z"
47+
lastTransitionTime: "2022-12-08T22:27:20Z"
48+
message: Job suspended
49+
reason: JobSuspended
50+
status: "True"
51+
type: Suspended

0 commit comments

Comments
 (0)