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 validateStableVersion() #72059
kubeadm: refactor validateStableVersion() #72059
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. |
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.
doesn't validate remote versions in the special case when the client version is empty
the client version should never be empty.
if that's the case then we can consider this a build environment problem.
i'd argue that we pretty much need to os.Exit(1)
if pkgversion.Get().String()
fails to obtain an actual version.
it means that you could be building kubectl, the kubelet and control plane with the same environment and that not a great idea.
we had bug reports where we could not figure out what is happening and eventually found out that the user was building k8s components without the version info that the linker passes from GIT.
make all WHAT=./cmd/kubeadm
should populate the version info for you and you don't need an internet connection for that.
this will will feed a valid client version into kubeadm.
/priority backlog
/assign kad
@kubernetes/sig-cluster-lifecycle-pr-reviews |
/ok-to-test |
@neolit123 can you elaborate a bit more on this? Existing code already checks if version is empty. This PR just moves it to another place where it is more understandable. Am I missing something here? Are you suggesting to add os.Exit(1) call on top of the proposed change? |
@bart0sh @rojkov |
@neolit123 Thanks for review! This PR doesn't solve any problem except clarifying the code. Just wanted to keep the PR as simple and clear as possible. At least now it became more obvious that the empty string check is a weird edge case with missing explanation why it's needed. To illustrate why exactly this check is needed I submitted one more commit removing the check. Here's the result As you can see 7 bazel tests in CI start to fail and I can't say the reason is obvious. I've added one more commit which brings the fallback back and adds a TODO comment and an explicit error check. Then I'd argue that it's a build system problem. By definition a unit test is supposed to test only its corresponding unit. If it depends on other units like build systems it's not unit test any more or it's a manifestation of an architectural issue. As |
@rojkov @bart0sh @neolit123 the string returned by |
@neolit123, @rosti guys, I'd propose to look at this PR as a simple refactoring. First commit is quite obvious. Second commit improves readability. That's it. Let's not go to build system issues just yet, ok? Do you agree that as a simple refactoring PR it does make sense and worth merging? |
Yes, we may have gone a bit stray from the original intent here. Sorry about that. |
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.
As you can see 7 bazel tests in CI start to fail and I can't say the reason is obvious. I've added one more commit which brings the fallback back and adds a TODO comment and an explicit error check.
i forgot about this.
it happens because when doing unit tests on individual packages, there is nothing to populate the version.
cmd/kubeadm/app/util/version.go
Outdated
@@ -95,6 +94,13 @@ func KubernetesReleaseVersion(version string) (string, error) { | |||
klog.Infof("falling back to the local client version: %s", clientVersion) | |||
return KubernetesReleaseVersion(clientVersion) | |||
} | |||
|
|||
if clientVersionErr != nil { | |||
// TODO: theoretically clinetVersion is always accessible, but only if build system is tweaked correctly |
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 move the comment above:
pkgversion.Get().String()
and make it say:
pkgversion.Get().String() should always return a correct version added by the golang linker and the build system. The version can still be missing when doing unit tests on individual packages.
|
||
if clientVersionErr != nil { | ||
// TODO: theoretically clinetVersion is always accessible, but only if build system is tweaked correctly | ||
klog.Warningf("could not obtain client version; using remote version: %s", body) |
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.
at this point kubeadmVersion() can fail because of not being able to parse a remoteVersion too.
this case makes this error message invalid.
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.
Very true! I guess if both versions are unavailable we can do nothing, but os.Exit(1)
with some explanation. I'll squash these 3 commits and submit one more PR.
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.
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.
Yeap, I'll discuss with Ed what would be the best option.
we can agree on that, sure. so if your production binary is lacking a GIT version and this is air gapped scenario, upgrades might be broken too. |
Currently the function `cmd/kubeadm/app/util.validateStableVersion()` doesn't validate remote versions in the special case when the client version is empty. This makes the code more difficult to reason about, because the function may successfully return a string which isn't a valid version. Move handling the special case outside of the function to the place where its meaning is more obvious.
04aaad8
to
b9c2139
Compare
/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.
@rojkov thanks! for this pr!
I'm ok with the proposed changes.
Ping me when all the feedback addressed for lgtm/approval
/approve |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: fabriziopandini, rojkov 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 |
What type of PR is this?
/kind cleanup
What this PR does / why we need it:
Currently the function
cmd/kubeadm/app/util.validateStableVersion()
doesn't validate remote versions in the special case when the client version is empty. This makes the code more difficult to reason about, because the function may successfully return a string which isn't a valid version. And this conflicts with name of the function.Move handling the special case outside of the function to the place where its meaning is more obvious.
Does this PR introduce a user-facing change?: