Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions pkg/generate/codedeploy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,12 +113,12 @@ func TestCodeDeploy_Deployment(t *testing.T) {

// We marked the fields, "ApplicationName", "DeploymentGroupName",
// "DeploymentConfigName and "Description" as printer columns in the
// generator.yaml. Let's make sure that they are always returned in sorted
// order.
// generator.yaml and trimmed the "Name" suffix. Let's make sure that
// they are always returned in sorted order.
expPrinterColNames := []string{
"ApplicationName",
"DeploymentConfigName",
"DeploymentGroupName",
"Application",
"DeploymentConfig",
"DeploymentGroup",
"Description",
}
gotPrinterCols := crd.AdditionalPrinterColumns()
Expand Down
22 changes: 14 additions & 8 deletions pkg/generate/config/field.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,16 @@ type CompareFieldConfig struct {
NilEqualsZeroValue bool `json:"nil_equals_zero_value"`
}

// PrintFieldConfig instructs the code generator how to handle kubebuilder:printcolumn
// comment marker generation. If this struct is not nil, the field will be added to the
// columns of `kubectl get` response.
type PrintFieldConfig struct {
// Name instructs the code generator to override the column name used to
// include the field in `kubectl get` response. This field is generally used
// to override very long and redundant columns names.
Name string `json:"name"`
}

// FieldConfig contains instructions to the code generator about how
// to interpret the value of an Attribute and how to map it to a CRD's Spec or
// Status field
Expand All @@ -131,14 +141,6 @@ type FieldConfig struct {
// IsReadOnly indicates the field's value can not be set by a Kubernetes
// user; in other words, the field should go in the CR's Status struct
IsReadOnly bool `json:"is_read_only"`
// IsPrintable determines whether the field should be included in the
// AdditionalPrinterColumns list to be included in the `kubectl get`
// response.
IsPrintable bool `json:"is_printable"`
// PrintName instructs the code generator to override the column name used
// to include the field in `kubectl get` response. If `IsPrintable` is false
// this field is ignored.
PrintName string `json:"print_name"`
// Required indicates whether this field is a required member or not.
// This field is used to configure '+kubebuilder:validation:Required' on API object's members.
IsRequired *bool `json:"is_required,omitempty"`
Expand Down Expand Up @@ -168,4 +170,8 @@ type FieldConfig struct {
// Compare instructs the code generator how to produce code that compares
// the value of the field in two resources
Compare *CompareFieldConfig `json:"compare,omitempty"`
// Print instructs the code generator how to generate comment markers that
// influence hows field are printed in `kubectl get` response. If this field
// is not nil, it will be added to the columns of `kubectl get`.
Print *PrintFieldConfig `json:"print,omitempty"`
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,13 @@ resources:
# below, we're testing printer columns end up sorted properly in the CRD
fields:
DeploymentGroupName:
is_printable: true
print:
name: DeploymentGroup
ApplicationName:
is_printable: true
print:
name: Application
DeploymentConfigName:
is_printable: true
print:
name: DeploymentConfig
Description:
is_printable: true
print: {}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not a huge fan of this, as I feel it is overly verbose and easy to mess up :)

How about we just remove the IsPrintable field and keep the PrintName field, but make it a *string instead of string and just require any printable column to have PrintName set to a string value (even if that string value is the same name as the field).

Copy link
Member Author

@a-hilaly a-hilaly Jun 8, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem is that there are other configuration we want to add the PrinterColumn generator. Like order, priority, type and probably more in the future.

So long term, instead of having something like:

resources:
  Deployment:
    fields:
      DeploymentGroupName:
        is_printable: true
        print_name: DeploymentGroup
        print_order: 3
        print_priority: 1
      DeploymentConfigName:
        is_printable: true
        print_name: DeploymentConfig
        print_order: 2
        print_priority: 1
        print_type: string

we can have something like:

resources:
  Deployment:
    fields:
      DeploymentGroupName:
        print:
          name: DeploymentGroup
          order: 3
          priority: 1
      DeploymentConfigName:
        print:
          name: DeploymentConfig
          order: 2
          priority: 1
          type: string

The second option is way less verbose and easier/clearer to read/understand IMO.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, you convinced me. :)

4 changes: 2 additions & 2 deletions pkg/model/crd.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ func (r *CRD) AddSpecField(
fConfigs := r.cfg.ResourceFields(r.Names.Original)
fConfig := fConfigs[memberNames.Original]
f := NewField(r, fPath, memberNames, shapeRef, fConfig)
if fConfig != nil && fConfig.IsPrintable {
if fConfig != nil && fConfig.Print != nil {
r.addSpecPrintableColumn(f)
}
r.SpecFields[memberNames.Original] = f
Expand All @@ -193,7 +193,7 @@ func (r *CRD) AddStatusField(
fConfigs := r.cfg.ResourceFields(r.Names.Original)
fConfig := fConfigs[memberNames.Original]
f := NewField(r, fPath, memberNames, shapeRef, fConfig)
if fConfig != nil && fConfig.IsPrintable {
if fConfig != nil && fConfig.Print != nil {
r.addStatusPrintableColumn(f)
}
r.StatusFields[memberNames.Original] = f
Expand Down
4 changes: 2 additions & 2 deletions pkg/model/printer_column.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,8 @@ func (r *CRD) addPrintableColumn(
}

name := field.Names.Camel
if field.FieldConfig.PrintName != "" {
name = field.FieldConfig.PrintName
if field.FieldConfig.Print.Name != "" {
name = field.FieldConfig.Print.Name
}

column := &PrinterColumn{
Expand Down