Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NO-JIRA: fix helmchart gather unit test #880

Merged
merged 2 commits into from
Jan 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions docs/gathered-data.md
Original file line number Diff line number Diff line change
Expand Up @@ -771,8 +771,16 @@ None

## HelmInfo

Collects summarized info about the helm usage on a cluster
in a generic fashion
Collects statistics about resources deployed via HelmChart, counting only the resources
with `app.kubernetes.io/managed-by=Helm` and `helm.sh/chart` labels. The data is then summarized
and grouped by hashed namespace.

Resource types included:
- ReplicaSets
- DaemonSets
- StatefulSets
- Services
- Deployments

### API Reference
None
Expand Down
14 changes: 11 additions & 3 deletions pkg/gatherers/workloads/gather_helm_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,16 @@ import (

const labelChartNameKey = "helm.sh/chart"

// GatherHelmInfo Collects summarized info about the helm usage on a cluster
// in a generic fashion
// GatherHelmInfo Collects statistics about resources deployed via HelmChart, counting only the resources
// with `app.kubernetes.io/managed-by=Helm` and `helm.sh/chart` labels. The data is then summarized
// and grouped by hashed namespace.
//
// Resource types included:
// - ReplicaSets
// - DaemonSets
// - StatefulSets
// - Services
// - Deployments
//
// ### API Reference
// None
Expand Down Expand Up @@ -84,7 +92,7 @@ func gatherHelmInfo(
// Anonymize the namespace to make it unique identifier
hash, err := createHash(item.GetNamespace())
if err != nil {
klog.Errorf("unable to hash the namespace '%s': %v", labels[labelChartNameKey], err)
klog.Errorf("unable to hash the namespace '%s': %v", item.GetNamespace(), err)
continue
}

Expand Down
9 changes: 6 additions & 3 deletions pkg/gatherers/workloads/types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,6 @@ func TestAddItem(t *testing.T) {
for _, testCase := range tests {
tt := testCase
t.Run(tt.name, func(t *testing.T) {
t.Parallel()

helmList := newHelmChartInfoList()
for namespace, resources := range tt.info {
for resource, charts := range resources {
Expand All @@ -99,7 +97,12 @@ func TestAddItem(t *testing.T) {
}
}

assert.Equal(t, tt.expectedList, helmList.Namespaces, "expected '%v', got '%v'", tt.expectedList, helmList.Namespaces)
// check equality of elements in slices, ignoring order
for namespace, expectedCharts := range tt.expectedList {
actualCharts, ok := helmList.Namespaces[namespace]
assert.True(t, ok, "expected namespace '%s' not found", namespace)
assert.ElementsMatch(t, expectedCharts, actualCharts, "unexpected charts for namespace '%s'", namespace)
}
})
}
}