-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
🐛 When loading client config, check os/user.HomeDir if $HOME is unset #753
🐛 When loading client config, check os/user.HomeDir if $HOME is unset #753
Conversation
3b05e25
to
5491ea3
Compare
/lgtm This should be upstream but makes sense here for now. |
// os/user.HomeDir when $HOME is unset. | ||
// | ||
// TODO(jlanford): could this be done upstream? | ||
if _, ok := os.LookupEnv("HOME"); !ok { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
does this actually work? It looks like homedir is called from a static variable initializer -- https://github.com/kubernetes/client-go/blob/master/tools/clientcmd/loader.go#L51
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh good catch. Yeah this won't work. It looks like changing RecommendedHomeFile
will work though since that's what actually ends up getting used: https://github.com/kubernetes/client-go/blob/7ec8a74ae980246e9d1a5734f45bd44fde93a5c1/tools/clientcmd/loader.go#L153
I'll update to just set that directly instead of the HOME env var.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is that thread-safe?
I'm worried that we may have to do a more invasive solution here, like customizing the result of (or not using at all) the NewDefaultBlahBlahBlah method.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe this is now thread-safe. Now, we no longer change any global variables. Instead we create an instance of loadingRules
and then append the extra file derived from u.HomeDir
to the precedence list.
I manually tested this and it still works as expected.
Suggestions on adding a unit test for this? I'm not opposed, but the use of user.Current()
and u.HomeDir
makes it a little awkward. I don't love the idea of creating temporary files and directories in the home directories of anyone that runs the unit tests.
5491ea3
to
e10d30a
Compare
/test pull-controller-runtime-test |
/lgtm |
/hold thread safety |
@DirectXMan12 could you elaborate on the thread safety concern? I'm not seeing it. There is the concern that since this is a bug fix... it would also be good to have a test |
🐛 added multigroup check while creating resource
@kensipe I think the thead-safety concern is that this would change a global variable If multiple callers call any of the methods that use
Final value of @DirectXMan12 I'll look into alternatives. |
239a400
to
5515e31
Compare
/approve |
/hold cancel |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: DirectXMan12, joelanford The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
Following up on the regression introduced in #642 and discussed in #748, this PR detects if $HOME is empty and, if so, automatically sets $HOME to user.Current before using client-go's default loading rules, which only checks $HOME.
As a follow-on, we could submit an issue upstream to see if it makes sense for client-go to use user.Current as a fallback so that we don't have to do it here in controller-runtime.
Closes #748