Skip to content

Instantly share code, notes, and snippets.

@nickjordan
Forked from e-minguez/get-all.sh
Last active September 19, 2020 00:06
Show Gist options
  • Save nickjordan/209117fdf5d5954e8745f565910156d7 to your computer and use it in GitHub Desktop.
Save nickjordan/209117fdf5d5954e8745f565910156d7 to your computer and use it in GitHub Desktop.
Get all k8s objects, both namespaced or not
#!/usr/bin/env bash
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