/
machineconfigpoolconditions.go
67 lines (55 loc) · 1.74 KB
/
machineconfigpoolconditions.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
66
67
package cluster
// Copyright (c) Microsoft Corporation.
// Licensed under the Apache License 2.0.
import (
"context"
mcv1 "github.com/openshift/machine-config-operator/pkg/apis/machineconfiguration.openshift.io/v1"
"github.com/sirupsen/logrus"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
var machineConfigPoolConditionsExpected = map[mcv1.MachineConfigPoolConditionType]corev1.ConditionStatus{
mcv1.MachineConfigPoolDegraded: corev1.ConditionFalse,
mcv1.MachineConfigPoolNodeDegraded: corev1.ConditionFalse,
mcv1.MachineConfigPoolRenderDegraded: corev1.ConditionFalse,
mcv1.MachineConfigPoolUpdated: corev1.ConditionTrue,
mcv1.MachineConfigPoolUpdating: corev1.ConditionFalse,
}
func (mon *Monitor) emitMachineConfigPoolConditions(ctx context.Context) error {
var cont string
var count int64
for {
mcps, err := mon.mcocli.MachineconfigurationV1().MachineConfigPools().List(ctx, metav1.ListOptions{Limit: 500, Continue: cont})
if err != nil {
return err
}
count += int64(len(mcps.Items))
for _, mcp := range mcps.Items {
for _, c := range mcp.Status.Conditions {
if c.Status == machineConfigPoolConditionsExpected[c.Type] {
continue
}
mon.emitGauge("machineconfigpool.conditions", 1, map[string]string{
"name": mcp.Name,
"status": string(c.Status),
"type": string(c.Type),
})
if mon.hourlyRun {
mon.log.WithFields(logrus.Fields{
"metric": "machineconfigpool.conditions",
"name": mcp.Name,
"status": c.Status,
"type": c.Type,
"message": c.Message,
}).Print()
}
}
}
cont = mcps.Continue
if cont == "" {
break
}
}
mon.emitGauge("machineconfigpool.count", count, nil)
return nil
}