Skip to content

Commit

Permalink
add replicas info item to ReplicaSet node
Browse files Browse the repository at this point in the history
Signed-off-by: Zach Hammer <[email protected]>
  • Loading branch information
zhammer committed May 17, 2024
1 parent 210f26a commit 6fa0381
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
9 changes: 9 additions & 0 deletions controller/cache/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -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":
Expand Down
16 changes: 16 additions & 0 deletions controller/cache/info_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"})
}

0 comments on commit 6fa0381

Please sign in to comment.