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
22 changes: 22 additions & 0 deletions pkg/config/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,11 @@ type PrintConfig struct {
// NOTE: this is the Kubernetes resource Age (creation time at the api-server/etcd)
// and not the AWS resource Age.
AddAgeColumn bool `json:"add_age_column"`
// AddSyncedColumn is used to append a kubebuilder marker comment to show the status of a
// resource in `kubectl get` response.
//
// Default value is true.
AddSyncedColumn *bool `json:"add_synced_column"`
// OrderBy is the field used to sort the list of PrinterColumn options.
OrderBy string `json:"order_by"`
}
Expand Down Expand Up @@ -390,6 +395,23 @@ func (c *Config) ResourceDisplaysAgeColumn(resourceName string) bool {
return false
}

// ResourceDisplaysSyncedColumn returns true if the resource is
// configured to display the synced status.
func (c *Config) ResourceDisplaysSyncedColumn(resourceName string) bool {
if c == nil {
return false
}
rConfig, ok := c.Resources[resourceName]
if !ok {
return false
}
if rConfig.Print != nil {
// default value should be true.
return rConfig.Print.AddSyncedColumn == nil || *rConfig.Print.AddSyncedColumn
}
return false
}

// ResourceSetsSingleAttribute returns true if the supplied resource name has
// a SetAttributes operation that only actually changes a single attribute at a
// time. See: SNS SetTopicAttributes API call, which is entirely different from
Expand Down
6 changes: 6 additions & 0 deletions pkg/model/crd.go
Original file line number Diff line number Diff line change
Expand Up @@ -557,6 +557,12 @@ func (r *CRD) PrintAgeColumn() bool {
return r.cfg.ResourceDisplaysAgeColumn(r.Names.Camel)
}

// PrintSyncedColumn returns whether the code generator should append 'Sync'
// kubebuilder:printcolumn comment marker
func (r *CRD) PrintSyncedColumn() bool {
return r.cfg.ResourceDisplaysSyncedColumn(r.Names.Camel)
}

// ReconcileRequeuOnSuccessSeconds returns the duration after which to requeue
// the custom resource as int
func (r *CRD) ReconcileRequeuOnSuccessSeconds() int {
Expand Down
3 changes: 3 additions & 0 deletions templates/apis/crd.go.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ type {{ .CRD.Kind }}Status struct {
{{- range $column := .CRD.AdditionalPrinterColumns }}
// +kubebuilder:printcolumn:name="{{$column.Name}}",type={{$column.Type}},priority={{$column.Priority}},JSONPath=`{{$column.JSONPath}}`
{{- end }}
{{- if .CRD.PrintSyncedColumn }}
// +kubebuilder:printcolumn:name="Synced",type="boolean",priority=0,JSONPath=".status.conditions[?(@.type==\"ACK.ResourceSynced\")].status"
{{- end }}
{{- if .CRD.PrintAgeColumn }}
// +kubebuilder:printcolumn:name="Age",type="date",priority=0,JSONPath=".metadata.creationTimestamp"
{{- end }}
Expand Down