-
Notifications
You must be signed in to change notification settings - Fork 39.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
Platform-specific file locking for kubeconfig #107354
Platform-specific file locking for kubeconfig #107354
Conversation
Hi @deejross. Thanks for your PR. I'm waiting for a kubernetes member to verify that this patch is reasonable to test. If it is, they should reply with Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
/assign @soltysh |
/ok-to-test |
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: deejross The full list of commands accepted by this bot can be found here.
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
7eb348e
to
8675999
Compare
/triage accepted |
More specifically: If I have binary A using client-go from kubernetes 1.23 and I have binary B using client-go from kubernetes 1.24 with this change, and they both attempt to lock the configs, one using the .lock file and the other with this approach, presumably with e.g. flock on linux both processes will "lock" the file with their respective approaches and race reading/writing the configs? Repeat question for each platform's unique approach in the new implementation. |
Another great point, I guess it would make sense to deprecate the |
I think that sounds right, there probably needs to be some decision about how many releases. Not sure on that part ... 🤔 Also, we might need to check on client libraries that aren't client-go and this probably will need a release note to warn that other implementations need to be updated to match? (right now this PR has release-note=NONE). |
@BenTheElder any thoughts on the latest changes? |
@@ -26,6 +27,7 @@ import ( | |||
"strings" | |||
|
|||
"github.com/imdario/mergo" | |||
"go.etcd.io/etcd/client/pkg/v3/fileutil" |
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.
not too happy about this ... our client-go depending on "go.etcd.io/etcd/client/pkg/v3/fileutil"
cc @liggitt
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.
It's already in other areas of the codebase: https://github.com/kubernetes/kubernetes/blob/master/go.mod#L80
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.
that's not really relevant... adding dependencies to k8s.io/{api,apimachinery,client-go} pushes them onto far more consumers
were lock-free alternatives like writing to a tmp file and moving to replace considered? |
The current mechanism uses |
right, and they have other problems like requiring the entire directory to be writeable instead of just the kubeconfig file |
@deejross: PR needs rebase. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
sorry, I think these changes address my initial comments, but the other concerns mentioned seem valid. I don't know if there's a good path forward on this. I do think tools are going to race merging changes without some sort of lock (e.g. in my case users concurrently creating KIND clusters all writing to the default $KUBECONFIG), but ...
Atomic file rename would solve that readers unaware of the lock may try to read during writing, but the locks are also important for the problem of "two processes are reading, mutating, then writing back config", e.g. The approach currently in this PR would still support that and address the "directory needs to be writeable" concern once we remove the old .lock code after all these tools are updated to match after some grace period of supporting both modes. IMO writing by atomic rename would be great, but it would bring back the "directory must be writeable" problem * and we'd still have the read-write-merge issue if we didn't also use some other technique. * You can't just write to a temp directory when doing atomic rename because we can only do a |
@BenTheElder what would be the next steps on this? |
: thinking : I don't know if this change needs anything so heavyweight as a KEP, but you might want to at least bring it up with SIG CLI in some way (since it will impact kubectl behavior) and/or api-machinery (client-go). #107354 (comment) seems like the main blocker in review so far, client-go dependencies can be something of a headache, perhaps the subset we need can be re-implemented without additional dependencies (or forked into one of our existing dependencies?), but before going on that route I'd probably try to make sure OWNERS agree. I only own this from a dependency review standpoint, I just also happen to have some familiarity with this code and problem ... |
/remove-sig api-machinery I believe this is a question for SIG CLI, not api machinery. I've removed this from tomorrow's api machinery agenda; feel free to put it back if you want to talk about it anyway, but I don't think we can give you permission (and also I personally agree with the above comments on this PR). |
Looks like I'm late to the game here. For awareness, there has been a long standing request to add this feature in Golang... technically it already exists in Go but lives under IMO if we are going to properly support this, we should align with coming expectations. |
Closing this due to the general consensus being we don't to bring a new dependency into client-go, and would prefer to utilize locking functionality exposed from the Go standard library. |
What type of PR is this?
/kind feature
What this PR does / why we need it:
Previously when writing the kubeconfig file, it would write out a
.lock
file which was used to prevent concurrent writes to the file. This PR replaces that mechanism with a more robust platform-specific locking mechanism usingLockFileEx
for Windows orflock
for Linux.Which issue(s) this PR fixes:
Fixes #
Special notes for your reviewer:
This is my first pass and I made the assumption that we didn't want to change the signature of
WriteToFile
which is why it's structured this way.Also, while previously we were pre-locking all the files at once, they are now locked on-demand.This maintains the pre-locking behavior.Does this PR introduce a user-facing change?
Additional documentation e.g., KEPs (Kubernetes Enhancement Proposals), usage docs, etc.:
Related to conversation found here: #92513