Skip to content

Instantly share code, notes, and snippets.

@luckylittle
Created March 12, 2021 01:48
Show Gist options
  • Save luckylittle/92c722485fb32f11b775708ddd0440fa to your computer and use it in GitHub Desktop.
Save luckylittle/92c722485fb32f11b775708ddd0440fa to your computer and use it in GitHub Desktop.
How can I list all resources and custom resources in OpenShift 4

How can I list all resources and custom resources in OpenShift

List all CRDs with CR name and Scope

oc get crd -o=custom-columns=NAME:.metadata.name,CR_NAME:.spec.names.singular,SCOPE:.spec.scope

List every single custom resources in the cluster

oc get $(oc get crd -o=custom-columns=CR_NAME:.spec.names.singular --no-headers | awk '{printf "%s%s",sep,$0; sep=","}') --ignore-not-found --all-namespaces -o=custom-columns=KIND:.kind,NAME:.metadata.name,NAMESPACE:.metadata.namespace

List every single resource in the cluster (custom and non-custom)

oc get $(oc api-resources --verbs=list -o name | awk '{printf "%s%s",sep,$0;sep=","}') --ignore-not-found --all-namespaces -o=custom-columns=KIND:.kind,NAME:.metadata.name,NAMESPACE:.metadata.namespace --sort-by='metadata.namespace'

List every single non-namespaced resource in the cluster

oc get $(oc api-resources --namespaced=false --verbs=list -o name | awk '{printf "%s%s",sep,$0;sep=","}') --ignore-not-found --all-namespaces -o=custom-columns=KIND:.kind,NAME:.metadata.name --sort-by='kind'

List every single namespaced resource in a namespace

oc get $(oc api-resources --namespaced=true --verbs=list -o name | awk '{printf "%s%s",sep,$0;sep=","}') --ignore-not-found -n ${NAMESPACE} -o=custom-columns=KIND:.kind,NAME:.metadata.name --sort-by='kind'

Note: oc get all inside namespace does not really show "all" and the above commands will fill those gaps.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment