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
helm template inconsistently respects the --namespace option in different environments #12124
Comments
I've tracked the issue down to the lack of kubeconfig in CI. This is definitely a bug in helm, as it should not require a kubeconfig or any contact with any kubernetes cluster in order to generate a template. The following patch makes it work for our purposes: diff --git a/pkg/cli/environment.go b/pkg/cli/environment.go
index dac2a4bc..d8a25c18 100644
--- a/pkg/cli/environment.go
+++ b/pkg/cli/environment.go
@@ -223,6 +223,9 @@ func (s *EnvSettings) Namespace() string {
if ns, _, err := s.config.ToRawKubeConfigLoader().Namespace(); err == nil {
return ns
}
+ if s.namespace != "" {
+ return s.namespace
+ }
return "default"
} |
If I summarize my understanding of the above: |
Yes, it ignores the |
I think you're right, and this is a bug. A PR would be appreciated please. |
@gjenkins8 There already is one #12126 |
I couldn't duplicate this behavior. I unset KUBECONFIG set HOME=/tmp and ran namespacetest.zip |
@joejulian When I was testing this change, I just moved my ~/.kube directory. Perhaps something is not respecting the KUBECONFIG or HOME vars. |
Nope, still no failure.
I'll need a way to reproduce this problem with that chart in order to be able to approve this PR. |
I've also been unable to reproduce it now, but I think my coworker just hit this today. I've asked them to see if they can isolate the reproduction. |
Looking at the code, "default" will be used instead of the specified value if an err is encountered in s.config.ToRawKubeConfigLoader().Namespace() in the code snippet you have pointed out.
|
@MichaelMorrisEst Thank you for coming up with a reproduction! I am also able to reproduce it with that, or if I put invalid yaml into I'm surprised I even think that my original fix is sub-optimal, as it should probably be above the line that reads the config. diff --git a/pkg/cli/environment.go b/pkg/cli/environment.go
index dac2a4bc..fbd82b80 100644
--- a/pkg/cli/environment.go
+++ b/pkg/cli/environment.go
@@ -220,6 +220,9 @@ func (s *EnvSettings) EnvVars() map[string]string {
// Namespace gets the namespace from the configuration
func (s *EnvSettings) Namespace() string {
+ if s.namespace != "" {
+ return s.namespace
+ }
if ns, _, err := s.config.ToRawKubeConfigLoader().Namespace(); err == nil {
return ns
} |
This issue has been marked as stale because it has been open for 90 days with no activity. This thread will be automatically closed in 30 days if no further activity occurs. |
Any update on this? Helm really shouldn't need to interact with kubernetes to template yaml files. |
This issue has been marked as stale because it has been open for 90 days with no activity. This thread will be automatically closed in 30 days if no further activity occurs. |
Definitely still a bug |
Still a bug, and my PR is still a merge-able fix waiting for review #12126 |
Expected behavior:
When running
helm template
with the--namespace
argument, it should set the.Release.Namespace
variable, and any templates using that variable should be set to the value of the--namespace
argument.Actual behavior:
It is inconsistent about setting the
.Release.Namespace
variable. On my and my coworker's laptops, it works as expected. In our CI, it doesn't set it to the value of the--namespace
argument, but instead just defaults todefault
.It works on our laptops with or without docker, but in CI it doesn't. The same versions of
helm
andkubectl
are used on my laptop and in CI. The inconsistency persists even when running locally in the same Docker image used by CI (so the python versions are also the same).We've looked very hard for differences in our environments, and can find none, which leaves me to suspect helm itself is inconsistent.
Additional context:
Specifically, we're attempting to template the aws-ebs-csi-driver chart, version 2.19.0, from https://kubernetes-sigs.github.io/aws-ebs-csi-driver .
We're calling
helm template
in a python script pointing at a locally vendored copy of the chart. Values are passed to stdin.An example template in the chart which is rendered differently in CI vs locally (the namespace is
kube-system
locally, but in CI is rendered todefault
):Output of
helm version
:Output of
kubectl version
:Server version is not relevant to
helm template
.Cloud Provider/Platform (AKS, GKE, Minikube etc.):
N/A, but our CI is running in Github Actions and we're running
helm template
in a Docker container.The text was updated successfully, but these errors were encountered: