Skip to content

Instantly share code, notes, and snippets.

@mesuutt
Last active June 2, 2022 11:41
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mesuutt/b3a293decb85416cd770fbea27a6fc17 to your computer and use it in GitHub Desktop.
Save mesuutt/b3a293decb85416cd770fbea27a6fc17 to your computer and use it in GitHub Desktop.
rename kubeconfig files with cluster name
#!/bin/bash
# alias kctx="source ~/.bin/kctx.sh"
CONF_DIR=~/.kube/config.d
file=$(ls -1 $CONF_DIR | fzf)
echo "$file"
if [[ ! "$file" == "null" ]]; then
export KUBECONFIG="$CONF_DIR/$file"
fi
#!/bin/bash
CONF_DIR=~/.kube/config.d
for f in $CONF_DIR/*.yml; do
name=$(cat $f | yq -r '.clusters[0].name')
if [[ ! "$name" == "null" ]]; then
echo "$f === $name"
mv $f "$CONF_DIR/$name.yml"
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment