Created
May 4, 2020 13:03
-
-
Save e-minguez/0c47d1b537c14017ff851609dc409d3c to your computer and use it in GitHub Desktop.
Get all k8s objects, both namespaced or not
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
#!/usr/bin/env bash | |
# https://stackoverflow.com/a/55796558/491522 | |
getall() { | |
for i in $(oc api-resources --verbs=list --namespaced -o name | grep -v "events.events.k8s.io" | grep -v "events" | sort | uniq); do | |
echo "Resource:" $i | |
oc -n ${1} get --ignore-not-found=true ${i} -o yaml > ${1}/${i}.yaml | |
done | |
} | |
clusterwide() { | |
for object in $(oc api-resources --verbs=list --namespaced=false -o name | sort | uniq);do | |
echo "Resource:" ${object} | |
oc get --ignore-not-found=true ${object} -o yaml > clusterwide/${object}.yaml | |
done | |
} | |
for project in $(oc get project -o name | awk -F/ '{ print $2 }'); do | |
mkdir -p ./${project} | |
echo "Project: ${project}" | |
getall ${project} | |
done | |
mkdir -p ./clusterwide | |
echo "Clusterwide objects" | |
clusterwide |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment