1

Why do I have to use --verb=list option when I list all resources in the k8s namespace?

I read this question and linked GitHub issue, and they worked for me. However, I cannot understand why --verb=list option is used.

Thanks to the help, I now know what this option does. When I add this option, the command shows only resources which support list verb. However, I could not figure out why it was necessary to show only the resources that support the list verb.

Please teach me this.

yu saito
  • 125
  • 7

1 Answers1

1

The question you quoted was to list resources. To be able to list, the resource must support the listing. Based on official documentation:

kubectl api-resources --verbs=list,get       # All resources that support the "list" and "get" request verbs

In the case of documentation, we have 2 verbs (list, get), you had one (list). The idea is for the command to return only those api-resources which handle list verb.

In conclusion, the --verb=list flag was used to limit the results to only those that support the listing.

I could not figure out why it was necessary to show only the resources that support the list verb.

This solution is good if, for example, later you want to work on api-resources using only the list. If you would like to operate on a resource that does not support it, you will get an error similar to this:

kubectl list tokenreviews
error: unknown command "list" for "kubectl"

Did you mean this?
        get
        wait

To avoid this situation you can filter results before with the flag --verb=list.

Mikołaj Głodziak
  • 4,775
  • 7
  • 28
  • Thank you for your answer, and I have another question. Why is listing resources which support list verb suitable for getting all custom resources? In linked question, he asked how to display all the resources. According to your answer, `--verb=list` shows only listable resources. In my understanding, if any resource is included that does not support list verb, it will not be displayed. In other word, those commands do not show all resources. – yu saito Feb 05 '22 at 08:07
  • 1
    I will agree. If you want to list all `api-resources` no matter how you can handle them later, you shouldn't use `--verb=list`. This is an optional option, not required, that is used to limit the output. – Mikołaj Głodziak Feb 08 '22 at 07:54
  • 1
    Thank you very much! All my questions is resolved. – yu saito Feb 08 '22 at 09:07