Skip to content

Instantly share code, notes, and snippets.

@jakefhyde
Last active November 7, 2023 05:49
Show Gist options
  • Select an option

  • Save jakefhyde/c28be70da4b2a5cf153a2fdd269f8732 to your computer and use it in GitHub Desktop.

Select an option

Save jakefhyde/c28be70da4b2a5cf153a2fdd269f8732 to your computer and use it in GitHub Desktop.
get-cluster-yaml.sh
#!/bin/bash
set -ex
KUBECTL_CMD=kubectl
build() {
echo "Building cluster.yml..."
IFS=''
while read line
do
word=$(echo "$line" |awk -F ":" '{print $1}')
new_word=$(echo "$line" |awk -F ":" '{print $1}' | perl -pe 's/([a-z0-9])([A-Z])/$1_\L$2/g')
echo "$line"| sed "s/${word//\//\\/}/${new_word//\//\\/}/g" >>cluster.yml
done< <(${KUBECTL_CMD} -n kube-system get configmap full-cluster-state -o json | jq -r .data.\"full-cluster-state\" | jq -r .desiredState.rkeConfig | yq -P -)
echo "Building cluster.rkestate..."
${KUBECTL_CMD} -n kube-system get configmap full-cluster-state -o json | jq -r .data.\"full-cluster-state\" | jq -r . > cluster.rkestate
}
build
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment