Skip to content

Instantly share code, notes, and snippets.

@e-minguez
Created May 4, 2020 13:03
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save e-minguez/0c47d1b537c14017ff851609dc409d3c to your computer and use it in GitHub Desktop.
Save e-minguez/0c47d1b537c14017ff851609dc409d3c to your computer and use it in GitHub Desktop.
Get all k8s objects, both namespaced or not
#!/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