Goglides Dev 🌱

Goglides Dev 🌱 is a community of amazing users

We are working on this space so that IT professionals can grow together.

Create account Log in
Balkrishna Pandey
Balkrishna Pandey

Posted on

Tips and tricks- Openshift API Resources

oc api-resources is a convenient command which prints the supported API resources on the server. I usually use this command if I have to identify the scope of the API, whether it is namespaced or not. You can use this command, in combination with --namespaced=true or --namespaced=false. By default, this command will return all resources, but If you set it to true all namespace resources will be returned and vice versa.

For example, you can run the following command, which returns the API resources deployed in this cluster.

oc api-resources --namespaced=false --no-headers | wc -l
Enter fullscreen mode Exit fullscreen mode
116
Enter fullscreen mode Exit fullscreen mode
oc api-resources --namespaced=true --no-headers | wc -l
Enter fullscreen mode Exit fullscreen mode
192
Enter fullscreen mode Exit fullscreen mode
oc api-resources --no-headers | wc -l
Enter fullscreen mode Exit fullscreen mode
308
Enter fullscreen mode Exit fullscreen mode

Filter-based n API group

  • Return all core API groups as follows,
oc api-resources --api-group=''
Enter fullscreen mode Exit fullscreen mode

Output:

NAME           SHORTNAMES  APIVERSION  NAMESPACED  KIND
bindings               v1      true     Binding
componentstatuses    cs      v1      false    ComponentStatus
configmaps        cm      v1      true     ConfigMap
endpoints        ep      v1      true     Endpoints
events          ev      v1      true     Event
limitranges       limits    v1      true     LimitRange
namespaces        ns      v1      false    Namespace
nodes          no      v1      false    Node
persistentvolumeclaims  pvc     v1      true     PersistentVolumeClaim
persistentvolumes    pv      v1      false    PersistentVolume
pods           po      v1      true     Pod
podtemplates             v1      true     PodTemplate
replicationcontrollers  rc      v1      true     ReplicationController
resourcequotas      quota    v1      true     ResourceQuota
secrets                v1      true     Secret
serviceaccounts     sa      v1      true     ServiceAccount
services         svc     v1      true     Service
Enter fullscreen mode Exit fullscreen mode
  • Return all core-api groups which scope is global
oc api-resources --api-group='' --namespaced=false
Enter fullscreen mode Exit fullscreen mode

Output:

NAME        SHORTNAMES  APIVERSION  NAMESPACED  KIND
componentstatuses  cs      v1      false    ComponentStatus
namespaces     ns      v1      false    Namespace
nodes        no      v1      false    Node
persistentvolumes  pv      v1      false    PersistentVolume
Enter fullscreen mode Exit fullscreen mode
  • use -o to specify the output format. It currently supports only wide and name arguments.
oc api-resources --api-group policy -o wide
Enter fullscreen mode Exit fullscreen mode

Output

NAME          SHORTNAMES  APIVERSION    NAMESPACED  KIND         VERBS
poddisruptionbudgets  pdb     policy/v1    true     PodDisruptionBudget  [create delete deletecollection get list patch update watch]
podsecuritypolicies  psp     policy/v1beta1  false    PodSecurityPolicy   [create delete deletecollection get list patch update watch]
Enter fullscreen mode Exit fullscreen mode
  • You can sort the output by name or kind
oc api-resources --api-group "" -o name  --namespaced=false --sort-by=name
Enter fullscreen mode Exit fullscreen mode

Output:

componentstatuses
namespaces
nodes
persistentvolumes
Enter fullscreen mode Exit fullscreen mode

Discussion (0)