Last active
November 4, 2022 11:18
-
-
Save mesuutt/3a18f848479a613b01952dfe23f61837 to your computer and use it in GitHub Desktop.
Rename kubeconfig files with cluster's name.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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