Last active
March 15, 2018 15:58
-
-
Save takac/d24198bc7fe32d9da67415c9a69c54d1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -eu | |
if [[ ! -z "${DEBUG:-}" ]]; then | |
set -x | |
fi | |
function project_kube_check() { | |
PROJECT=${1:-$(gcloud config get-value project -q)} | |
ZONES=$(gcloud --project=$PROJECT --format='value[](zone)' container clusters list | uniq) | |
if [[ -n "${ZONES}" ]]; then | |
echo "- project: $PROJECT" | |
fi | |
for ZONE in $ZONES; do | |
CLUSTERS=$(gcloud --project=$PROJECT --format='value[](name)' container clusters --zone="$ZONE" list) | |
ZONE_CONFIG=$(gcloud --project=$PROJECT --format=json container get-server-config --zone "$ZONE" 2> /dev/null) | |
ZONE_VERSION=$(jq -r .validMasterVersions[0] <<< $ZONE_CONFIG) | |
if [[ -n "${CLUSTERS}" ]]; then | |
echo " zones:" | |
echo " - name: $ZONE" | |
echo " zone-latest-version: $ZONE_VERSION" | |
echo " clusters:" | |
fi | |
for CLUSTER in $CLUSTERS; do | |
echo " - name: $CLUSTER" | |
CLUSTER_CONFIG=$(gcloud --project=$PROJECT --format=json container clusters describe --zone $ZONE "$CLUSTER") | |
MASTER_VERSION=$(jq -r .currentMasterVersion <<< $CLUSTER_CONFIG) | |
NODE_VERSION=$(jq -r .currentNodeVersion <<< $CLUSTER_CONFIG) | |
echo " master-version: $MASTER_VERSION" | |
MASTER_BEHIND=$(jq -r '.validMasterVersions[]' <(cat <<< $ZONE_CONFIG) | awk '/'$MASTER_VERSION'/{print NR-1}') | |
if [[ "${MASTER_BEHIND}" == "0" ]]; then | |
echo " master-version-support: latest" | |
else | |
if [[ "$MASTER_BEHIND" == 1 || ${MASTER_BEHIND} == 2 ]]; then | |
echo " master-version-support: $MASTER_BEHIND versions behind" | |
else | |
echo " master-version-support: unsupported" | |
fi | |
SAFE_MASTER_VERSION=$(jq -r '.validMasterVersions[0]' <<< $ZONE_CONFIG) | |
echo " upgade-masters-command: >" | |
echo " gcloud --project=$PROJECT container clusters upgrade $CLUSTER --master --cluster-version=${SAFE_MASTER_VERSION} --zone=$ZONE" | |
fi | |
echo " node-version: $NODE_VERSION" | |
NODE_BEHIND=$(jq -r '.validNodeVersions[]' <(cat <<< $ZONE_CONFIG) | awk '/'$NODE_VERSION'/{print NR-1}') | |
if [[ "${NODE_BEHIND}" == "0" ]]; then | |
echo " node-version-support: latest" | |
else | |
if [[ "$NODE_BEHIND" == 1 || ${NODE_BEHIND} == 2 ]]; then | |
echo " node-version-support: $NODE_BEHIND versions behind" | |
else | |
echo " node-version-support: unsupported" | |
fi | |
SAFE_NODE_VERSION=$(jq -r '.validNodeVersions[0]' <<< $ZONE_CONFIG) | |
echo " upgade-nodes-command: >" | |
echo " gcloud --project=$PROJECT container clusters upgrade $CLUSTER --cluster-version=${SAFE_NODE_VERSION} --zone=$ZONE" | |
fi | |
done | |
done | |
} | |
# CLUSTERS=$(gcloud --format='value[](zone)' container clusters list) | |
if [[ -n "${ALL_PROJECTS:-}" ]]; then | |
for PROJECT in $(gcloud projects list --format=json | jq -r '.[].projectId'); do | |
project_kube_check $PROJECT | |
done | |
else | |
project_kube_check | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://cloud.google.com/kubernetes-engine/docs/tutorials/authenticating-to-cloud-platform
Using google/cloud-sdk image to automate update