@@ -84,8 +84,40 @@ respectively. Notice that each has a different API version.
84
84
Finally, if we wait a bit, we should notice that our CronJob continues to
85
85
reconcile, even though our controller is written against our v1 API version.
86
86
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
+
87
117
## Troubleshooting
88
118
89
119
[ steps for troubleshooting] ( /TODO.md )
90
120
91
121
[ 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