Skip to content

Instantly share code, notes, and snippets.

@vrutkovs
Created November 8, 2018 10:46
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vrutkovs/c97f6f531a2e5a3a404393bcffba1eda to your computer and use it in GitHub Desktop.
Save vrutkovs/c97f6f531a2e5a3a404393bcffba1eda to your computer and use it in GitHub Desktop.
#!/bin/bash
set -eux
set -o pipefail
cd /tmp
git clone https://robot:foo@gitea.vrutkovs.eu/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 roignac+test@gmail.com
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