-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Get HomeDir from os/user.Current().HomeDir and fallback with $HOME #1261
Comments
This is still a breaking change. client-go is not the only client library in the project and clients are expected to have the same lookup behavior for KUBECONFIG and have for many years. even if client-go were the only client, skew between different versions is a problem.
That comment may be the intent, but the actual behavior is observable and well known and has additional implementations (many of which are not written in Go). Changing behavior like this requires a KEP (Kubernetes Enhancement Proposal) to outline how we will safely roll out behavioral changes and formally have area owners accept a proposed change that is not a bug-fix. As previously mentioned please see the existing discussion for XDG, which is at least a standard not specific to snap: kubernetes/enhancements#2111 Frankly, I would not recommend using a snap for kubectl. It's a single-file static go binary. $HOME is in the POSIX portable operating systems standard that should be pointed at the user's home directory. Presumably snap packages could wrap kubectl with a shim that sets |
Also: Any disucussion here or in kubernetes/kubernetes doesn't change the fact that this would require a KEP similar to kubernetes/enhancements#2111, and that the owners of the client have previously rejected similar changes. Even if I agreed that we should change the implementation, we could not do so without a formal accepted proposal like the one rejected in kubernetes/enhancements#2111. As mentioned repeatedly, a detailed KEP could be considered, otherwise this behavior is not changing. Until then I think you could just make the kubectl snap be: #!/usr/bin/sh
HOME=$SNAP_REAL_HOME kubectl-real $@
|
Although I'm still not happy, thankfully there's someone standing out explaining what it actually breaks finally. I admit that fixing the BUG itself is a breaking change, but I would still point out that it's not as easy as you mentioned to mitigate this issue. Snap is designed to run in an isolated environment, which means they are not supposed to have any read or write access to any other programs' files (similar to the concept of the container but without cgroups). Since the majority of the programs just need to have their own config files and logs under $HOME, and nothing else, they choose to remap $HOME so that the majority of the programs can easily get packed as a snap without any code change. Now, things changed for a Kubernetes client, since reading the
I have already checked that PR a long time ago when you mention it there kubernetes/kubernetes#117165 (comment), and it has a completely different situation than the one I'm proposing. There it says:
I'm in charge of packaging kubescape/kubescape as a snap package, and our own kubescape/k8s-interface depends on kubernetes-sigs/controller-runtime to get kubenetes config files. So I first went there and proposed the change kubernetes-sigs/controller-runtime#2266, but got rejected since the maintainer said "It doesn't make sense". While controller-runtime depends on the client-go, I go up here and propose the change again. So as you can see, we don't rely on kubectl binaries but the client-go library. In addition, wrapping kubescape with a shim that sets HOME=$SNAP_REAL_HOME will not work as kubescape have its own config files to get stored in the snap remapped Considering the words here kubernetes/kubernetes#117165 (comment) Also, if you think bugs can also be a feature and own style of behavior, and we shall fix no bugs and make no improvements to introduce no breaks at all, then I have nothing to say. I won't waste time looking into any possible solutions for you related to this anymore, as long as you think that fixing this bug is a breaking change. |
thank you! |
Continuation of kubernetes/kubernetes#117165 as the conversation has been limited to collaborators.
Background
Since snap contaminates the $HOME out of their own considerations, software running under snap can't use the $HOME value to get the current user's real home directory. (Snap then introduced
$SNAP_REAL_HOME
to store the original $HOME value before their contamination, then I proposed that change to use$SNAP_REAL_HOME
to get client-go working, but as you can see, that PR got strongly rejected)Propose
Now I realize that
os/user.Current().HomeDir
actually returns the current user's real home directory even under the snap environment, so to fix this in a way that can never break anything normal, we simply rely on theos/user.Current().HomeDir
to get the HomeDir since namely the client-fo function should have the same feature as the Go native one according to the comment (// HomeDir returns the home directory for the current user.
). We will only fall back to $HOME blindly when there is something wrong with getting the current user (os/user.Current()
) or the HomeDir value is empty.I have created a patch for demoing my proposed change: https://github.com/kubescape/packaging/blob/main/snap_homedir.patch If you finally decide to accept this, I'm willing to realize it into a PR.
cc: @BenTheElder
The text was updated successfully, but these errors were encountered: