-
Notifications
You must be signed in to change notification settings - Fork 13
/
deployment.go
43 lines (38 loc) · 1.19 KB
/
deployment.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
package kubeinventory
import (
"context"
"time"
"github.com/circonus-labs/circonus-unified-agent/cua"
v1 "github.com/ericchiang/k8s/apis/apps/v1"
)
func collectDeployments(ctx context.Context, acc cua.Accumulator, ki *KubernetesInventory) {
list, err := ki.client.getDeployments(ctx)
if err != nil {
acc.AddError(err)
return
}
for _, d := range list.Items {
ki.gatherDeployment(*d, acc)
// if err = ki.gatherDeployment(*d, acc); err != nil {
// acc.AddError(err)
// return
// }
}
}
func (ki *KubernetesInventory) gatherDeployment(d v1.Deployment, acc cua.Accumulator) {
fields := map[string]interface{}{
"replicas_available": d.Status.GetAvailableReplicas(),
"replicas_unavailable": d.Status.GetUnavailableReplicas(),
"created": time.Unix(d.Metadata.CreationTimestamp.GetSeconds(), int64(d.Metadata.CreationTimestamp.GetNanos())).UnixNano(),
}
tags := map[string]string{
"deployment_name": d.Metadata.GetName(),
"namespace": d.Metadata.GetNamespace(),
}
for key, val := range d.GetSpec().GetSelector().GetMatchLabels() {
if ki.selectorFilter.Match(key) {
tags["selector_"+key] = val
}
}
acc.AddFields(deploymentMeasurement, fields, tags)
}