/
batch_v1_job.go
64 lines (52 loc) · 1.57 KB
/
batch_v1_job.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package resourcesmisc
import (
"fmt"
ctlres "github.com/k14s/kapp/pkg/kapp/resources"
batchv1 "k8s.io/api/batch/v1"
corev1 "k8s.io/api/core/v1"
)
type BatchV1Job struct {
resource ctlres.Resource
}
func NewBatchV1Job(resource ctlres.Resource) *BatchV1Job {
matcher := ctlres.APIVersionKindMatcher{
APIVersion: "batch/v1",
Kind: "Job",
}
if matcher.Matches(resource) {
return &BatchV1Job{resource}
}
return nil
}
func (s BatchV1Job) IsDoneApplying() DoneApplyState {
job := batchv1.Job{}
err := s.resource.AsTypedObj(&job)
if err != nil {
return DoneApplyState{Done: true, Successful: false,
Message: fmt.Sprintf("Error: Failed obj conversion: %s", err)}
}
for _, cond := range job.Status.Conditions {
switch {
case cond.Type == batchv1.JobComplete && cond.Status == corev1.ConditionTrue:
return DoneApplyState{Done: true, Successful: true, Message: "Completed"}
case cond.Type == batchv1.JobFailed && cond.Status == corev1.ConditionTrue:
return DoneApplyState{Done: true, Successful: false,
Message: fmt.Sprintf("Failed with reason %s: %s", cond.Reason, cond.Message)}
}
}
return DoneApplyState{Done: false, Message: fmt.Sprintf(
"Waiting to complete (%d active, %d failed, %d succeeded)",
job.Status.Active, job.Status.Failed, job.Status.Succeeded)}
}
/*
status:
conditions:
- lastProbeTime: "2019-06-26T22:18:22Z"
lastTransitionTime: "2019-06-26T22:18:22Z"
message: Job has reached the specified backoff limit
reason: BackoffLimitExceeded
status: "True"
type: Failed
failed: 7
startTime: "2019-06-26T22:07:50Z"
*/