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: modify SetKubernetesVersion #69645

Merged
merged 1 commit into from
Oct 15, 2018

Conversation

neolit123
Copy link
Member

@neolit123 neolit123 commented Oct 11, 2018

What this PR does / why we need it:

Without this patch SetKubernetesVersion does not set
a version in all locations where it's called, because
the passed config to it always has a default version
stable-1.

This always triggers the != "" check and the function
returns without setting a version.

Validate against DefaultKubernetesVersion instead.

This fixes all cases where fetching a version from the internet
is not needed at all - e.g. "kubeadm token create".

Which issue(s) this PR fixes (optional, in fixes #<issue number>(, fixes #<issue_number>, ...) format, will close the issue(s) when PR gets merged):
refs #kubernetes/kubeadm#1166

Special notes for your reviewer:
NONE

Release note:

kubeadm: fix a case where fetching a kubernetesVersion from the internet still happened even if some commands don't need it.

/assign @xiangpengzhao
/assign @fabriziopandini
/cc @timothysc
/kind bug

Peter, this is related to your patch about:

// KubernetesVersion is not used, but we set it explicitly to avoid the lookup
// of the version from the internet when executing ConfigFileAndDefaultsToInternalConfig

5cf9291

WDYT?
i don't see a problem with having the function like that in the current codebase - i.e it would override with the client version, but this will avoid fetching from the internet if labels are passed.

also, it's not a critical bug, but i'd vote for us to cherry pick this for 1.12.

@k8s-ci-robot k8s-ci-robot added the release-note Denotes a PR that will be considered when it comes time to generate release notes. label Oct 11, 2018
@k8s-ci-robot k8s-ci-robot added kind/bug Categorizes issue or PR as related to a bug. size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels Oct 11, 2018
@k8s-ci-robot k8s-ci-robot added area/kubeadm sig/cluster-lifecycle Categorizes an issue or PR as relevant to SIG Cluster Lifecycle. labels Oct 11, 2018
@neolit123 neolit123 changed the title kubeadm: make SetKubernetesVersion explicit kubeadm: modify SetKubernetesVersion Oct 11, 2018
@neolit123
Copy link
Member Author

neolit123 commented Oct 11, 2018

found issue with the initial patch that i sent, applied modification and renamed the PR too.

@neolit123
Copy link
Member Author

/retest

Copy link
Contributor

@xiangpengzhao xiangpengzhao left a comment

Choose a reason for hiding this comment

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

@neolit123 Agree with your idea 👍 EDIT: I misread the PR body. You're correct on the condition change.

Copy link
Contributor

@xiangpengzhao xiangpengzhao left a comment

Choose a reason for hiding this comment

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

Just one concern, otherwise LGTM. Thanks for fixing this! @neolit123

func SetKubernetesVersion(client clientset.Interface, cfg *kubeadmapiv1beta1.InitConfiguration) error {
if cfg.KubernetesVersion != "" {

if cfg.KubernetesVersion != kubeadmapiv1beta1.DefaultKubernetesVersion {
Copy link
Contributor

Choose a reason for hiding this comment

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

Although cfg.KubernetesVersion is not empty by default, do we still want to check against the empty case here ? In case it changes to an empty default value for any reason in the future?

Copy link
Contributor

Choose a reason for hiding this comment

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

/lgtm

Copy link
Member Author

Choose a reason for hiding this comment

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

@xiangpengzhao

hm, so if the default changes to "" the branch will handle it and return.
but i'm wondering if we should handle "" with the current default not being "".

if cfg.KubernetesVersion != kubeadmapiv1beta1.DefaultKubernetesVersion && cfg.KubernetesVersion != "") {
    return nil
}

^ i assume this is what we want?

Copy link
Member

Choose a reason for hiding this comment

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

So, my general hot-take is that we should test all the different scenarios of input to the function.

Copy link
Member Author

Choose a reason for hiding this comment

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

sounds good.
will update the PR tomorrow.

Copy link
Contributor

Choose a reason for hiding this comment

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

SGTM :)

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Oct 11, 2018
Copy link
Member

@timothysc timothysc left a comment

Choose a reason for hiding this comment

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

This points to a gap in testing, could you please add a unit test for the different scenarios.

func SetKubernetesVersion(client clientset.Interface, cfg *kubeadmapiv1beta1.InitConfiguration) error {
if cfg.KubernetesVersion != "" {

if cfg.KubernetesVersion != kubeadmapiv1beta1.DefaultKubernetesVersion {
Copy link
Member

Choose a reason for hiding this comment

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

So, my general hot-take is that we should test all the different scenarios of input to the function.

@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed lgtm "Looks good to me", indicates that a PR is ready to be merged. size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. labels Oct 12, 2018
@neolit123
Copy link
Member Author

updated:

  • added a unit test for SetKubernetesVersion
  • modified the function to use version.Get().String() directly too.

Copy link
Contributor

@xiangpengzhao xiangpengzhao left a comment

Choose a reason for hiding this comment

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

Good refactoring 👍 Just one concern, otherwise LGTM.

output: ver,
},
{
name: "any other version is processed",
Copy link
Contributor

Choose a reason for hiding this comment

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

Seems like the logic of SetKubernetesVersion is "empty version and default version is processed and any other version is skipped". @neolit123 WDYT?

Copy link
Member Author

Choose a reason for hiding this comment

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

sorry, was in a rush and got things mixed up. i will update the PR later today.

Copy link
Member Author

Choose a reason for hiding this comment

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

updated. :)

Without this patch SetKubernetesVersion does not set
a version in all locations where it's called, because
the passed config to it always has a default version
stable-1.

This always triggers the != "" check and the function
returns without setting a version.

Validate against DefaultKubernetesVersion and "" instead.

This fixes all cases where fetching a version from the internet
is not needed at all - e.g. "kubeadm token create".

Also make SetKubernetesVersion default to version.Get().String()
and add unit tests for the function.
@neolit123
Copy link
Member Author

/retest

Copy link
Member

@timothysc timothysc 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 @neolit123

/lgtm
/approve

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Oct 15, 2018
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: neolit123, timothysc

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 the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Oct 15, 2018
@timothysc timothysc added the kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. label Oct 15, 2018
@k8s-ci-robot k8s-ci-robot merged commit b11211e into kubernetes:master Oct 15, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. area/kubeadm cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/bug Categorizes issue or PR as related to a bug. 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. release-note Denotes a PR that will be considered when it comes time to generate release notes. 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

6 participants