-
Notifications
You must be signed in to change notification settings - Fork 39.6k
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
Implement kubeadm upgrade diff
#63930
Conversation
I couldn't think of any tests that would provide much useful signal here and wouldn't be brittle across versions. If anyone has any suggestions I'm open to them! |
/cc @kubernetes/sig-cluster-lifecycle-pr-reviews |
cmd/kubeadm/app/cmd/upgrade/diff.go
Outdated
|
||
k8sVer, err := version.ParseSemantic(flags.newK8sVersionStr) | ||
if err != nil { | ||
kubeadmutil.CheckErr(err) |
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 really hard to write unit tests around CheckErr()
as it effectively calls exit(1)
on error.
:(
i would return an error
from this function an only call a single CheckErr()
on that error in the Cobra Run()
.
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.
Can you please file an issue to improve that? Such unit testing would be a perfect contribution from you 👍
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.
shouldn't a unit test be added as part of this PR? @liztio WDYT?
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.
@neolit123 like I said, I couldn't figure out what good unit tests would look like since the diffs are likely to change a lot between versions. I'm open to ideas on what they could look like.
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.
possible tests:
- non existing config path in
flags.parent.cfgPath
flags.newK8sVersionStr == ""
, but noversion
arg is provided- bad version format in
flags.newK8sVersionStr
to make ParseSemantic() fail - make
kubeadmutil.MarshalToYaml
fail somehow. - fail
ioutil.ReadFile(path)
by providing bad 'path'
i don't think that the diff output itself should be tested - e.g. making sure that a diff buffer looks exactly like another diff buffer.
one problem i have with Lucas' request is that my setup is quite broken at the moment, so if you want me to add tests for this, i would need a fully working master configuration yaml aaand i might ask some questions too - because i simply don't understand some of the things 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.
@liztio TLDR if you are out of time and want me to help send me a YAML that returns nil
for runDiff()
.
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.
Those sound good. Unfortunately, I'm out thursday and friday this week, and it's basically the end of my day. So given the choice between adding unit tests and missing the 0.11 deadline, I'll defer the unit tests until I get back. I made an issue so I don't forget to follow up.
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.
A couple of small comments only, generally LGTM
cmd/kubeadm/app/cmd/upgrade/diff.go
Outdated
|
||
k8sVer, err := version.ParseSemantic(flags.newK8sVersionStr) | ||
if err != nil { | ||
kubeadmutil.CheckErr(err) |
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.
Can you please file an issue to improve that? Such unit testing would be a perfect contribution from you 👍
cmd/kubeadm/app/cmd/upgrade/diff.go
Outdated
} | ||
|
||
// Convert to an internal representation | ||
internalcfg := &kubeadmapi.MasterConfiguration{} |
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 already is internal, why have these lines of code 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.
whoops, leftover from a rebase.
cmd/kubeadm/app/cmd/upgrade/diff.go
Outdated
corev1 "k8s.io/api/core/v1" | ||
kubeadmapi "k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm" | ||
"k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm/scheme" | ||
kubeadmapiext "k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm/v1alpha2" |
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.
We use kubeadmv1alpha2
as the name everywhere else currently. If you care strongly about the naming there, please open an issue to change it to something else, but please be consistent for now.
cmd/kubeadm/app/cmd/upgrade/diff.go
Outdated
var cfg *kubeadmapi.MasterConfiguration | ||
|
||
// If the version is specified in config file, pick up that value. | ||
if flags.parent.cfgPath != "" { |
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.
Technically I don't think you should need to do this, as ConfigFileAndDefaultsToInternalConfig
has this conditional inside of itself.
cmd/kubeadm/app/cmd/upgrade/diff.go
Outdated
continue | ||
} | ||
|
||
new, err := kubeadmutil.MarshalToYaml(&pod, corev1.SchemeGroupVersion) |
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 new a keyword? can you make the name a bit longer like newPodYAML
?
cmd/kubeadm/app/cmd/upgrade/diff.go
Outdated
|
||
cmd := &cobra.Command{ | ||
Use: "diff [version]", | ||
Short: "Show what differences would be applied to existing static pod manifests", |
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.
Can you please add a reference to apply --dry-run
here so that it's more discoverable?
30e2356
to
2ab79d7
Compare
This command takes an upgrade version, and shows how the static pod manifests will be changed by a given upgrade.
path = flags.schedulerManifestPath | ||
default: | ||
glog.Errorf("[diff] unknown spec %v", spec) | ||
continue |
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 it OK to skip unknown specs here?
should we return fmt.Errorf()
instead.
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 prefer to err on the side of not breaking this for users. This shouldn't come up, but in case it does I don't want it to break upgrade diff
altogether.
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.
sounds good.
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.
/lgtm
/approve
Thanks Liz, this is a very useful UX improvement 🎉!
/assign @pwittrock |
/retest I'm just gonna add it manually, makes no sense to have a dedicated approver for that old stuff we don't care about anymore |
[APPROVALNOTIFIER] This PR is APPROVED Approval requirements bypassed by manually added approval. This pull-request has been approved by: liztio, luxas 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 |
Automatic merge from submit-queue (batch tested with PRs 63865, 57849, 63932, 63930, 63936). If you want to cherry-pick this change to another branch, please follow the instructions here. |
What this PR does / why we need it:
Some users want to see the changes
kubeadm
woulda apply before actually runningkubeadm upgrade apply
. This shows the changes that will be made to the static pod manifests before applying them. This is a narrower case thankubeadm upgrade apply --dry-run
, which specifically focuses on the static pod manifests.Which issue(s) this PR fixes:
Part of kubeadm/489
Fixes kubernetes/kubeadm#830
Special notes for your reviewer:
Release note: