/
replicasetstatuses.go
52 lines (40 loc) · 1.08 KB
/
replicasetstatuses.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
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) emitReplicasetStatuses(ctx context.Context) error {
var cont string
var count int64
for {
rss, err := mon.cli.AppsV1().ReplicaSets("").List(ctx, metav1.ListOptions{Limit: 500, Continue: cont})
if err != nil {
return err
}
count += int64(len(rss.Items))
for _, rs := range rss.Items {
if !namespace.IsOpenShiftNamespace(rs.Namespace) {
continue
}
if rs.Status.Replicas == rs.Status.AvailableReplicas {
continue
}
mon.emitGauge("replicaset.statuses", 1, map[string]string{
"availableReplicas": strconv.Itoa(int(rs.Status.AvailableReplicas)),
"name": rs.Name,
"namespace": rs.Namespace,
"replicas": strconv.Itoa(int(rs.Status.Replicas)),
})
}
cont = rss.Continue
if cont == "" {
break
}
}
mon.emitGauge("replicaset.count", count, nil)
return nil
}