Skip to content

Commit

Permalink
NO-JIRA: fix helmchart gather unit test (#880)
Browse files Browse the repository at this point in the history
* test: fix helmchart gather unit test

* docs: better gather helm docs
  • Loading branch information
Ricardo Lüders authored Jan 23, 2024
1 parent 6fc5127 commit 226e253
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 8 deletions.
12 changes: 10 additions & 2 deletions docs/gathered-data.md
Original file line number Diff line number Diff line change
Expand Up @@ -773,8 +773,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)
}
})
}
}

0 comments on commit 226e253

Please sign in to comment.