/
deploymentstatuses.go
50 lines (40 loc) · 1.06 KB
/
deploymentstatuses.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
package cluster
// Copyright (c) Microsoft Corporation.
// Licensed under the Apache License 2.0.
import (
"context"
"strconv"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"github.com/Azure/ARO-RP/pkg/util/namespace"
)
func (mon *Monitor) emitDeploymentStatuses(ctx context.Context) error {
var cont string
var count int64
for {
ds, err := mon.cli.AppsV1().Deployments("").List(ctx, metav1.ListOptions{Limit: 500, Continue: cont})
if err != nil {
return err
}
count += int64(len(ds.Items))
for _, d := range ds.Items {
if !namespace.IsOpenShiftNamespace(d.Namespace) {
continue
}
if d.Status.Replicas == d.Status.AvailableReplicas {
continue
}
mon.emitGauge("deployment.statuses", 1, map[string]string{
"availableReplicas": strconv.Itoa(int(d.Status.AvailableReplicas)),
"name": d.Name,
"namespace": d.Namespace,
"replicas": strconv.Itoa(int(d.Status.Replicas)),
})
}
cont = ds.Continue
if cont == "" {
break
}
}
mon.emitGauge("deployment.count", count, nil)
return nil
}