-
Notifications
You must be signed in to change notification settings - Fork 7k
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
Go SDK installing Kubernetes resources to the wrong namespaces #8780
Comments
I think this may be related to #8685. |
I understand the confusion and in Helm v4 we may be able to more easily refine the API to make this easier. There are things I would change to make the experience better. I believe this is a bug. One complicated enough I don't have a quick fix for. Here is what I see happening. When When In the Helm client this works as expected because of the way it's built. But, the SDK can have issues. There is no way, currently, to set the namespace for the KubeClient to use. I manually tested all of this out. Now we need to find the best way to fix this issue. |
jup im experiencing the same issues, which makes using the go client pretty much unusable. the release gets installed in the targeted namespaced, but the resources get applied to the namespace in the kubeconfig (default in my case) |
We are experiencing the same issue as @philipp1992 |
There is a way to change the namespace parameter in the KubeClient after it’s been instantiated. You just need to acquire a handle to the client... Which I do not believe is readily available from within the action.Configuration object: https://github.com/helm/helm/blob/master/pkg/kube/client.go#L63 https://github.com/helm/helm/blob/master/pkg/kube/client.go#L143 |
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. |
This seems to have been closed, but as I read this, no solution is provided. This really does make using the SDK extremely difficult. I have to manually code my namespace into all my templates. Is there really nothing that can be done in Helm here? As @bacongobbler points out, if the underlying KubeClient were simply exported (I think that is what he is getting at), then I could resolve this. |
Just a note to anybody who comes across this issue. The solution proposed in #9171 worked for me (e.g., setting |
The issue here is that the kube client namespace cannot be set or changed easily programmatically. I dealt with it not long ago and feel everyone's frustration. I did manage to come up with a work around for the project I'm working on. First, what's happening... a.Init(c.RESTClientGetter(), "default", "", debug) When this line (from the original snippet) is executed two things initially happen... Lines 365 to 372 in e9e6b07
The first this is that a kube client is created. Later that is attached to the action configurations The second thing is a lazyclient is created with a namespace. This is for the storage of the Helm release record. The release record and the Kubernetes resource locations can be different. So far we have a blank namespace, which will go with the default per your kubeconfig, and one tied to a namespace. It's worth noting that the lazyclient namespace which is injected into the storage drivers isn't something that's easily changed with the API. But, there is a way to change that, too. After There is no native way to set the KubeClient namespace. I lost hours trying to solve for this. I've found a work around for custom applications. The basics of it are in this file. Instead of using action configuration... we use our own wrapper just to add a method... // Configuration is a composite type of Helm's Configuration type
type Configuration struct {
*action.Configuration
} Then we added a By switching on the Note, there is technically no need to create a function or extend the action configuration. In the main line code above the relevant switch statements could be used. We just did that to easily contain the code. |
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. |
#9171 didn't solve the problem for me. What seems to work is the solution of Hypher
|
I am working on a standalone Go binary that uses the
helm
Go APIs to deploy a chart. The tricky part is that the binary is a long-running service running in a particular namespace, and it's deploying arbitrary helm charts to other, arbitrary namespaces. The perhaps more tricky part is that this binary is expected to be concurrency-safe, so more than one deployment may happen at once.The problem that I am experiencing is when that the service (running in namespace
nhi
) deploys a chart, the helm chart itself lands in the desired namespaces ("default"), but the kubernetes resources described by the chart land in thenhi
namespaces.This situation has been discussed in a number of other issues, but I am not clear at this point if this is the expected behavior (and if so, I don't understand why), or if it's an acknowledged bug. I think that I have read (and I may be wrong) that the target namespace get derived from the kube context, but I am not sure that works for me given the constraints mentioned above.
I have a demo project that illustrates the problem: https://github.com/object88/namespaced-helm-install. Relevant code snippet:
The
test.sh
command will build and push the "server" docker image to thenhi
namespace, and deploy the server. (if you run this, you may need to manually create that namespace. Also, you will need to comment this out code to build and publish the docker image, or change to a different dockerhub repo) The server then attempts to deploy a different chart, "foo" to the "default" namespace. After runningtest.sh
, you can run the following commands:Contents of
go.mod
:Output of
kubectl version
:Cloud Provider/Platform (AKS, GKE, Minikube etc.):
minikube
Thanks for any feedback, corrections for my code, or otherwise.
The text was updated successfully, but these errors were encountered: