dotfiles/.bin/kube-merge

24 lines
527 B
Plaintext
Raw Permalink Normal View History

2023-01-05 21:12:56 +00:00
#!/bin/sh
# Create backup of previous kubeconfig
cp ~/.kube/config ~/.kube/config.bak
KUBECONFIG=""
for config in ~/.kube/config-*
do
profile=$(echo $config | cut -d '-' -f 2)
# De-duplicate profile names
sed 's/default/'$profile'/g' $config > $config.tmp
KUBECONFIG="$KUBECONFIG:$config.tmp"
done
KUBECONFIG=$(echo $KUBECONFIG | cut -c2-)
# Flatten configuration and write it to file
KUBECONFIG=$KUBECONFIG kubectl config view --flatten > ~/.kube/config
# Remove building blocks
rm ~/.kube/config-*.tmp