Skip to content
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

Conversation

rojkov
Copy link

@rojkov rojkov commented Jan 21, 2019

What type of PR is this?
/kind cleanup

What this PR does / why we need it:
The change

  1. removes code duplication in NewCmdApply() and NewCmdPlan() by moving their common logic into enforceRequirements();
  2. makes flags provided by a user read-only structures and drops SetImplicitFlags();
  3. avoids state maintenance for non-interactiveness in flags.nonInteractiveMode, but rather calculates the mode from immutable variables.

Does this PR introduce a user-facing change?:

NONE

@k8s-ci-robot k8s-ci-robot added release-note-none Denotes a PR that doesn't merit a release note. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. needs-priority Indicates a PR lacks a `priority/foo` label and requires one. labels Jan 21, 2019
@k8s-ci-robot
Copy link
Contributor

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 /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

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.

@k8s-ci-robot k8s-ci-robot added needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels Jan 21, 2019
@rojkov rojkov changed the title Kubeadm refactor version big enforce requirements kubeadm: refactor upgrade plan and apply commands Jan 21, 2019
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: rojkov
To fully approve this pull request, please assign additional approvers.
We suggest the following additional approver: fabriziopandini

If they are not already assigned, you can assign the PR to them by writing /assign @fabriziopandini in a comment when ready.

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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added area/kubeadm sig/cluster-lifecycle Categorizes an issue or PR as relevant to SIG Cluster Lifecycle. and removed needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. labels Jan 21, 2019
@kad
Copy link
Member

kad commented Jan 21, 2019

/ok-to-test

@k8s-ci-robot k8s-ci-robot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Jan 21, 2019
@rojkov
Copy link
Author

rojkov commented Jan 21, 2019

/test pull-kubernetes-e2e-kops-aws

Copy link
Member

@yagonobre yagonobre left a 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

@k8s-ci-robot k8s-ci-robot added priority/important-longterm Important over the long term, but may not be staffed and/or may need multiple releases to complete. and removed needs-priority Indicates a PR lacks a `priority/foo` label and requires one. labels Jan 21, 2019
// 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) {
Copy link
Contributor

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.

Copy link
Author

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)
Copy link
Contributor

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.

Copy link
Author

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).

Copy link
Contributor

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.

@rojkov rojkov force-pushed the kubeadm-refactor-version-big-enforceRequirements branch from 16ccf2d to 6034f8a Compare January 24, 2019 09:20
@rojkov
Copy link
Author

rojkov commented Jan 29, 2019

/test pull-kubernetes-kubemark-e2e-gce-big

@rosti
Copy link
Contributor

rosti commented Jan 30, 2019

@rojkov Can you squash most (if not all) of your commits here into a more general role?
This needs more reviews as it's size/L and I may have missed something.

/assign @fabriziopandini @neolit123
/cc @yagonobre

Copy link
Member

@neolit123 neolit123 left a 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

@rojkov rojkov force-pushed the kubeadm-refactor-version-big-enforceRequirements branch from 6034f8a to 089dc59 Compare January 31, 2019 08:31
@k8s-ci-robot k8s-ci-robot removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jan 31, 2019
@rojkov
Copy link
Author

rojkov commented Jan 31, 2019

@rosti @neolit123 Thank you for review!
Indeed I was going to squash the commits after review, so I did it now and rebased.

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")
Copy link
Contributor

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.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@rosti
Copy link
Contributor

rosti commented Jan 31, 2019

Actually, I spotted a few Infofs in plan.go and apply.go, that are not touched by this PR. They are out of the scope of it, but need to be fixed.
@rojkov given, that you work in this area, can we count on you for a followup PR fixing those? If you don't have the time I'll create a help wanted issue.

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
@rojkov rojkov force-pushed the kubeadm-refactor-version-big-enforceRequirements branch from 089dc59 to 9cf1868 Compare January 31, 2019 10:25
@rojkov
Copy link
Author

rojkov commented Jan 31, 2019

@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 Infofs.

Copy link
Member

@yagonobre yagonobre left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @rojkov
/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Feb 5, 2019
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)
Copy link
Member

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.

@timothysc
Copy link
Member

This should definitely be more than 1 PR per refactoring. I'll defer to @fabriziopandini on approval.

Copy link
Member

@fabriziopandini fabriziopandini left a 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!

@rojkov
Copy link
Author

rojkov commented Feb 8, 2019

Submitted #73844 as a first PR in a series of split commits comprising this bigger PR.

@fabriziopandini
Copy link
Member

/hold
as per comment above

@k8s-ci-robot k8s-ci-robot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Feb 11, 2019
@k8s-ci-robot
Copy link
Contributor

@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.

@rojkov
Copy link
Author

rojkov commented Feb 28, 2019

Closing as the content of this PR has been merged from separate PRs referenced above.

@rojkov rojkov closed this Feb 28, 2019
@neolit123
Copy link
Member

thank you for the separate PRs @rojkov

@fabriziopandini
Copy link
Member

Well done @rojkov

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/kubeadm cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. lgtm "Looks good to me", indicates that a PR is ready to be merged. needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. priority/important-longterm Important over the long term, but may not be staffed and/or may need multiple releases to complete. release-note-none Denotes a PR that doesn't merit a release note. sig/cluster-lifecycle Categorizes an issue or PR as relevant to SIG Cluster Lifecycle. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants