Skip to content

Commit

Permalink
Document CustomResourceDefinition additionalPrinterColumns
Browse files Browse the repository at this point in the history
  • Loading branch information
sttts committed Jul 12, 2018
1 parent 2d302e6 commit 4ebd6b0
Showing 1 changed file with 90 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ The first delete request on an object with finalizers merely sets a value for th
entries in the `finalizer` list can only be removed.

This triggers controllers watching the object to execute any finalizers they handle.
This will be represented via polling update requests for that
This will be represented via polling update requests for that
object, until all finalizers have been removed and the resource is deleted.

The time period of polling update can be controlled by `metadata.deletionGracePeriodSeconds`.
Expand All @@ -226,7 +226,7 @@ This feature is __beta__ in v1.9.
You can disable this feature using the `CustomResourceValidation` feature gate on
the [kube-apiserver](/docs/admin/kube-apiserver):

```
```
--feature-gates=CustomResourceValidation=false
```

Expand Down Expand Up @@ -330,6 +330,94 @@ kubectl create -f my-crontab.yaml
crontab "my-new-cron-object" created
```

### Additional Printer Columns

Starting with Kubernetes 1.11, kubectl uses server-side printing. This means that the server decides which
columns are to be printed by `kubectl get`. These columns can be customized in a CustomResourceDefinition:

Save the CustomResourceDefinition to `resourcedefinition.yaml`:

```yaml
apiVersion: apiextensions.k8s.io/v1beta1
kind: CustomResourceDefinition
metadata:
name: crontabs.stable.example.com
spec:
group: stable.example.com
version: v1
scope: Namespaced
names:
plural: crontabs
singular: crontab
kind: CronTab
shortNames:
- ct
additionalPrinterColumns:
- name: Spec
type: string
description: The cron spec defining the interval a CronJob is run
JSONPath: .spec.cronSpec
- name: Replicas
type: integer
description: The number of jobs launched by the CronJob
JSONPath: .spec.replicas
- name: Age
type: date
JSONPath: .metadata.creationTimestamp
```

and create it:

```shell
kubectl create -f resourcedefinition.yaml
```

Finally, create an instance using the `my-crontab.yaml` from the previous section.

Now invoke the server-side printing via:

```shell
kubectl get crontab my-new-cron-object
```

and see the output of the custom columns:

```
NAME SPEC REPLICAS AGE
my-new-cron-object * * * * * 1 7s
```

Note, that the name column is implicit and does not have to be defined in the CRD.

Also note, that there is a `priority` field for each column. In Kubernetes 1.11 this
only differentiates between those columns shown in standard view (all those with priority `0`)
and those which are shown in addition in `-o wide` view (all those with priority `> 0`).

The following types are available to be used in the `type` field of columns (compare [OpenAPI v3 data types](https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.0.md#dataTypes)):

- `integer` – non-floating-point numbers
- `number` – floating point numbers
- `string` – strings
- `boolean` – true or false
- `date` – renderend differentially as time since this timestamp.

If the value inside a CustomResource does not match the type specified for the column,
the value is omitted. Hence, it is highly suggested to use CRD validation to ensure
that the value types are correct.

The following formats are available to be used in the `format` field of columns:

- `int32`
- `int64`
- `float`
- `double`
- `byte`
- `date`
- `date-time`
- `password`

These influence the printing style in kubectl.

### Subresources

Custom resources support `/status` and `/scale` subresources.
Expand Down Expand Up @@ -547,5 +635,3 @@ crontabs/my-new-cron-object 3s
* Learn how to [Migrate a ThirdPartyResource to CustomResourceDefinition](/docs/tasks/access-kubernetes-api/migrate-third-party-resource/).
* See [CustomResourceDefinition](/docs/reference/generated/kubernetes-api/{{< param "version" >}}/#customresourcedefinition-v1beta1-apiextensions-k8s-io).
{{% /capture %}}


0 comments on commit 4ebd6b0

Please sign in to comment.