Skip to content

Commit a055fba

Browse files
authored
Merge pull request #7299 from liggitt/shortnames
Document short-names and categories
2 parents c95cf93 + f88bbba commit a055fba

File tree

1 file changed

+71
-0
lines changed

1 file changed

+71
-0
lines changed

contributors/devel/sig-architecture/api-conventions.md

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ An introduction to using resources with kubectl can be found in [the object mana
2222
- [Differing Representations](#differing-representations)
2323
- [Verbs on Resources](#verbs-on-resources)
2424
- [PATCH operations](#patch-operations)
25+
- [Short-names and Categories](#short-names-and-categories)
26+
- [Short-names](#short-names)
27+
- [Categories](#categories)
2528
- [Idempotency](#idempotency)
2629
- [Optional vs. Required](#optional-vs-required)
2730
- [Defaulting](#defaulting)
@@ -716,6 +719,74 @@ saved. For more details on how to use Merge Patch, see the RFC.
716719
detailed explanation of how it works and why it needed to be introduced, see
717720
[here](/contributors/devel/sig-api-machinery/strategic-merge-patch.md).
718721

722+
## Short-names and Categories
723+
724+
Resource implementers can optionally include "short names" and categories
725+
in the discovery information published for a resource type,
726+
which clients may use as hints when resolving ambiguous user invocations.
727+
728+
For compiled-in resources, these are controlled by the REST handler `ShortNames() []string` and `Categories() []string` implementations.
729+
730+
For custom resources, these are controlled by the `.spec.names.shortNames` and `.spec.names.categories` fields in the CustomResourceDefinition.
731+
732+
### Short-names
733+
734+
Note: Due to unpredictable behavior when short names collide (with each other or with resource types),
735+
do not add new short names to built-in resources unless specifically allowed by API reviewers. See issues
736+
[#117742](https://issue.k8s.io/117742#issuecomment-1545945336) and [#108573](http://issue.k8s.io/108573).
737+
738+
"Short names" listed in discovery may be used by clients as hints to resolve ambiguous user invocations to a single resource.
739+
740+
Examples of built-in short names include:
741+
742+
* `ds` -> `apps/v* daemonsets`
743+
* `sts` -> `apps/v* statefulsets`
744+
* `hpa` -> `autoscaling/v* horizontalpodautoscalers`
745+
746+
For example, with only built-in API types served, `kubectl get sts` is equivalent to `kubectl get statefulsets.v1.apps`.
747+
748+
Short-name matches may be given lower priority than an exact match of a resource type,
749+
so use of short names increases potential for inconsistent behavior in clusters
750+
with custom resources installed, if those custom resource types overlap with short names.
751+
752+
Continuing the above example, if a custom resource with `.spec.names.plural` set to `sts` was installed in a cluster,
753+
`kubectl get sts` would switch to retrieving instances of the custom resource instead.
754+
755+
### Categories
756+
757+
Note: Due to inconsistent behavior when categories collide with resource types,
758+
and difficulties knowing when it is safe to add new resources to an existing category,
759+
do not add new categories to built-in resources unless specifically allowed by API reviewers.
760+
See issues [#7547](https://github.com/kubernetes/kubernetes/issues/7547#issuecomment-355835279)
761+
[#42885](https://github.com/kubernetes/kubernetes/issues/42885#issuecomment-531265679),
762+
and [considerations for adding to the "all" category](https://github.com/kubernetes/community/blob/master/contributors/devel/sig-cli/kubectl-conventions.md#rules-for-extending-special-resource-alias---all)
763+
for examples of the difficulties encountered.
764+
765+
Categories listed in discovery may be used by clients as hints to resolve user invocations to multiple resources.
766+
767+
Examples of built-in categories and the resources they map to include:
768+
* `api-extensions`
769+
* `apiregistration.k8s.io/v* apiservices`
770+
* `admissionregistration.k8s.io/v* mutatingwebhookconfigurations`
771+
* `admissionregistration.k8s.io/v* validatingwebhookconfigurations`
772+
* `admissionregistration.k8s.io/v* validatingadmissionpolicies`
773+
* `admissionregistration.k8s.io/v* validatingadmissionpolicybindings`
774+
* `apiextensions.k8s.io/v* customresourcedefinitions`
775+
* `all`
776+
* `v1 pods`
777+
* `v1 replicationcontrollers`
778+
* `v1 services`
779+
* `apps/v* daemonsets`
780+
* `apps/v* deployments`
781+
* `apps/v* replicasets`
782+
* `apps/v* statefulsets`
783+
* `autoscaling/v* horizontalpodautoscalers`
784+
* `batch/v* cronjobs`
785+
* `batch/v* jobs`
786+
787+
With the above categories, and only built-in API types served, `kubectl get all` would be equivalent to
788+
`kubectl get pods.v1.,replicationcontrollers.v1.,services.v1.,daemonsets.v1.apps,deployments.v1.apps,replicasets.v1.apps,statefulsets.v1.apps,horizontalpodautoscalers.v2.autoscaling,cronjobs.v1.batch,jobs.v1.batch,`.
789+
719790
## Idempotency
720791

721792
All compatible Kubernetes APIs MUST support "name idempotency" and respond with

0 commit comments

Comments
 (0)