Skip to content

Commit

Permalink
added new generic context setup function
Browse files Browse the repository at this point in the history
  • Loading branch information
fragolinux committed Nov 5, 2021
1 parent 3c0d972 commit c2ffc63
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions lib/kube-config.sh
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,30 @@ has_context() {
kubectx | grep -q "$context_name"
}

prepare_and_check_k8s_context_generic() {
local context_name="${1:-"${RESOURCE_GROUP}-cluster"}"
local cluster_description

log "Searching for accessibility of k8s context $(b "${context_name}")"
if has_context "${context_name}"; then
log "k8s context $(b "${context_name}") is accessible, switching to it"
kubectx "${context_name}" >/dev/null 2>&1
else
whine "k8s context $(b "${context_name}") is not accessible, check your env"
fi
cluster_description="context: $(b "$(kubectx -c)")"
log "Switched to k8s ${cluster_description}"

log "Checking Kubernetes accessibility - ${cluster_description}"
if kubectl version >/dev/null 2>&1 ; then
log "Found valid Kubernetes accessibility - ${cluster_description}"
log "Server version: $(b "$(get_kube_server_version)")"
else
whine "Couldn't access Kubernetes right now, please fix it"
fi
}

# deprecated
prepare_and_check_k8s_context() {
local context_prefix="$1"
local cluster_description
Expand Down

0 comments on commit c2ffc63

Please sign in to comment.