Skip to content

Commit 465c44d

Browse files
committed
feat: modify generated code for lazyBindControllers feature
related to aws-controllers-k8s/runtime#240
1 parent ece451c commit 465c44d

5 files changed

Lines changed: 31 additions & 5 deletions

File tree

templates/cmd/controller/main.go.tpl

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,13 +69,14 @@ func main() {
6969
flag.Parse()
7070
ackCfg.SetupLogger()
7171

72+
ctx := ctrlrt.SetupSignalHandler()
73+
7274
managerFactories := svcresource.GetManagerFactories()
7375
resourceGVKs := make([]schema.GroupVersionKind, 0, len(managerFactories))
7476
for _, mf := range managerFactories {
7577
resourceGVKs = append(resourceGVKs, mf.ResourceDescriptor().GroupVersionKind())
7678
}
7779

78-
ctx := context.Background()
7980
if err := ackCfg.Validate(ctx, ackcfg.WithGVKs(resourceGVKs)); err != nil {
8081
setupLog.Error(
8182
err, "Unable to create controller manager",
@@ -144,8 +145,6 @@ func main() {
144145
os.Exit(1)
145146
}
146147

147-
stopChan := ctrlrt.SetupSignalHandler()
148-
149148
setupLog.Info(
150149
"initializing service controller",
151150
"aws.service", awsServiceAlias,
@@ -177,7 +176,7 @@ func main() {
177176
}
178177
}
179178

180-
if err = sc.BindControllerManager(mgr, ackCfg); err != nil {
179+
if err = sc.BindControllerManager(ctx, mgr, ackCfg); err != nil {
181180
setupLog.Error(
182181
err, "unable bind to controller manager to service controller",
183182
"aws.service", awsServiceAlias,
@@ -204,7 +203,7 @@ func main() {
204203
"starting manager",
205204
"aws.service", awsServiceAlias,
206205
)
207-
if err := mgr.Start(stopChan); err != nil {
206+
if err := mgr.Start(ctx); err != nil {
208207
setupLog.Error(
209208
err, "unable to start controller manager",
210209
"aws.service", awsServiceAlias,

templates/config/controller/deployment.yaml.tpl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ spec:
4444
- --feature-gates
4545
- "$(FEATURE_GATES)"
4646
- --enable-carm=$(ENABLE_CARM)
47+
- --lazy-bind-reconcilers=$(LAZY_BIND_RECONCILERS)
48+
- --lazy-bind-retry-interval
49+
- "$(LAZY_BIND_RETRY_INTERVAL)"
4750
image: controller:latest
4851
name: controller
4952
ports:
@@ -83,6 +86,10 @@ spec:
8386
value: ""
8487
- name: "ENABLE_CARM"
8588
value: "true"
89+
- name: "LAZY_BIND_RECONCILERS"
90+
value: "false"
91+
- name: "LAZY_BIND_RETRY_INTERVAL"
92+
value: "10"
8693
securityContext:
8794
allowPrivilegeEscalation: false
8895
privileged: false

templates/helm/templates/deployment.yaml.tpl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,11 @@ spec:
104104
- "$(FEATURE_GATES)"
105105
{{ "{{- end }}" }}
106106
- {{ "--enable-carm={{ .Values.enableCARM }}" }}
107+
- {{ "--lazy-bind-reconcilers={{ .Values.lazyBindReconcilers }}" }}
108+
{{ "{{- if .Values.lazyBindReconcilers }}" }}
109+
- --lazy-bind-retry-interval
110+
- {{ "{{ .Values.lazyBindRetryInterval | quote }}" }}
111+
{{ "{{- end }}" }}
107112
image: {{ "{{ .Values.image.repository }}:{{ .Values.image.tag }}" }}
108113
imagePullPolicy: {{ "{{ .Values.image.pullPolicy }}" }}
109114
name: controller

templates/helm/values.yaml.tpl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,15 @@ leaderElection:
180180
# Enable Cross Account Resource Management (default = true). Set this to false to disable cross account resource management.
181181
enableCARM: true
182182

183+
# Enable Lazy Bind Reconcilers (default = false). When enabled, defers reconciler
184+
# binding for missing CRDs until they become available, allowing the controller to
185+
# start serving installed CRDs immediately instead of crash-looping.
186+
lazyBindReconcilers: false
187+
188+
# The interval in seconds between retry attempts when polling the discovery API
189+
# for missing CRDs (only used when lazyBindReconcilers is true).
190+
lazyBindRetryInterval: 10
191+
183192
# Configuration for feature gates. These are optional controller features that
184193
# can be individually enabled ("true") or disabled ("false") by adding key/value
185194
# pairs below.

templates/pkg/resource/descriptor.go.tpl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,12 @@ func (d *resourceDescriptor) GroupVersionKind() schema.GroupVersionKind {
3737
return svcapitypes.GroupVersion.WithKind(GroupKind.Kind)
3838
}
3939

40+
// GroupVersionResource returns a Kubernetes schema.GroupVersionResource struct that
41+
// describes the API Group, Version and Resource of CRs described by the descriptor
42+
func (d *resourceDescriptor) GroupVersionResource() schema.GroupVersionResource {
43+
return GroupVersionResource
44+
}
45+
4046
// EmptyRuntimeObject returns an empty object prototype that may be used in
4147
// apimachinery and k8s client operations
4248
func (d *resourceDescriptor) EmptyRuntimeObject() rtclient.Object {

0 commit comments

Comments
 (0)