Skip to content

Commit

Permalink
updated .envrc
Browse files Browse the repository at this point in the history
  • Loading branch information
HariSekhon committed Feb 9, 2024
1 parent 431818b commit b018edb
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions .envrc
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,20 @@ kube_context(){
export KUBECONFIG="$tmpdir/config.${EUID:-${UID:-$(id -u)}}.$$.$epoch"

# load your real kube config to isolated staging area to source the context info
local src_kubeconfig
if [ -f "$original_kubeconfig" ]; then
cp -- "$original_kubeconfig" "$KUBECONFIG"
src_kubeconfig="$original_kubeconfig"
elif [ -f "$default_kubeconfig" ]; then
cp -- "$default_kubeconfig" "$KUBECONFIG"
src_kubeconfig="$default_kubeconfig"
elif [ -f "$PWD/.kube/config" ]; then
cp -- "$PWD/.kube/config" "$KUBECONFIG"
src_kubeconfig="$PWD/.kube/config"
elif [ -f "/etc/rancher/k3s/k3s.yaml" ]; then
cp -- "/etc/rancher/k3s/k3s.yaml" "$KUBECONFIG"
src_kubeconfig="/etc/rancher/k3s/k3s.yaml"
fi
if [ -n "$src_kubeconfig" ]; then
if [ "$src_kubeconfig" != "$KUBECONFIG" ]; then
cp -f -- "$src_kubeconfig" "$KUBECONFIG"
fi
else
echo "WARNING: failed to find one of:
Expand All @@ -99,7 +105,8 @@ kube_context(){

# race condition - kubectl config get-contexts fails to find the context and switch in many runs without this sleep
context_found=0
for ((i=0;i<10;i++)); do
local i
for ((i=0; i < 10; i++)); do
# surprisingly unreliable - if kubectl config get-contexts -o name | grep -Fxq "$context" can miss even after these succeed
#if [ -s "$KUBECONFIG" ]; then
#if cmp --quiet "$from_kubeconfig" "$KUBECONFIG"; then
Expand All @@ -124,6 +131,11 @@ kube_context(){

gke_kube_context(){
local CONTEXT
for _ in CLOUDSDK_CORE_PROJECT CLOUDSDK_COMPUTE_REGION CLOUDSDK_CONTAINER_CLUSTER; do
if [ -z "${!_}" ]; then
echo "WARNING: \$$_ is not set" >&2
fi
done
# if CLOUDSDK_CONTAINER_CLUSTER and it's generated as a naming convention such as "${CLOUDSDK_CORE_PROJECT}-${CLOUDSDK_COMPUTE_REGION}"
#export CLOUDSDK_CONTAINER_CLUSTER="${CLOUDSDK_CONTAINER_CLUSTER:-${CLOUDSDK_CORE_PROJECT}-${CLOUDSDK_COMPUTE_REGION}}"

Expand Down

0 comments on commit b018edb

Please sign in to comment.