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
pkg/kubectl: check version of kubectl #41
Conversation
/cc @lbb |
If someone tries to execute krew binary standalone with kubectl <1.12, adding a failure. I'm not entirely sure if it's a valid use case. The only encounter of this could be when someone installs krew, and directly tries to invoke the binary (as krew 0.2 won't work on kubectl 1.11 or older). Probably harmless for now (also added a KREW_DISABLE_KUBECTL_VERSION_CHECK escape hatch for dev/build purposes). We can remove this pkg and check soon. Currently adds ~100 ms to each krew cmd. Signed-off-by: Ahmet Alp Balkan <ahmetb@google.com>
1751b5c
to
a1847aa
Compare
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 few nits.
I'm not convinced we have to execute the check every time (maybe only when we install krew).
We should not rely on an exec check, as the actual version might be different.
// detect kubectl version to prevent running krew standalone with older | ||
// versions of kubectl. | ||
// TODO(ahmetb): this may not be necessary after most users are on 1.12 | ||
glog.V(4).Infof("checking kubectl version") |
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.
Capitalize
@@ -19,6 +19,8 @@ import ( | |||
"fmt" | |||
"os" | |||
|
|||
"github.com/GoogleContainerTools/krew/pkg/kubectl" | |||
|
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.
remove space
glog.V(4).Infof("checking kubectl version") | ||
ok, err := kubectl.IsSupportedVersion() | ||
if err != nil { | ||
glog.Fatalf("error checking kubectl version: %+v", 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.
Capitalize
glog.Fatal("You are running on an unsupported version of \"kubectl\"." + | ||
" This version of krew requires minimum kubectl 1.12.0.") | ||
} | ||
glog.V(4).Infof("checked kubectl version") |
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.
Capitalize
|
||
var ( | ||
minKubectl = semver.New("1.12.0-alpha.0") | ||
versionProvider = execKubectlVersion |
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.
defaultVersionProvider
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.
or remove, why it is needed?
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 for mocking easily.
cmd := exec.Command("kubectl", "version", "--client", "--output=json") | ||
b, err := cmd.CombinedOutput() | ||
if err != nil { | ||
return "", fmt.Errorf("failed to execute kubectl version. error=%v, out=%v", err, string(b)) |
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.
put the cascading error at the end of the message
/hold |
If someone tries to execute krew binary standalone with kubectl <1.12, adding
a failure.
I'm not entirely sure if it's a valid use case. The only encounter of this
could be when someone installs krew, and directly tries to invoke the binary
(as krew 0.2 won't work on kubectl 1.11 or older).
Probably harmless for now (also added a KREW_DISABLE_KUBECTL_VERSION_CHECK
escape hatch for dev/build purposes). We can remove this pkg and check soon.
Currently adds ~100 ms to each krew cmd.