Skip to content

Commit 18fb351

Browse files
committed
📖 note multiversion kubectl behavior
This describes how kubectl handles preferred versions, with a link to the official docs. This should make it clearer how folks can expect users to interact with multiversion APIs. It also adds a reminder to always use qualified GVRs in scripts.
1 parent c749b4c commit 18fb351

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

docs/book/src/multiversion-tutorial/deployment.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,40 @@ respectively. Notice that each has a different API version.
8484
Finally, if we wait a bit, we should notice that our CronJob continues to
8585
reconcile, even though our controller is written against our v1 API version.
8686

87+
<aside class="note">
88+
89+
<h1>kubectl and Preferred Versions</h1>
90+
91+
When we access our API types from Go code, we ask for a specific version
92+
by using that version's Go type (e.g. `batchv2.CronJob`).
93+
94+
You might've noticed that the above invocations of kubectl looked
95+
a little different from what we usually do -- namely, they specify
96+
a *group-version-resource*, instead of just a resource.
97+
98+
When we write `kubectl get cronjob`, kubectl needs to figure out which
99+
group-version-resource that maps to. To do this, it uses the *discovery
100+
API* to figure out the preferred version of the `cronjob` resource. For
101+
CRDs, this is more-or-less the latest stable version (see the [CRD
102+
docs][CRD-version-pref] for specific details).
103+
104+
With our updates to CronJob, this means that `kubectl get cronjob` fetches
105+
the `batch/v2` group-version.
106+
107+
If we want to specify an exact version, we can use `kubectl get
108+
resource.version.group`, as we do above.
109+
110+
***You should always use fully-qualified group-version-resource syntax in
111+
scripts***. `kubectl get resource` is for humans, self-aware robots, and
112+
other sentient beings that can figure out new versions. `kubectl get
113+
resource.version.group` is for everything else.
114+
115+
</aside>
116+
87117
## Troubleshooting
88118

89119
[steps for troubleshooting](/TODO.md)
90120

91121
[ref-multiver]: /reference/generating-crd.md#multiple-versions "Generating CRDs: Multiple Versions"
122+
123+
[crd-version-pref]: https://kubernetes.io/docs/tasks/access-kubernetes-api/custom-resources/custom-resource-definition-versioning/#version-priority "Versions in CustomResourceDefinitions"

0 commit comments

Comments
 (0)