Skip to content

Instantly share code, notes, and snippets.

@mesuutt
Last active November 4, 2022 11:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mesuutt/3a18f848479a613b01952dfe23f61837 to your computer and use it in GitHub Desktop.
Save mesuutt/3a18f848479a613b01952dfe23f61837 to your computer and use it in GitHub Desktop.
Rename kubeconfig files with cluster's name.
#!/bin/bash
# exit on error
set -e
CONF_DIR=~/.kube/config.d
require() {
if ! hash "$1" &>/dev/null; then
echo "'$1' not found in PATH"
exit 1
fi
}
require yq
for f in $CONF_DIR/*.{yml,conf}; 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