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

pkg/kubectl: check version of kubectl #41

Closed
wants to merge 1 commit into from

Conversation

ahmetb
Copy link
Member

@ahmetb ahmetb commented Sep 17, 2018

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.

@ahmetb
Copy link
Member Author

ahmetb commented Sep 17, 2018

/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>
Copy link
Contributor

@lbb lbb left a 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")
Copy link
Contributor

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"

Copy link
Contributor

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)
Copy link
Contributor

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")
Copy link
Contributor

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
Copy link
Contributor

Choose a reason for hiding this comment

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

defaultVersionProvider

Copy link
Contributor

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?

Copy link
Member Author

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))
Copy link
Contributor

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

@ahmetb
Copy link
Member Author

ahmetb commented Sep 21, 2018

/hold
I'm kinda convinced we don't need this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants