Skip to content

Commit e517724

Browse files
authored
Add a new config to override kubebuilder printcolumn:name (#79)
Issue N/A In some CRDs like `GlobalTable` adding a `is_printable: true` to the `GlobalTableStatus` causes `kubectl get` to print very large/redundant column names. Description of changes: - This patch adds a new config to allow overriding kubebuilder `printcolumn:name` - Adds `metav1.Time` to the `acceptableColumnMap` By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
1 parent 1745951 commit e517724

File tree

2 files changed

+26
-16
lines changed

2 files changed

+26
-16
lines changed

pkg/generate/config/field.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,10 @@ type FieldConfig struct {
135135
// AdditionalPrinterColumns list to be included in the `kubectl get`
136136
// response.
137137
IsPrintable bool `json:"is_printable"`
138+
// PrintName instructs the code generator to override the column name used
139+
// to include the field in `kubectl get` response. If `IsPrintable` is false
140+
// this field is ignored.
141+
PrintName string `json:"print_name"`
138142
// Required indicates whether this field is a required member or not.
139143
// This field is used to configure '+kubebuilder:validation:Required' on API object's members.
140144
IsRequired *bool `json:"is_required,omitempty"`

pkg/model/printer_column.go

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -82,21 +82,22 @@ func (r *CRD) addPrintableColumn(
8282
// https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md#data-types
8383
// This maps Go type to OpenAPI type.
8484
acceptableColumnMaps := map[string]string{
85-
"string": "string",
86-
"boolean": "boolean",
87-
"int": "integer",
88-
"int8": "integer",
89-
"int16": "integer",
90-
"int32": "integer",
91-
"int64": "integer",
92-
"uint": "integer",
93-
"uint8": "integer",
94-
"uint16": "integer",
95-
"uint32": "integer",
96-
"uint64": "integer",
97-
"uintptr": "integer",
98-
"float32": "number",
99-
"float64": "number",
85+
"string": "string",
86+
"boolean": "boolean",
87+
"int": "integer",
88+
"int8": "integer",
89+
"int16": "integer",
90+
"int32": "integer",
91+
"int64": "integer",
92+
"uint": "integer",
93+
"uint8": "integer",
94+
"uint16": "integer",
95+
"uint32": "integer",
96+
"uint64": "integer",
97+
"uintptr": "integer",
98+
"float32": "number",
99+
"float64": "number",
100+
"metav1.Time": "date",
100101
}
101102
printColumnType, exists := acceptableColumnMaps[fieldColumnType]
102103

@@ -108,9 +109,14 @@ func (r *CRD) addPrintableColumn(
108109
panic(msg)
109110
}
110111

112+
name := field.Names.Camel
113+
if field.FieldConfig.PrintName != "" {
114+
name = field.FieldConfig.PrintName
115+
}
116+
111117
column := &PrinterColumn{
112118
CRD: r,
113-
Name: field.Names.Camel,
119+
Name: name,
114120
Type: printColumnType,
115121
JSONPath: jsonPath,
116122
}

0 commit comments

Comments
 (0)