#!/usr/bin/env bash
set -euo pipefail

unset KUBECONFIG
project=${PROJECT:-pingcap-gardener}

gcpRegions=( us-west1 us-west2 asia-northeast1)

function gcpKubeConfig(){
    gcloud container clusters list --region $1 | awk 'NR == 1 {next} {print $1}' | xargs -n 1 -I {} gcloud container clusters get-credentials {} --region $1 --project $project
}

# update kubeconfig for GCP GKE cluster
for region in "${gcpRegions[@]}"
do
  gcpKubeConfig $region
done

kubectl config get-contexts
