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

GKE: Adjust the PATH to the right kubectl for gcloud #3092

Merged
merged 1 commit into from
Dec 22, 2014

Conversation

zmerlynn
Copy link
Member

Force kubectl to the git repo version if we detect a built version,
otherwise a system version. Previously, your actual PATH influenced
what kubectl was getting picked up, which violates POLA for a dev
environment.

Along the way: Add the root install of kubectl.

@zmerlynn zmerlynn assigned zmerlynn and mbforbes and unassigned zmerlynn Dec 22, 2014
@@ -64,6 +68,7 @@ locations=(
"${KUBE_ROOT}/_output/local/bin/${host_os}/${host_arch}/kubectl"
"${KUBE_ROOT}/platforms/${host_os}/${host_arch}/kubectl"
"${HOME}/google-cloud-sdk/bin/kubectl"
"/usr/local/share/google/google-cloud-sdk/bin/kubectl"
Copy link
Contributor

Choose a reason for hiding this comment

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

If we want to force gcloud to pick up the built version, we should remove this line (and the line above) so that the tests will fail on gke if we can't built kubectl. Otherwise we have a weird situation where sometimes we are using the kubectl built from source and other times we are using the kubectl packaged with gcloud.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, I actually debated that. We can either force the git version, or allow the gcloud version. As written, this would actually let you do a "make clean" and use the gcloud version for e2e's, though, and there's no easy way to do that otherwise.

Copy link
Contributor

Choose a reason for hiding this comment

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

Well, right now if you do a make clean the tests will fail because there won't be a kubecfg to execute, but hopefully that will be fixed soon.

Since users can choose their own google-cloud-sdk install directory, it seems fragile to start encoding common ones here. How about replacing these two lines with $(which kubectl) which will pick it up from the gcloud install directory?

Copy link
Member Author

Choose a reason for hiding this comment

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

Actually, better yet, since we're allowing GCLOUD=foo/bar/gcloud, why not KUBECTL=foo/bar/kubectl? Seems like that would allow you to test from a system install, but it forces you to be conscious about it.

Copy link
Contributor

Choose a reason for hiding this comment

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

That will work for any installed gcloud, but won't work for a gcloud built from head, because kubectl isn't in the same directory until the tool in packaged.

@zmerlynn
Copy link
Member Author

@roberthbailey: PTAL, reassigned since you took a look already. :) This implements my last suggestion.

@mbforbes
Copy link
Contributor

I'm looking too :-)

@mbforbes
Copy link
Contributor

By "POLA" do you mean "principle of least authority" or "principle of least astonishment"?

@zmerlynn
Copy link
Member Author

I meant least astominshment. I surprised me that I needed to hit the PATH on the Jenkins box to actually influence the kubectl it was picking up. :)

@@ -22,6 +22,10 @@ KUBE_ROOT=$(dirname "${BASH_SOURCE}")/..
source "${KUBE_ROOT}/cluster/kube-env.sh"
source "${KUBE_ROOT}/cluster/${KUBERNETES_PROVIDER}/util.sh"

get_absolute_dirname() {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: function comment?

@mbforbes
Copy link
Contributor

Thanks for taking a stab at this, Zach. I had implemented the original solution before I was piping kubectl calls through gcloud, so the current state is leftover crud. Once we address the possible PATH inflation this looks good to me.

…rride

Force kubectl to the git repo version if we detect a built version.
Add a KUBECTL_PATH override so that system/home directory versions of
kubectl can be used if desired. Remove existing $HOME inference.
@zmerlynn
Copy link
Member Author

@mbforbes @roberthbailey: PTAL. It turns out that KUBECTL is also a bad name and broke kube-up (and would've broken other providers, so I changed it to KUBECTL_PATH. Which is a little inconsistent with GCLOUD, but we can handle that cleanup later.

@mbforbes
Copy link
Contributor

Another option is to match config-common.sh and call it KUBECTL_DIR and have it not contain the actual binary name... but that would be overly fussy and probably actually look worse. Looking through now...

} >&2
exit 1
fi
elif [[ ! -x "${KUBECTL_PATH}" ]]; then
Copy link
Contributor

Choose a reason for hiding this comment

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

This is probably overkill, but it would be a bit more resilient to actually run kubectl (similarly to how you run gcloud preview in pr #3082) rather than just check the executable bit.

Copy link
Member Author

Choose a reason for hiding this comment

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

I think that's a verify_prereqs thing to do, not an every-time-you-run kubectl.sh thing to do. :) I did consider it, though.

Copy link
Contributor

Choose a reason for hiding this comment

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

Good point.

@roberthbailey
Copy link
Contributor

LGTM. Kicking travis.

@roberthbailey roberthbailey added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Dec 22, 2014
@mbforbes
Copy link
Contributor

LGTM

roberthbailey added a commit that referenced this pull request Dec 22, 2014
GKE: Adjust the PATH to the right kubectl for gcloud
@roberthbailey roberthbailey merged commit 9b6aec5 into kubernetes:master Dec 22, 2014
@lavalamp
Copy link
Member

I haven't read this PR so forgive this possibly silly question: is it now possible to run e2e against GKE in all of (old client, new cluster), (new client, old cluster), and (new client, new cluster) configurations?

@mbforbes
Copy link
Contributor

I think we've only tested the (new client, old cluster) config. The others should at least run (simply because we always pass --check_version_skew=false given we're testing the config I mentioned), but as far as I know we haven't tried it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lgtm "Looks good to me", indicates that a PR is ready to be merged.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants