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

kubectl: support GKE internal IP endpoint (#810) #822

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions kubectl/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ If your GKE cluster is in a different project than the build itself, also set:

```CLOUDSDK_CORE_PROJECT=<the GKE cluster project>```

To use the internal IP address of the cluster endpoint, set:

```CLOUDSDK_INTERNAL_IP=true```

## Using this builder with Google Kubernetes Engine

To use this builder on Google Cloud Build, your [builder service
Expand Down
11 changes: 7 additions & 4 deletions kubectl/kubectl.bash
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ function var_usage() {
CLOUDSDK_CONTAINER_CLUSTER=<cluster name>

Optionally, you can specify the kubectl version via KUBECTL_VERSION, taking one of the following values: ${versions[@]}
Setting CLOUDSDK_INTERNAL_IP=true will use the internal IP address of the cluster endpoint.
EOF

exit 1
Expand All @@ -39,20 +40,22 @@ cluster=${CLOUDSDK_CONTAINER_CLUSTER:-$(gcloud config get-value container/cluste
region=${CLOUDSDK_COMPUTE_REGION:-$(gcloud config get-value compute/region 2> /dev/null)}
zone=${CLOUDSDK_COMPUTE_ZONE:-$(gcloud config get-value compute/zone 2> /dev/null)}
project=${CLOUDSDK_CORE_PROJECT:-$(gcloud config get-value core/project 2> /dev/null)}
extra_args=()

[[ -z "$cluster" ]] && var_usage
[ ! "$zone" -o "$region" ] && var_usage
if [[ -n "$KUBECTL_VERSION" ]] && [[ ! " ${versions[*]} " =~ " ${KUBECTL_VERSION} " ]]; then
echoerr "Bad KUBECTL_VERSION \"${KUBECTL_VERSION}\". Expected one of ${versions[*]}" >&2
exit 1
fi
[[ "${CLOUDSDK_INTERNAL_IP}" == "true" ]] && extra_args+=(--internal-ip)

if [ -n "$region" ]; then
echoerr "Running: gcloud container clusters get-credentials --project=\"$project\" --region=\"$region\" \"$cluster\""
gcloud container clusters get-credentials --project="$project" --region="$region" "$cluster" || exit
echoerr "Running: gcloud container clusters get-credentials --project=\"$project\" --region=\"$region\" ${extra_args[@]} \"$cluster\""
gcloud container clusters get-credentials --project="$project" --region="$region" "${extra_args[@]}" "$cluster" || exit
else
echoerr "Running: gcloud container clusters get-credentials --project=\"$project\" --zone=\"$zone\" \"$cluster\""
gcloud container clusters get-credentials --project="$project" --zone="$zone" "$cluster" || exit
echoerr "Running: gcloud container clusters get-credentials --project=\"$project\" --zone=\"$zone\" ${extra_args[@]} \"$cluster\""
gcloud container clusters get-credentials --project="$project" --zone="$zone" "${extra_args[@]}" "$cluster" || exit
fi

echoerr "Running: ${kubectl_cmd}" "$@" >&2
Expand Down