Skip to content

Commit b6fcf29

Browse files
stttsMisty Linville
authored andcommitted
Document CustomResourceDefinition additionalPrinterColumns
1 parent 42decf8 commit b6fcf29

1 file changed

Lines changed: 109 additions & 12 deletions

File tree

content/en/docs/tasks/access-kubernetes-api/custom-resources/custom-resource-definitions.md

Lines changed: 109 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -208,23 +208,26 @@ metadata:
208208
Finalizers are arbitrary string values, that when present ensure that a hard delete
209209
of a resource is not possible while they exist.
210210
211-
The first delete request on an object with finalizers merely sets a value for the
212-
`metadata.deletionTimestamp` field instead of deleting it. Once this value is set,
211+
The first delete request on an object with finalizers sets a value for the
212+
`metadata.deletionTimestamp` field but does not delete it. Once this value is set,
213213
entries in the `finalizer` list can only be removed.
214214

215-
This triggers controllers watching the object to execute any finalizers they handle.
216-
This will be represented via polling update requests for that
217-
object, until all finalizers have been removed and the resource is deleted.
215+
When the `metadata.deletionTimestamp` field is set, controllers watching the object
216+
execute any finalizers they handle, by polling update requests for that
217+
object. When all finalizers have been executed, the resource is deleted.
218218

219-
The time period of polling update can be controlled by `metadata.deletionGracePeriodSeconds`.
219+
The value of `metadata.deletionGracePeriodSeconds` controls the interval between
220+
polling updates.
220221

221222
It is the responsibility of each controller to removes its finalizer from the list.
222223

223-
Kubernetes will only finally delete the object if the list of finalizers is empty,
224-
meaning all finalizers are done.
224+
Kubernetes only finally deletes the object if the list of finalizers is empty,
225+
meaning all finalizers have been executed.
225226

226227
### Validation
227228

229+
{{< feature-state state="beta" for_kubernetes_version="1.9" >}}
230+
228231
Validation of custom objects is possible via
229232
[OpenAPI v3 schema](https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.0.md#schemaObject).
230233
Additionally, the following restrictions are applied to the schema:
@@ -234,11 +237,10 @@ Additionally, the following restrictions are applied to the schema:
234237
- The field `uniqueItems` cannot be set to true.
235238
- The field `additionalProperties` cannot be set to false.
236239

237-
This feature is __beta__ in v1.9.
238240
You can disable this feature using the `CustomResourceValidation` feature gate on
239241
the [kube-apiserver](/docs/admin/kube-apiserver):
240242

241-
```
243+
```
242244
--feature-gates=CustomResourceValidation=false
243245
```
244246

@@ -346,6 +348,103 @@ kubectl create -f my-crontab.yaml
346348
crontab "my-new-cron-object" created
347349
```
348350

351+
### Additional printer columns
352+
353+
Starting with Kubernetes 1.11, kubectl uses server-side printing. The server decides which
354+
columns are shown by the `kubectl get` command. You can customize these columns using a
355+
CustomResourceDefinition. The following example adds the `Spec`, `Replicas`, and `Age`
356+
columns.
357+
358+
1. Save the CustomResourceDefinition to `resourcedefinition.yaml`.
359+
```yaml
360+
apiVersion: apiextensions.k8s.io/v1beta1
361+
kind: CustomResourceDefinition
362+
metadata:
363+
name: crontabs.stable.example.com
364+
spec:
365+
group: stable.example.com
366+
version: v1
367+
scope: Namespaced
368+
names:
369+
plural: crontabs
370+
singular: crontab
371+
kind: CronTab
372+
shortNames:
373+
- ct
374+
additionalPrinterColumns:
375+
- name: Spec
376+
type: string
377+
description: The cron spec defining the interval a CronJob is run
378+
JSONPath: .spec.cronSpec
379+
- name: Replicas
380+
type: integer
381+
description: The number of jobs launched by the CronJob
382+
JSONPath: .spec.replicas
383+
- name: Age
384+
type: date
385+
JSONPath: .metadata.creationTimestamp
386+
```
387+
388+
2. Create the CustomResourceDefinition:
389+
390+
```shell
391+
kubectl create -f resourcedefinition.yaml
392+
```
393+
394+
3. Create an instance using the `my-crontab.yaml` from the previous section.
395+
396+
4. Invoke the server-side printing:
397+
398+
```shell
399+
kubectl get crontab my-new-cron-object
400+
```
401+
402+
Notice the `NAME`, `SPEC`, `REPLICAS`, and `AGE` columns in the output:
403+
404+
```
405+
NAME SPEC REPLICAS AGE
406+
my-new-cron-object * * * * * 1 7s
407+
```
408+
409+
The `NAME` column is implicit and does not need to be defined in the CustomResourceDefinition.
410+
411+
#### Priority
412+
413+
Each column includes a `priority` field for each column. Currently, the priority
414+
differentiates between columns shown in standard view or wide view (using the `-o wide` flag).
415+
416+
- Columns with priority `0` are shown in standard view.
417+
- Columns with priority greater than `0` are shown only in wide view.
418+
419+
#### Type
420+
421+
A column's `type` field can be any of the following (compare [OpenAPI v3 data types](https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.0.md#dataTypes)):
422+
423+
- `integer` – non-floating-point numbers
424+
- `number` – floating point numbers
425+
- `string` – strings
426+
- `boolean` – true or false
427+
- `date` – rendered differentially as time since this timestamp.
428+
429+
If the value inside a CustomResource does not match the type specified for the column,
430+
the value is omitted. Use CustomResource validation to ensure that the value
431+
types are correct.
432+
433+
#### Format
434+
435+
A column's `format` field can be any of the following:
436+
437+
- `int32`
438+
- `int64`
439+
- `float`
440+
- `double`
441+
- `byte`
442+
- `date`
443+
- `date-time`
444+
- `password`
445+
446+
The column's `format` controls the style used when `kubectl` prints the value.
447+
349448
### Subresources
350449

351450
Custom resources support `/status` and `/scale` subresources.
@@ -569,5 +668,3 @@ crontabs/my-new-cron-object 3s
569668
* Serve [multiple versions](/docs/tasks/access-kubernetes-api/custom-resources/custom-resource-definition-versioning/) of a
570669
CustomResourceDefinition
571670
{{% /capture %}}
572-
573-

0 commit comments

Comments
 (0)