/
jobconditions.go
65 lines (51 loc) · 1.37 KB
/
jobconditions.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
65
package cluster
// Copyright (c) Microsoft Corporation.
// Licensed under the Apache License 2.0.
import (
"context"
batchv1 "k8s.io/api/batch/v1"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"github.com/Azure/ARO-RP/pkg/util/namespace"
)
var jobConditionsExpected = map[batchv1.JobConditionType]corev1.ConditionStatus{
batchv1.JobComplete: corev1.ConditionTrue,
batchv1.JobFailed: corev1.ConditionFalse,
}
func (mon *Monitor) emitJobConditions(ctx context.Context) error {
var cont string
var count int64
for {
jobs, err := mon.cli.BatchV1().Jobs("").List(ctx, metav1.ListOptions{Limit: 500, Continue: cont})
if err != nil {
return err
}
count += int64(len(jobs.Items))
for _, job := range jobs.Items {
if !namespace.IsOpenShiftNamespace(job.Namespace) {
continue
}
if job.Status.Active > 0 {
// some pods are still active = job is still running, ignore
continue
}
for _, cond := range job.Status.Conditions {
if cond.Status == jobConditionsExpected[cond.Type] {
continue
}
mon.emitGauge("job.conditions", 1, map[string]string{
"name": job.Name,
"namespace": job.Namespace,
"type": string(cond.Type),
"status": string(cond.Status),
})
}
}
cont = jobs.Continue
if cont == "" {
break
}
}
mon.emitGauge("job.count", count, nil)
return nil
}