Skip to content

Instantly share code, notes, and snippets.

@fulvi0
Forked from bu3ny/ocp4_all_resources.md
Created March 8, 2022 13:05
Show Gist options
  • Select an option

  • Save fulvi0/2f4fe112e638d0351d3b6dfa9cca3c50 to your computer and use it in GitHub Desktop.

Select an option

Save fulvi0/2f4fe112e638d0351d3b6dfa9cca3c50 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