Commit Graph

3 Commits

Author SHA1 Message Date
Jan Chaloupka ba75977126 kubectl explain: detect resource group in case there are two or more groups discovered
Assume the following CRDs exist (ordered by priority, the first is the highest):
- authentications.migration.k8s.io (K=Authentications, G=migration.k8s.io)
- authentications.metal3.io (K=Authentications, G=metal3.io)
- authentications.whereabouts.cni.cncf.io (K=Authentications, G=whereabouts.cni.cncf.io)
- authentications.snapshot.storage.k8s.io (K=Authentications, G=snapshot.storage.k8s.io)

In case 'kubectl explain authentications' is ran, the highest priority definition (in this case authentications.migration.k8s.io)
is returned. In case a user wants to explain authentication CRD of a different group, --api-version flag has to be set alongside
to point to a specific group and version. E.g. --api-version=metal3.io/v1

This PR allows to dismiss --api-version flag and perform a prefix check to select a resource (e.g. CRD) whose (resource, group) pair
fully prefixes requested resource. E.g. running 'kubectl explain authentications.metal3.io' will return
description of authentications.metal3.io. The same holds for optional field path.
I.e. 'kubectl explain authentications.metal3.io.spec' will return description of spec field
of authentications.metal3.io.spec. In case no resource match is found, the search falls back
to selecting the highest priority gvr that matches the resource.
In case --api-version is set, no prefix matching is performed. To cover cases
such as 'kubectl explain authentications.metal3.io --api-version=authentications.metal3.io/v1' where
fields path coincide with the resource fully specified name (to access .metal3.io field of authentications.metal3.io).

Kubernetes-commit: 30674db1595e3a24273ceb71cbfe67bb300ad951
2021-01-14 09:08:20 +01:00
knight42 b9bc004f47 fix(kubectl): explain crds with the same resource name with builtin objects
Kubernetes-commit: 397f107a0886999e0d45955dfe460112edd9ac5e
2020-03-26 16:07:06 +08:00
Sean Sullivan 171822aafc Move pkg/kubect/explain to staging
Kubernetes-commit: 1252ab3c983d8e4f1de18ffbf57b799e5882a8d1
2019-07-29 14:57:41 -07:00