Created
November 8, 2018 10:46
-
-
Save vrutkovs/c97f6f531a2e5a3a404393bcffba1eda to your computer and use it in GitHub Desktop.
This file contains 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 | |
set -eux | |
set -o pipefail | |
cd /tmp | |
git clone https://robot:[email protected]/vadim/cluster-state.git | |
cd cluster-state | |
rm -rf ./* | |
# Globals | |
types=("persistentvolumes" "securitycontextconstraints" "clusterroles" "clusterrolebindings") | |
for type in "${types[@]}"; do | |
mkdir -p globals/$type | |
mapfile -t objs < <( oc get $type -o name ) | |
for obj in "${objs[@]}"; do | |
oc export $obj > globals/${obj}.yml | |
done | |
done | |
# namespaced objects | |
while read -d ' ' p; do | |
mkdir $p | |
oc export project $p > project-$p.yml | |
pushd $p | |
oc project $p > /dev/null | |
types=("is" "bc" "dc" "cm" "secret" "cronjob" "route" "svc" "pvc" "role" "rolebinding" "ds" "sa" "sts") | |
for type in "${types[@]}"; do | |
mapfile -t objs < <( oc get $type -o name ) | |
for obj in "${objs[@]:-}"; do | |
[ ! -z $obj ] || continue | |
oc export $obj > ${obj/\//-}.yml | |
done | |
done | |
popd | |
done <<< $(oc projects -q) | |
git config --global user.name "Openshift robot" | |
git config --global user.email [email protected] | |
git add -A | |
git commit -am "Cluster state on $(date)" | |
git push -f |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment