From 914acf6e3d229c5ff272877eab40749e5bf0a4c0 Mon Sep 17 00:00:00 2001 From: Matthias Radestock Date: Thu, 30 Nov 2017 18:40:00 +0000 Subject: [PATCH] fix incorrect reporting of replicaset DesiredReplicas ReplicaSetSpec.Replicas is an *int32. Just like in DeploymentSpec, where we deal with that in the same way. --- probe/kubernetes/replica_set.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/probe/kubernetes/replica_set.go b/probe/kubernetes/replica_set.go index 36df4ec788..6424f9bd4d 100644 --- a/probe/kubernetes/replica_set.go +++ b/probe/kubernetes/replica_set.go @@ -53,10 +53,15 @@ func (r *replicaSet) AddParent(topology, id string) { } func (r *replicaSet) GetNode(probeID string) report.Node { + // Spec.Replicas can be omitted, and the pointer will be nil. It defaults to 1. + desiredReplicas := 1 + if r.Spec.Replicas != nil { + desiredReplicas = int(*r.Spec.Replicas) + } return r.MetaNode(report.MakeReplicaSetNodeID(r.UID())).WithLatests(map[string]string{ ObservedGeneration: fmt.Sprint(r.Status.ObservedGeneration), Replicas: fmt.Sprint(r.Status.Replicas), - DesiredReplicas: fmt.Sprint(r.Spec.Replicas), + DesiredReplicas: fmt.Sprint(desiredReplicas), FullyLabeledReplicas: fmt.Sprint(r.Status.FullyLabeledReplicas), report.ControlProbeID: probeID, }).WithParents(r.parents).WithLatestActiveControls(ScaleUp, ScaleDown)