26 lines
840 B
Plaintext
26 lines
840 B
Plaintext
aws-eksc() {
|
|
local clusters cluster_name
|
|
|
|
# Fetch clusters into a zsh array; exit if the command fails.
|
|
clusters=(${(f)"$(aws eks list-clusters 2>/dev/null | jq -r '.clusters[]')"})
|
|
|
|
if (( ${#clusters[@]} == 0 )); then
|
|
echo "No EKS clusters found in the current region/profile." >&2
|
|
return 1
|
|
elif (( ${#clusters[@]} == 1 )); then
|
|
cluster_name="${clusters[1]}"
|
|
echo "Auto-selecting only cluster: ${cluster_name}"
|
|
else
|
|
# Prompt for selection if more than one cluster exists.
|
|
cluster_name=$(printf '%s\n' "${clusters[@]}" | fzf --prompt="Select EKS Cluster > ")
|
|
fi
|
|
|
|
# Proceed if a cluster name was selected (handles fzf cancellation).
|
|
if [[ -n "$cluster_name" ]]; then
|
|
aws eks update-kubeconfig --name "$cluster_name" 2>&1 >/dev/null
|
|
else
|
|
echo "No cluster selected." >&2
|
|
return 1
|
|
fi
|
|
}
|