Skip to content

Commit 29a22d1

Browse files
authored
Merge pull request kubernetes-sigs#4162 from camilamacedo86/fix-multigroup
🐛 fix: ensure unique controller names to fix name conflicts in multigroup setup
2 parents ff8d772 + 79a06e5 commit 29a22d1

File tree

22 files changed

+30
-0
lines changed

22 files changed

+30
-0
lines changed

docs/book/src/cronjob-tutorial/testdata/project/internal/controller/cronjob_controller.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -574,5 +574,6 @@ func (r *CronJobReconciler) SetupWithManager(mgr ctrl.Manager) error {
574574
return ctrl.NewControllerManagedBy(mgr).
575575
For(&batchv1.CronJob{}).
576576
Owns(&kbatch.Job{}).
577+
Named("cronjob").
577578
Complete(r)
578579
}

docs/book/src/getting-started/testdata/project/internal/controller/memcached_controller.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,7 @@ func (r *MemcachedReconciler) SetupWithManager(mgr ctrl.Manager) error {
205205
return ctrl.NewControllerManagedBy(mgr).
206206
For(&cachev1alpha1.Memcached{}).
207207
Owns(&appsv1.Deployment{}).
208+
Named("memcached").
208209
Complete(r)
209210
}
210211

docs/book/src/multiversion-tutorial/testdata/project/internal/controller/cronjob_controller.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -574,5 +574,6 @@ func (r *CronJobReconciler) SetupWithManager(mgr ctrl.Manager) error {
574574
return ctrl.NewControllerManagedBy(mgr).
575575
For(&batchv1.CronJob{}).
576576
Owns(&kbatch.Job{}).
577+
Named("cronjob").
577578
Complete(r)
578579
}

pkg/plugins/golang/deploy-image/v1alpha1/scaffolds/internal/templates/controllers/controller.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -478,6 +478,11 @@ func (r *{{ .Resource.Kind }}Reconciler) SetupWithManager(mgr ctrl.Manager) erro
478478
// Uncomment the following line adding a pointer to an instance of the controlled resource as an argument
479479
// For().
480480
{{- end }}
481+
{{- if and (.MultiGroup) (not (isEmptyStr .Resource.Group)) }}
482+
Named("{{ lower .Resource.Group }}-{{ lower .Resource.Kind }}").
483+
{{- else }}
484+
Named("{{ lower .Resource.Kind }}").
485+
{{- end }}
481486
// Watch the Deployment managed by the {{ .Resource.Kind }}Reconciler. If any changes occur to the Deployment
482487
// owned and managed by this controller, it will trigger reconciliation, ensuring that the cluster
483488
// state aligns with the desired state. See that the ownerRef was set when the Deployment was created.

pkg/plugins/golang/v4/scaffolds/internal/templates/controllers/controller.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,11 @@ func (r *{{ .Resource.Kind }}Reconciler) SetupWithManager(mgr ctrl.Manager) erro
115115
// Uncomment the following line adding a pointer to an instance of the controlled resource as an argument
116116
// For().
117117
{{- end }}
118+
{{- if and (.MultiGroup) (not (isEmptyStr .Resource.Group)) }}
119+
Named("{{ lower .Resource.Group }}-{{ lower .Resource.Kind }}").
120+
{{- else }}
121+
Named("{{ lower .Resource.Kind }}").
122+
{{- end }}
118123
Complete(r)
119124
}
120125
`

testdata/project-v4-multigroup-with-plugins/internal/controller/apps/deployment_controller.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,5 +57,6 @@ func (r *DeploymentReconciler) Reconcile(ctx context.Context, req ctrl.Request)
5757
func (r *DeploymentReconciler) SetupWithManager(mgr ctrl.Manager) error {
5858
return ctrl.NewControllerManagedBy(mgr).
5959
For(&appsv1.Deployment{}).
60+
Named("apps-deployment").
6061
Complete(r)
6162
}

testdata/project-v4-multigroup-with-plugins/internal/controller/crew/captain_controller.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,5 +58,6 @@ func (r *CaptainReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ct
5858
func (r *CaptainReconciler) SetupWithManager(mgr ctrl.Manager) error {
5959
return ctrl.NewControllerManagedBy(mgr).
6060
For(&crewv1.Captain{}).
61+
Named("crew-captain").
6162
Complete(r)
6263
}

testdata/project-v4-multigroup-with-plugins/internal/controller/example.com/busybox_controller.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -434,6 +434,7 @@ func (r *BusyboxReconciler) SetupWithManager(mgr ctrl.Manager) error {
434434
// Watch the Busybox CR(s) and trigger reconciliation whenever it
435435
// is created, updated, or deleted
436436
For(&examplecomv1alpha1.Busybox{}).
437+
Named("example.com-busybox").
437438
// Watch the Deployment managed by the BusyboxReconciler. If any changes occur to the Deployment
438439
// owned and managed by this controller, it will trigger reconciliation, ensuring that the cluster
439440
// state aligns with the desired state. See that the ownerRef was set when the Deployment was created.

testdata/project-v4-multigroup-with-plugins/internal/controller/example.com/memcached_controller.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -440,6 +440,7 @@ func (r *MemcachedReconciler) SetupWithManager(mgr ctrl.Manager) error {
440440
// Watch the Memcached CR(s) and trigger reconciliation whenever it
441441
// is created, updated, or deleted
442442
For(&examplecomv1alpha1.Memcached{}).
443+
Named("example.com-memcached").
443444
// Watch the Deployment managed by the MemcachedReconciler. If any changes occur to the Deployment
444445
// owned and managed by this controller, it will trigger reconciliation, ensuring that the cluster
445446
// state aligns with the desired state. See that the ownerRef was set when the Deployment was created.

testdata/project-v4-multigroup-with-plugins/internal/controller/fiz/bar_controller.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,5 +58,6 @@ func (r *BarReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.R
5858
func (r *BarReconciler) SetupWithManager(mgr ctrl.Manager) error {
5959
return ctrl.NewControllerManagedBy(mgr).
6060
For(&fizv1.Bar{}).
61+
Named("fiz-bar").
6162
Complete(r)
6263
}

0 commit comments

Comments
 (0)