-
Notifications
You must be signed in to change notification settings - Fork 38.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
kubeadm: refactor upgrade plan and apply commands #73135
kubeadm: refactor upgrade plan and apply commands #73135
Conversation
Hi @rojkov. 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. |
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: rojkov If they are not already assigned, you can assign the PR to them by writing 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 |
/ok-to-test |
/test pull-kubernetes-e2e-kops-aws |
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.
Thanks @rojkov
/priority important-longterm
// enforceRequirements verifies that it's okay to upgrade and then returns the variables needed for the rest of the procedure | ||
func enforceRequirements(flags *applyPlanFlags, dryRun bool, newK8sVersion string) (*upgradeVariables, error) { | ||
func enforceRequirements(flags *applyPlanFlags, args []string, dryRun bool, versionIsMandatory bool) (clientset.Interface, upgrade.VersionGetter, *kubeadmapi.InitConfiguration, 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.
I am kind of reluctant to let the args
slice propagate so far down the call stack. In my opinion, we should handle them as early as the run funcs of apply
and plan
.
This can be done in a separate helper func and then we can propagate the results of it to enforceRequirements
.
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.
Yes, makes sense. I've moved args handling in a separate function now.
return err | ||
} | ||
|
||
// Use normalized version string in all following code. | ||
flags.newK8sVersionStr = upgradeVars.cfg.KubernetesVersion | ||
k8sVer, err := version.ParseSemantic(flags.newK8sVersionStr) | ||
newK8sVersion, err := version.ParseSemantic(cfg.KubernetesVersion) |
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 think, that cfg.KubernetesVersion
is going to have the old version here, since it's taken from the ClusterConfiguration
, that is in a config map in the cluster.
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.
@rosti could you please elaborate a bit why this change is worse than the existing code?
In the old code flags.newK8sVersionStr
is set one line above from the same source (upgradeVars.cfg.KubernetesVersion
).
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.
Sorry about that, I must have been blind when I was looking at it. Totally missed the line above that.
16ccf2d
to
6034f8a
Compare
/test pull-kubernetes-kubemark-e2e-gce-big |
@rojkov Can you squash most (if not all) of your commits here into a more general role? /assign @fabriziopandini @neolit123 |
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.
thanks for the cleanup @rojkov
unlike other projects, the k8s project usually doesn't follow the multi-commit per PR.
and we usually squash commits in a PR into one and focus a PR on a single change.
(i've seen exceptions).
with that in mind this PR probably could have been broken in 2-3 scoped single commit PRs.
having said that, i think it's OK to get this PR out of the way.
please, just keep that in mind for the future.
thanks.
LGTM
/lgtm
ping @fabriziopandini for the final /approve
6034f8a
to
089dc59
Compare
@rosti @neolit123 Thank you for review! Just in case the split commits can be found in https://github.com/rojkov/kubernetes/tree/kubeadm-refactor-enforceRequirements-split. |
} | ||
|
||
// Ensure the user is root | ||
klog.V(1).Infof("running preflight checks") |
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.
Please, change Infof
to Infoln
here.
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.
Done
Actually, I spotted a few |
Rremove code duplication in NewCmdApply() and NewCmdPlan() by moving their common logic into enforceRequirements() and getK8sVersionFromUserInput(); Make flags provided by a user read-only structures and drop SetImplicitFlags(). Avoid state maintenance for non-interactiveness in flags.nonInteractiveMode, but rather calculate the mode from immutable variables. Squashed commits: kubeadm: unhide the logic for non-interactiveness kubeadm: use non-formatting constructor for new error kubeadm: unhide version non-emptiness check kubeadm: drop applyFlags.newK8sVersion field since it's not a command line flag. kubeadm: drop applyFlags.newK8sVersionStr field since it's not a command line flag. kubeadm: simplify creating etcdClient kubeadm: move duplicated code into enforceRequirements() kubeadm: drop planFlags type kubeadm: move getting version from user's input to a separate function
089dc59
to
9cf1868
Compare
@rosti Sure, you can count on me. K8s is my day job, though I'm focused on hardware enabling. I'll submit a followup PR for the |
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.
Thanks @rojkov
/lgtm
if err != nil { | ||
return errors.Errorf("unable to parse normalized version %q as a semantic version", flags.newK8sVersionStr) | ||
return errors.Errorf("unable to parse normalized version %q as a semantic version", cfg.KubernetesVersion) |
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'd have to double check that the precedence order is correct, here.
This should definitely be more than 1 PR per refactoring. I'll defer to @fabriziopandini on approval. |
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.
@rojkov thanks for this PR and sorry again for the delay on the review!
At first sight all the changes you are proposing seems reasonable, but I agree with @timothysc (and @neolit123) that probably it is better to break down all the different refactors in multiple PRs.
Please consider that ATM the CI signal for upgrades is not fully reliable, and the complexity of upgrades unfortunately already bite us in the past. Let's move carefully in this area (we are working on improving CI signal, but this will take some time).
PS. I see you are more and more active in kubeadm; I hope we will see you/hear your opinion at the kubeadm office hours soon!
Submitted #73844 as a first PR in a series of split commits comprising this bigger PR. |
/hold |
@rojkov: 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. |
Closing as the content of this PR has been merged from separate PRs referenced above. |
thank you for the separate PRs @rojkov |
Well done @rojkov |
What type of PR is this?
/kind cleanup
What this PR does / why we need it:
The change
NewCmdApply()
andNewCmdPlan()
by moving their common logic intoenforceRequirements()
;flags
provided by a user read-only structures and dropsSetImplicitFlags()
;Does this PR introduce a user-facing change?: