-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
Warn if incompatible kubectl version is in use #5596
Conversation
Fixes: kubernetes#3329 Modification is done inside start.go where additional checking on the version returned via the kubectl CLI is checked. Running 'kubectl version --output=json' will return both client and server information.
Can one of the admins verify this patch? |
Hi @nanikjava. 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. |
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: nanikjava The full list of commands accepted by this bot can be found here.
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
Codecov Report
@@ Coverage Diff @@
## master #5596 +/- ##
==========================================
+ Coverage 36.89% 37.15% +0.25%
==========================================
Files 102 103 +1
Lines 7369 7545 +176
==========================================
+ Hits 2719 2803 +84
- Misses 4297 4369 +72
- Partials 353 373 +20
|
cmd/minikube/cmd/start.go
Outdated
out.T(out.Tip, "For best results, install kubectl: https://kubernetes.io/docs/tasks/tools/install-kubectl/") | ||
} | ||
} | ||
|
||
if kcs.KeepContext { |
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.
Move this connection output to the top of showKubectlConnectInfo
.
This will allow both the version mismatch error to come at the end, which is more visible, and will allow you to exit early if kubectl does not exist, which will allow for more readable code as the version checking won't have to be indented.
cmd/minikube/cmd/start.go
Outdated
out.T(out.Tip, "For best results, install kubectl: https://kubernetes.io/docs/tasks/tools/install-kubectl/") | ||
} else { | ||
glog.Infof("Kubectl found at the following location %s. Let's execute and get the result", path) | ||
output, err = exec.Command(path, "version", "--output=json").Output() |
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.
This may show the wrong server version, as it queries the active context kubectl is configured for, which may not be minikube.
My suggestion is to use kubectl version --short --output=json
, and add k8sVersion
as an argument to the function.
cmd/minikube/cmd/start.go
Outdated
if err != nil { | ||
out.T(out.Tip, "For best results, install kubectl: https://kubernetes.io/docs/tasks/tools/install-kubectl/") | ||
} else { | ||
glog.Infof("Kubectl found at the following location %s. Let's execute and get the result", path) |
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.
While good for initial debugging, I think this log message can be removed.
cmd/minikube/cmd/start.go
Outdated
output, err = exec.Command(path, "version", "--output=json").Output() | ||
|
||
// ...once we get something back do some version checking | ||
if err == nil { |
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 mention this later, but try to structure functions so that exceptional conditions are handled first, and exited early. So for istance:
if err != nil {
.. return ..
}
.. do the rest with one level less indentation
cmd/minikube/cmd/start.go
Outdated
clientjsonErr := json.Unmarshal(output, &clientVersion) | ||
|
||
// ....... and {server} json | ||
serverjsonErr := json.Unmarshal(output, &serverVersion) |
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.
No need to unmarshal the same output twice: the server version is already in clientVersion.SVersion
cmd/minikube/cmd/start.go
Outdated
serverjsonErr := json.Unmarshal(output, &serverVersion) | ||
|
||
if (clientjsonErr != nil) || (serverjsonErr != nil) { | ||
glog.Infof("There was an error processing the json output") |
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.
here is another opportunity to return early.
cmd/minikube/cmd/start.go
Outdated
serverMinor, _ := strconv.Atoi(serverVersion.SVersion.Minor) | ||
clientMinor, _ := strconv.Atoi(serverVersion.CVersion.Minor) | ||
|
||
if clientMinor < serverMinor { |
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.
This is not quite correct yet. https://kubernetes.io/docs/setup/release/version-skew-policy/#kubectl dictates that you are allowed up to one version difference. One possibility is:
if math.Abs(float64(clientMinor - serverMinor)) > 1 {
cmd/minikube/cmd/start.go
Outdated
clientMinor, _ := strconv.Atoi(serverVersion.CVersion.Minor) | ||
|
||
if clientMinor < serverMinor { | ||
out.T(out.Tip, "The version of kubectl {{.kubectl}} installed is incompatible with your Kubernetes {{.kubernetes}} deployment. Please upgrade/downgrade as necessary, or use minikube kubectlto connect to your cluster", |
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 would be helpful to include the path. How about something like:
{{.path}} is version {{.version}}, and is incompatible with your specified Kubernetes version. You will need to update {{.path}} or use 'minikube kubectl' to connect with this cluster
* When nil is returned from function just return back * Restructure the output so that it will make more sense for the user
Keywords which can automatically close issues and at(@) mentions are not allowed in commit messages. The list of commits with invalid commit messages:
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. I understand the commands that are listed 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.
Thank you!
Fixes: #3329
Modification is done inside start.go where additional checking on the
version returned via the kubectl CLI is checked.
Running 'kubectl version --output=json' will return both client
and server information.