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

helm mixes namespaces from kubeconfig file and actionConfig.Init funtion #13037

Open
fragpit opened this issue May 15, 2024 · 3 comments
Open
Labels
bug Categorizes issue or PR as related to a bug. v4.x Issues deferred for v4 discussion

Comments

@fragpit
Copy link

fragpit commented May 15, 2024

I'm developing a Golang application that uses Helm as a library. And I noticed the behavior that Helm ignores the client settings and uses the namespace that is specified in kubeconfig. Here is my function code:

func (vc *HelmConn) DeleteHelmRelease(name, ns string) error {
	actionConfig := new(action.Configuration)

	if err := actionConfig.Init(vc.HelmConfig.RESTClientGetter(), ns, "", log.Printf); err != nil {
		return err
	}

	client := action.NewUninstall(actionConfig)
	client.Timeout = helmDeleteTimeout
	client.DeletionPropagation = "background"
	client.Wait = true

	_, err := client.Run(name)
	if err != nil {
		return err
	}

	return nil
}

at the same time, even the namespace from kubeconfig is not fully used. Let's say namespace test1 is set in kubeconfig, and I pass namespace test2 to the function, the result will be:

  • helm release (metadata) will be removed from namespace test2
  • k8s resources will be removed from namespace test1
  • post-install hooks will run in namespace test1 , but {{ .Release.Namespace }} in hooks template will be test2.

Also in command line utility I managed to reproduce the same behavior.

  1. Set namespace test1 in kubeconfig
  2. run helm uninstall release_name
  3. immediately change the namespace in kubeconfig to test2.

The result will be the same as described above.

Output of helm version:

version.BuildInfo{Version:"v3.14.4", GitCommit:"81c902a123462fd4052bc5e9aa9c513c4c8fc142", GitTreeState:"clean", GoVersion:"go1.22.2"}

Output of kubectl version:

Client Version: v1.30.1
Kustomize Version: v5.0.4-0.20230601165947-6ce0bf390ce3
Server Version: v1.23.16+k3s1
WARNING: version difference between client (1.30) and server (1.23) exceeds the supported minor version skew of +/-1
@fragpit
Copy link
Author

fragpit commented May 16, 2024

I managed to set namespace in my code with

	vc.HelmConfig.SetNamespace(ns) // var vc.HelmConfig *cli.EnvSettings

which is an analogy of using --namespace flag in command line client.

But still there is a dangerous behavior when accidentally changing namespace in kubeconfig file while helm uninstall ... command is running.

@banjoh
Copy link

banjoh commented May 20, 2024

@fragpit this feels like a race condition somewhere where helm uninstall. Perhaps helm re-initialises its kubernetes client connection, fetching kubeconfig again. I have tried to reproduce using the CLI but I cannot. The steps are clear, so thanks for that. Do you mind providing a reproducer chart and commands someone can run? Pasting the exact commands would help.

@gjenkins8 gjenkins8 added question/support bug Categorizes issue or PR as related to a bug. v4.x Issues deferred for v4 discussion and removed question/support labels May 20, 2024
@gjenkins8
Copy link
Contributor

The SDK was not very well separated from the CLI when it was first realized. Please do what is needed for your current project (it is intended the SDK is used like this). There are plans to clean this up.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Categorizes issue or PR as related to a bug. v4.x Issues deferred for v4 discussion
Projects
None yet
Development

No branches or pull requests

3 participants