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
Cloud node controller: Only call once into cloud provider #85735
Cloud node controller: Only call once into cloud provider #85735
Conversation
/assign @andrewsykim |
|
||
type nodeModify func(*v1.Node) | ||
var nodeModifyers []nodeModify |
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.
modifiers
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.
Fixed
type nodeModify func(*v1.Node) | ||
var nodeModifyers []nodeModify | ||
|
||
if err := func() error { |
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.
This warrants AT LEAST a comment, if not being a whole new function
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.
Yeah, I was trying to minimize the diff for this PR. I have factored this out to keep the code readable.
if curNode.Spec.ProviderID == "" { | ||
providerID, err := cloudprovider.GetInstanceProviderID(ctx, cnc.cloud, types.NodeName(curNode.Name)) | ||
if err == nil { | ||
curNode.Spec.ProviderID = providerID | ||
nodeModifyers = append(nodeModifyers, func(n *v1.Node) { |
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.
Before this PR, the whole loop would be retried. That would re-evaluate the conditional above. I am not SUPER familiar with this, but it seems that it's safe NOT to re-evaluate the conditional, since (if we did lose a race and hit a conflict) this modify function will be idempotent, right?
If so, please comment. Maybe above, where you declare vars, explain that such modify funcs MUST be safe idempotent in the face of a conflict-and-retry loop
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.
In other words, this is tricky enough that I am asking you to make it more obvious by comments, code structure, or both.
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 did add godocs mentioning why those modify
funcs exist and what expectations there are. Also, this particular part actually did introduce a change in behavior, by allowing to overwrite an existing providerID, which wasn't possible before. I fixed that by also doing the empty string check in the modify
.
d5b2845
to
7326a50
Compare
80a124e
to
f5b5b77
Compare
/retest |
f5b5b77
to
18fa7bd
Compare
Thanks! /lgtm |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: alvaroaleman, thockin 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 |
What type of PR is this?
/kind cleanup
What this PR does / why we need it:
Currently, the cloud provider node initialization wraps both the "calling to cloud provider" and "update node" into a
retry.RetryOnConflict
. Since calling into the cloudprovider is a pretty expensive operation and there is a high chance of hitting a conflict especially for a new node, this PR changes that behaviour to re-use the result of calling into the cloud provider using a set of modify funcs.I also thought about using patch, but assumed that if it was that easy someone would have done it long ago already.
Which issue(s) this PR fixes:
Fixes #
Special notes for your reviewer:
Does this PR introduce a user-facing change?:
Additional documentation e.g., KEPs (Kubernetes Enhancement Proposals), usage docs, etc.: