Skip to content

Commit

Permalink
Add a new config to override kubebuilder:printcolumn priority (#86)
Browse files Browse the repository at this point in the history
Issue aws-controllers-k8s/community#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.
  • Loading branch information
a-hilaly authored Jun 9, 2021
1 parent e8cba6c commit cac5654
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 1 deletion.
4 changes: 4 additions & 0 deletions pkg/generate/config/field.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions pkg/model/printer_column.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ type PrinterColumn struct {
CRD *CRD
Name string
Type string
Priority int
JSONPath string
}

Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion templates/apis/crd.go.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -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 ";" }}
Expand Down

0 comments on commit cac5654

Please sign in to comment.