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
Member

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 requested a review from timothysc Oct 11, 2018

@neolit123 neolit123 changed the title from kubeadm: make SetKubernetesVersion explicit to kubeadm: modify SetKubernetesVersion Oct 11, 2018

@neolit123

This comment has been minimized.

Member

neolit123 commented Oct 11, 2018

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

@neolit123

This comment has been minimized.

Member

neolit123 commented Oct 11, 2018

/retest

@xiangpengzhao

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

@xiangpengzhao

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 {

This comment has been minimized.

@xiangpengzhao

xiangpengzhao Oct 11, 2018

Member

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?

This comment has been minimized.

@bart0sh

bart0sh Oct 11, 2018

Contributor

/lgtm

This comment has been minimized.

@neolit123

neolit123 Oct 11, 2018

Member

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

This comment has been minimized.

@timothysc

timothysc Oct 11, 2018

Member

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

This comment has been minimized.

@neolit123

neolit123 Oct 11, 2018

Member

sounds good.
will update the PR tomorrow.

This comment has been minimized.

@xiangpengzhao
@timothysc

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 {

This comment has been minimized.

@timothysc

timothysc Oct 11, 2018

Member

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 and removed lgtm size/XS labels Oct 12, 2018

@neolit123

This comment has been minimized.

Member

neolit123 commented Oct 12, 2018

updated:

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

Good refactoring 👍 Just one concern, otherwise LGTM.

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

This comment has been minimized.

@xiangpengzhao

xiangpengzhao Oct 13, 2018

Member

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

This comment has been minimized.

@neolit123

neolit123 Oct 13, 2018

Member

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

This comment has been minimized.

@neolit123

neolit123 Oct 13, 2018

Member

updated. :)

kubeadm: modify SetKubernetesVersion
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

This comment has been minimized.

Member

neolit123 commented Oct 13, 2018

/retest

@timothysc

Thanks for the cleanup @neolit123

/lgtm
/approve

@k8s-ci-robot

This comment has been minimized.

Contributor

k8s-ci-robot commented Oct 15, 2018

[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 merged commit b11211e into kubernetes:master Oct 15, 2018

18 checks passed

cla/linuxfoundation neolit123 authorized
Details
pull-kubernetes-bazel-build Job succeeded.
Details
pull-kubernetes-bazel-test Job succeeded.
Details
pull-kubernetes-cross Skipped
pull-kubernetes-e2e-gce Job succeeded.
Details
pull-kubernetes-e2e-gce-100-performance Job succeeded.
Details
pull-kubernetes-e2e-gce-device-plugin-gpu Job succeeded.
Details
pull-kubernetes-e2e-gke Skipped
pull-kubernetes-e2e-kops-aws Job succeeded.
Details
pull-kubernetes-e2e-kubeadm-gce Skipped
pull-kubernetes-integration Job succeeded.
Details
pull-kubernetes-kubemark-e2e-gce-big Job succeeded.
Details
pull-kubernetes-local-e2e Skipped
pull-kubernetes-local-e2e-containerized Skipped
pull-kubernetes-node-e2e Job succeeded.
Details
pull-kubernetes-typecheck Job succeeded.
Details
pull-kubernetes-verify Job succeeded.
Details
tide In merge pool.
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment