From cac5654b7bb64c8f754ad9af01799ef70d9541b6 Mon Sep 17 00:00:00 2001 From: Amine Date: Wed, 9 Jun 2021 18:43:29 +0200 Subject: [PATCH] Add a new config to override `kubebuilder:printcolumn` priority (#86) Issue https://github.com/aws-controllers-k8s/community/issues/821 Description of changes: This patch introduces a new config field called "Standard" under `PrintFieldConfig` to indicates whether the column is of priority 0 or 1. By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license. --- pkg/generate/config/field.go | 4 ++++ pkg/model/printer_column.go | 2 ++ templates/apis/crd.go.tpl | 2 +- 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/pkg/generate/config/field.go b/pkg/generate/config/field.go index 70929637..17e0b777 100644 --- a/pkg/generate/config/field.go +++ b/pkg/generate/config/field.go @@ -124,6 +124,10 @@ type PrintFieldConfig struct { // include the field in `kubectl get` response. This field is generally used // to override very long and redundant columns names. Name string `json:"name"` + // Priority differentiates between fields/columns shown in standard view or wide + // view (using the -o wide flag). Fields with priority 0 are shown in standard view. + // Fields with priority greater than 0 are only shown in wide view. Default is 0 + Priority int `json:"priority"` } // FieldConfig contains instructions to the code generator about how diff --git a/pkg/model/printer_column.go b/pkg/model/printer_column.go index 6f8d4488..e5c49cab 100644 --- a/pkg/model/printer_column.go +++ b/pkg/model/printer_column.go @@ -24,6 +24,7 @@ type PrinterColumn struct { CRD *CRD Name string Type string + Priority int JSONPath string } @@ -140,6 +141,7 @@ func (r *CRD) addPrintableColumn( CRD: r, Name: name, Type: printColumnType, + Priority: field.FieldConfig.Print.Priority, JSONPath: jsonPath, } r.additionalPrinterColumns = append(r.additionalPrinterColumns, column) diff --git a/templates/apis/crd.go.tpl b/templates/apis/crd.go.tpl index af25bad6..e92de837 100644 --- a/templates/apis/crd.go.tpl +++ b/templates/apis/crd.go.tpl @@ -48,7 +48,7 @@ type {{ .CRD.Kind }}Status struct { // +kubebuilder:object:root=true // +kubebuilder:subresource:status {{- range $column := .CRD.AdditionalPrinterColumns }} -// +kubebuilder:printcolumn:name="{{$column.Name}}",type={{$column.Type}},JSONPath=`{{$column.JSONPath}}` +// +kubebuilder:printcolumn:name="{{$column.Name}}",type={{$column.Type}},priority={{$column.Priority}},JSONPath=`{{$column.JSONPath}}` {{- end }} {{- if .CRD.ShortNames }} // +kubebuilder:resource:shortName={{ Join .CRD.ShortNames ";" }}