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
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 nil
}

resourceConfig, ok := c.Resources[resourceName]
if !ok || resourceConfig.Print == nil || len(resourceConfig.Print.AdditionalColumns) == 0 {
return nil
}
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 {
// Name is the thing to display in the column's output.
Name string `json:"name"`
// JSONPath defines the source of the output.
JSONPath string `json:"json_path"`
// Type is 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"`
// Priority of the column in the resource's output.
Priority int `json:"priority,omitempty"`
// Index is 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
12 changes: 12 additions & 0 deletions pkg/model/crd.go
Original file line number Diff line number Diff line change
Expand Up @@ -566,6 +566,18 @@ func (r *CRD) PrintSyncedColumn() bool {
return r.cfg.ResourceDisplaysSyncedColumn(r.Names.Camel)
}

func (r *CRD) addAdditionalPrinterColumns(additionalColumns []*ackgenconfig.AdditionalColumnConfig) {
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)
}
}

// 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.addAdditionalPrinterColumns(m.cfg.GetAdditionalColumns(crdName))

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