Skip to content

Commit 5d5ae05

Browse files
authored
Move "printer column" options under the same generator config struct (#82)
Issue N/A Initially we used to have one config field ("is_printable") under `ackconfig.FieldConfig` to instruct the code generator to generate kubebuilder marker comments in order to include the field in `kubectl get` response. Time passed and we are in a situation where want to tune more the way we print these fields and extend the `kubebuilder:printcolumns` comment markers to include options like `priority`, `order` and default columns. This patch reworks the field configuration structure and prepare the laying ground for future print config fields. This patch will simplify the realization of the following issues: * aws-controllers-k8s/community#821 * aws-controllers-k8s/community#822 * aws-controllers-k8s/community#823 By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
1 parent 8d7e9fa commit 5d5ae05

File tree

5 files changed

+30
-21
lines changed

5 files changed

+30
-21
lines changed

pkg/generate/codedeploy_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -113,12 +113,12 @@ func TestCodeDeploy_Deployment(t *testing.T) {
113113

114114
// We marked the fields, "ApplicationName", "DeploymentGroupName",
115115
// "DeploymentConfigName and "Description" as printer columns in the
116-
// generator.yaml. Let's make sure that they are always returned in sorted
117-
// order.
116+
// generator.yaml and trimmed the "Name" suffix. Let's make sure that
117+
// they are always returned in sorted order.
118118
expPrinterColNames := []string{
119-
"ApplicationName",
120-
"DeploymentConfigName",
121-
"DeploymentGroupName",
119+
"Application",
120+
"DeploymentConfig",
121+
"DeploymentGroup",
122122
"Description",
123123
}
124124
gotPrinterCols := crd.AdditionalPrinterColumns()

pkg/generate/config/field.go

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,16 @@ type CompareFieldConfig struct {
116116
NilEqualsZeroValue bool `json:"nil_equals_zero_value"`
117117
}
118118

119+
// PrintFieldConfig instructs the code generator how to handle kubebuilder:printcolumn
120+
// comment marker generation. If this struct is not nil, the field will be added to the
121+
// columns of `kubectl get` response.
122+
type PrintFieldConfig struct {
123+
// Name instructs the code generator to override the column name used to
124+
// include the field in `kubectl get` response. This field is generally used
125+
// to override very long and redundant columns names.
126+
Name string `json:"name"`
127+
}
128+
119129
// FieldConfig contains instructions to the code generator about how
120130
// to interpret the value of an Attribute and how to map it to a CRD's Spec or
121131
// Status field
@@ -131,14 +141,6 @@ type FieldConfig struct {
131141
// IsReadOnly indicates the field's value can not be set by a Kubernetes
132142
// user; in other words, the field should go in the CR's Status struct
133143
IsReadOnly bool `json:"is_read_only"`
134-
// IsPrintable determines whether the field should be included in the
135-
// AdditionalPrinterColumns list to be included in the `kubectl get`
136-
// response.
137-
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"`
142144
// Required indicates whether this field is a required member or not.
143145
// This field is used to configure '+kubebuilder:validation:Required' on API object's members.
144146
IsRequired *bool `json:"is_required,omitempty"`
@@ -168,4 +170,8 @@ type FieldConfig struct {
168170
// Compare instructs the code generator how to produce code that compares
169171
// the value of the field in two resources
170172
Compare *CompareFieldConfig `json:"compare,omitempty"`
173+
// Print instructs the code generator how to generate comment markers that
174+
// influence hows field are printed in `kubectl get` response. If this field
175+
// is not nil, it will be added to the columns of `kubectl get`.
176+
Print *PrintFieldConfig `json:"print,omitempty"`
171177
}

pkg/generate/testdata/models/apis/codedeploy/0000-00-00/generator.yaml

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,13 @@ resources:
77
# below, we're testing printer columns end up sorted properly in the CRD
88
fields:
99
DeploymentGroupName:
10-
is_printable: true
10+
print:
11+
name: DeploymentGroup
1112
ApplicationName:
12-
is_printable: true
13+
print:
14+
name: Application
1315
DeploymentConfigName:
14-
is_printable: true
16+
print:
17+
name: DeploymentConfig
1518
Description:
16-
is_printable: true
19+
print: {}

pkg/model/crd.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ func (r *CRD) AddSpecField(
176176
fConfigs := r.cfg.ResourceFields(r.Names.Original)
177177
fConfig := fConfigs[memberNames.Original]
178178
f := NewField(r, fPath, memberNames, shapeRef, fConfig)
179-
if fConfig != nil && fConfig.IsPrintable {
179+
if fConfig != nil && fConfig.Print != nil {
180180
r.addSpecPrintableColumn(f)
181181
}
182182
r.SpecFields[memberNames.Original] = f
@@ -193,7 +193,7 @@ func (r *CRD) AddStatusField(
193193
fConfigs := r.cfg.ResourceFields(r.Names.Original)
194194
fConfig := fConfigs[memberNames.Original]
195195
f := NewField(r, fPath, memberNames, shapeRef, fConfig)
196-
if fConfig != nil && fConfig.IsPrintable {
196+
if fConfig != nil && fConfig.Print != nil {
197197
r.addStatusPrintableColumn(f)
198198
}
199199
r.StatusFields[memberNames.Original] = f

pkg/model/printer_column.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,8 @@ func (r *CRD) addPrintableColumn(
110110
}
111111

112112
name := field.Names.Camel
113-
if field.FieldConfig.PrintName != "" {
114-
name = field.FieldConfig.PrintName
113+
if field.FieldConfig.Print.Name != "" {
114+
name = field.FieldConfig.Print.Name
115115
}
116116

117117
column := &PrinterColumn{

0 commit comments

Comments
 (0)