either by your hand or in other concurrently executing scripts changes your global kubectl context to run on the given cluster, which could divert your command or concurrently long running scripts in other windows to run kubectl commands on the wrong cluster, leading to cross environment misconfigurations and real world outages (I've seen this personally)
if GKE_CONTEXT is not setthen requires the following to be set in the environment in order to obtain the credentials to the GKE cluster:
GKE_CLUSTER - the name of your GKE cluster
CLOUDSDK_CORE_PROJECT - the project in which your GKE cluster resides (will try to auto-infer from gcloud config if not set)
CLOUDSDK_COMPUTE_REGION - the region in which to find your GKE cluster (will try to auto-infer from gcloud config if not set)
If the CLOUDSDK variables are not set and cannot be inferred from gcloud config, then errors out. If they are set though, they may be pointing to the wrong project or region so it is recommended to set them
For frequent more convenient usage you will want to shorten the CLI by copying this script to a local copy in each cluster's yaml config directory and hardcoding the GKE_CONTEXT (use gke_kube_creds.sh to pre-populate the context and credentials) or CLOUDSDK_CORE_PROJECT, CLOUDSDK_COMPUTE_REGION and GKE_CLUSTER variables if pulling GKE creds.
Could also use main kube config with kubectl switches --cluster / --context (after configuring, see gke_kube_creds.sh), but this is more convenient, especially when hardcoded for the local copy in each cluster's k8s yaml dir
CLOUDSDK_CORE_PROJECT="${CLOUDSDK_CORE_PROJECT:-$(gcloud config list --format="get(core.project)")}"
CLOUDSDK_COMPUTE_REGION="${CLOUDSDK_COMPUTE_REGION:-$(gcloud config list --format="get(compute.region)")}"
check_env_defined CLOUDSDK_CORE_PROJECT
check_env_defined CLOUDSDK_COMPUTE_REGION
# if set and available in original kube config, will just copy config and switch to this context (faster and less noisy than re-pulling creds from GKE)
# if original kube config contains the context, copy and reuse it (faster and less noisy than re-pulling the creds from GKE), especially when called in script iterations
# switch context if not already the current context (avoids repeating "switching context" output noise when this script it called iteratively in loop by other scripts)