Skip to content

Commit 92aec8d

Browse files
authored
Add a new generator config to append a Synced printer column (#329)
Issue: aws-controllers-k8s/community#1281 Description: Since all ACK kubernetes resources have a synced condition status, we need a way to instruct the code generator to generate kubebuilder marker comments that will append the SYNCED field the `kubectl get` response. This patch extends Resource.PrintConfig to allow configuring the ack-generate to generate such marker comments. By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
1 parent 141cb9d commit 92aec8d

File tree

3 files changed

+31
-0
lines changed

3 files changed

+31
-0
lines changed

pkg/config/resource.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,11 @@ type PrintConfig struct {
305305
// NOTE: this is the Kubernetes resource Age (creation time at the api-server/etcd)
306306
// and not the AWS resource Age.
307307
AddAgeColumn bool `json:"add_age_column"`
308+
// AddSyncedColumn is used to append a kubebuilder marker comment to show the status of a
309+
// resource in `kubectl get` response.
310+
//
311+
// Default value is true.
312+
AddSyncedColumn *bool `json:"add_synced_column"`
308313
// OrderBy is the field used to sort the list of PrinterColumn options.
309314
OrderBy string `json:"order_by"`
310315
}
@@ -390,6 +395,23 @@ func (c *Config) ResourceDisplaysAgeColumn(resourceName string) bool {
390395
return false
391396
}
392397

398+
// ResourceDisplaysSyncedColumn returns true if the resource is
399+
// configured to display the synced status.
400+
func (c *Config) ResourceDisplaysSyncedColumn(resourceName string) bool {
401+
if c == nil {
402+
return false
403+
}
404+
rConfig, ok := c.Resources[resourceName]
405+
if !ok {
406+
return false
407+
}
408+
if rConfig.Print != nil {
409+
// default value should be true.
410+
return rConfig.Print.AddSyncedColumn == nil || *rConfig.Print.AddSyncedColumn
411+
}
412+
return false
413+
}
414+
393415
// ResourceSetsSingleAttribute returns true if the supplied resource name has
394416
// a SetAttributes operation that only actually changes a single attribute at a
395417
// time. See: SNS SetTopicAttributes API call, which is entirely different from

pkg/model/crd.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -557,6 +557,12 @@ func (r *CRD) PrintAgeColumn() bool {
557557
return r.cfg.ResourceDisplaysAgeColumn(r.Names.Camel)
558558
}
559559

560+
// PrintSyncedColumn returns whether the code generator should append 'Sync'
561+
// kubebuilder:printcolumn comment marker
562+
func (r *CRD) PrintSyncedColumn() bool {
563+
return r.cfg.ResourceDisplaysSyncedColumn(r.Names.Camel)
564+
}
565+
560566
// ReconcileRequeuOnSuccessSeconds returns the duration after which to requeue
561567
// the custom resource as int
562568
func (r *CRD) ReconcileRequeuOnSuccessSeconds() int {

templates/apis/crd.go.tpl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@ type {{ .CRD.Kind }}Status struct {
5353
{{- range $column := .CRD.AdditionalPrinterColumns }}
5454
// +kubebuilder:printcolumn:name="{{$column.Name}}",type={{$column.Type}},priority={{$column.Priority}},JSONPath=`{{$column.JSONPath}}`
5555
{{- end }}
56+
{{- if .CRD.PrintSyncedColumn }}
57+
// +kubebuilder:printcolumn:name="Synced",type="boolean",priority=0,JSONPath=".status.conditions[?(@.type==\"ACK.ResourceSynced\")].status"
58+
{{- end }}
5659
{{- if .CRD.PrintAgeColumn }}
5760
// +kubebuilder:printcolumn:name="Age",type="date",priority=0,JSONPath=".metadata.creationTimestamp"
5861
{{- end }}

0 commit comments

Comments
 (0)