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

fix: Default the Helm manifest namespace to the release namespace #95

Merged
merged 1 commit into from
Jan 29, 2021
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: 12 additions & 0 deletions pkg/collector/helm2.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package collector

import (
"fmt"

corev1 "k8s.io/client-go/kubernetes/typed/core/v1"
"k8s.io/client-go/tools/clientcmd"

Expand Down Expand Up @@ -71,6 +72,17 @@ func (c *HelmV2Collector) Get() ([]map[string]interface{}, error) {
err := fmt.Errorf("failed to parse release %s/%s: %v", r.Namespace, r.Name, err)
return nil, err
}

// Default to the release namespace if the manifest doesn't have the namespace set
if meta, ok := manifest["metadata"]; ok {
switch v := meta.(type) {
case map[string]interface{}:
if _, ok := v["namespace"]; !ok {
v["namespace"] = r.Namespace
}
}
}

results = append(results, manifest)
}
}
Expand Down
12 changes: 12 additions & 0 deletions pkg/collector/helm3.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package collector

import (
"fmt"

corev1 "k8s.io/client-go/kubernetes/typed/core/v1"
"k8s.io/client-go/tools/clientcmd"

Expand Down Expand Up @@ -71,6 +72,17 @@ func (c *HelmV3Collector) Get() ([]map[string]interface{}, error) {
err := fmt.Errorf("failed to parse release %s/%s: %v", r.Namespace, r.Name, err)
return nil, err
}

// Default to the release namespace if the manifest doesn't have the namespace set
if meta, ok := manifest["metadata"]; ok {
switch v := meta.(type) {
case map[string]interface{}:
if _, ok := v["namespace"]; !ok {
v["namespace"] = r.Namespace
}
}
}

results = append(results, manifest)
}
}
Expand Down