From 6fa0381ae00eb825f14bb53d444961b814ea141e Mon Sep 17 00:00:00 2001 From: Zach Hammer Date: Mon, 8 Jan 2024 13:35:19 -0500 Subject: [PATCH] add replicas info item to ReplicaSet node Signed-off-by: Zach Hammer --- controller/cache/info.go | 9 +++++++++ controller/cache/info_test.go | 16 ++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/controller/cache/info.go b/controller/cache/info.go index 0734e2d118678..56a455c7894d6 100644 --- a/controller/cache/info.go +++ b/controller/cache/info.go @@ -54,6 +54,8 @@ func populateNodeInfo(un *unstructured.Unstructured, res *ResourceInfo, customLa populatePodInfo(un, res) case kube.ServiceKind: populateServiceInfo(un, res) + case kube.ReplicaSetKind: + populateReplicaSetInfo(un, res) case "Node": populateHostNodeInfo(un, res) } @@ -103,6 +105,13 @@ func populateServiceInfo(un *unstructured.Unstructured, res *ResourceInfo) { res.NetworkingInfo = &v1alpha1.ResourceNetworkingInfo{TargetLabels: targetLabels, Ingress: ingress, ExternalURLs: urls} } +func populateReplicaSetInfo(un *unstructured.Unstructured, res *ResourceInfo) { + replicas, ok, err := unstructured.NestedInt64(un.Object, "spec", "replicas") + if err == nil && ok { + res.Info = append(res.Info, v1alpha1.InfoItem{Name: "Replicas", Value: fmt.Sprintf("Replicas:%d", replicas)}) + } +} + func getServiceName(backend map[string]interface{}, gvk schema.GroupVersionKind) (string, error) { switch gvk.Group { case "extensions": diff --git a/controller/cache/info_test.go b/controller/cache/info_test.go index d0d67244ca4f9..6eff62057a1f1 100644 --- a/controller/cache/info_test.go +++ b/controller/cache/info_test.go @@ -754,3 +754,19 @@ func TestManifestHash(t *testing.T) { assert.Equal(t, expected, hash) assert.Nil(t, err) } + +func TestReplicaSet(t *testing.T) { + replicaSet := strToUnstructured(` + apiVersion: v1 + kind: ReplicaSet + metadata: + name: helm-guestbook + spec: + replicas: 10 +`) + + info := &ResourceInfo{} + populateNodeInfo(replicaSet, info, []string{}) + + assert.Contains(t, info.Info, v1alpha1.InfoItem{Name: "Replicas", Value: "Replicas:10"}) +}