Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
13 changes: 13 additions & 0 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,19 @@ type PrefixConfig struct {
StatusField string `json:"status_field,omitempty"`
}

// GetAdditionalColumns extracts AdditionalColumns defined for a given Resource
func (c *Config) GetAdditionalColumns(resourceName string) []*AdditionalColumnConfig {
if c == nil {
return []*AdditionalColumnConfig{}
}

resourceConfig, ok := c.Resources[resourceName]
if !ok || resourceConfig.Print == nil || len(resourceConfig.Print.AdditionalColumns) == 0 {
return []*AdditionalColumnConfig{}
Copy link
Member

Choose a reason for hiding this comment

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

Ditto

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

}
return resourceConfig.Print.AdditionalColumns
}

// GetCustomListFieldMembers finds all of the custom list fields that need to
// be generated as defined in the generator config.
func (c *Config) GetCustomListFieldMembers() []string {
Expand Down
20 changes: 20 additions & 0 deletions pkg/config/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,22 @@ type UpdateOperationConfig struct {
CustomMethodName string `json:"custom_method_name"`
}

// AdditionalConfig can be used to specify additional printer columns to be included
// in a Resource's output from kubectl
type AdditionalColumnConfig struct {
// the name to display in the column's output
Name string `json:"name"`
// the JSONPath definining the source of the output
JSONPath string `json:"json_path"`
// the OpenAPI type of the output
// c.f., https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md#data-types
Type string `json:"type"`
// the priority of the column in the resource's output
Priority int `json:"priority,omitempty"`
// the zero-based index of the position at which to display the column in output
Index int `json:"index,omitempty"`
}

// PrintConfig informs instruct the code generator on how to sort kubebuilder
// printcolumn marker coments.
type PrintConfig struct {
Expand All @@ -334,6 +350,10 @@ type PrintConfig struct {
AddSyncedColumn *bool `json:"add_synced_column"`
// OrderBy is the field used to sort the list of PrinterColumn options.
OrderBy string `json:"order_by"`

// AdditionalColumns can be used to add arbitrary extra columns to a Resource's output
// if present, should be a list of objects, each containing: name, json_path, and type
AdditionalColumns []*AdditionalColumnConfig `json:"additional_columns,omitempty"`
}

// ReconcileConfig describes options for controlling the reconciliation
Expand Down
14 changes: 14 additions & 0 deletions pkg/model/crd.go
Original file line number Diff line number Diff line change
Expand Up @@ -566,6 +566,20 @@ func (r *CRD) PrintSyncedColumn() bool {
return r.cfg.ResourceDisplaysSyncedColumn(r.Names.Camel)
}

func (r *CRD) setAdditionalPrinterColumns(additionalColumns []*ackgenconfig.AdditionalColumnConfig) {
r.additionalPrinterColumns = []*PrinterColumn{}

for _, additionalColumn := range additionalColumns {
printerColumn := &PrinterColumn{}
printerColumn.Name = additionalColumn.Name
printerColumn.JSONPath = additionalColumn.JSONPath
printerColumn.Type = additionalColumn.Type
printerColumn.Priority = additionalColumn.Priority
printerColumn.Index = additionalColumn.Index
r.additionalPrinterColumns = append(r.additionalPrinterColumns, printerColumn)
}
}

Copy link
Member

Choose a reason for hiding this comment

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

The allocation on L570 overrides the existing printerColumns previously added in model.go L284 and L236. Removing L570 should fix the code and the unit tests

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ahh, good point. In that case, I'm going to rename this addAdditionalPrinterColumns to avoid ambiguity.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

// ReconcileRequeuOnSuccessSeconds returns the duration after which to requeue
// the custom resource as int
func (r *CRD) ReconcileRequeuOnSuccessSeconds() int {
Expand Down
4 changes: 4 additions & 0 deletions pkg/model/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,10 @@ func (m *Model) GetCRDs() ([]*CRD, error) {
crd.AddStatusField(memberNames, memberShapeRef)
}

// Now add the additional printer columns that have been defined explicitly
// in additional_columns
crd.setAdditionalPrinterColumns(m.cfg.GetAdditionalColumns(crdName))

crds = append(crds, crd)
}
sort.Slice(crds, func(i, j int) bool {
Expand Down