Skip to content

Commit

Permalink
Pass maxDuration flag to each controller, preventing ctx cancel
Browse files Browse the repository at this point in the history
Signed-off-by: Danil-Grigorev <danil.grigorev@suse.com>
  • Loading branch information
Danil-Grigorev committed Sep 2, 2024
1 parent b54cc52 commit faf8d23
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
4 changes: 3 additions & 1 deletion internal/controllers/capiprovider_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"k8s.io/apimachinery/pkg/runtime"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/controller"
"sigs.k8s.io/controller-runtime/pkg/log"

operatorv1 "sigs.k8s.io/cluster-api-operator/api/v1alpha2"
Expand Down Expand Up @@ -96,8 +97,9 @@ func (r *CAPIProviderReconciler) patchStatus(ctx context.Context, capiProvider *
}

// SetupWithManager sets up the controller with the Manager.
func (r *CAPIProviderReconciler) SetupWithManager(_ context.Context, mgr ctrl.Manager) (err error) {
func (r *CAPIProviderReconciler) SetupWithManager(_ context.Context, mgr ctrl.Manager, options controller.Options) (err error) {
b := ctrl.NewControllerManagedBy(mgr).
WithOptions(options).
For(&turtlesv1.CAPIProvider{})

resources := []client.Object{
Expand Down
3 changes: 2 additions & 1 deletion internal/controllers/capiprovider_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
operatorv1 "sigs.k8s.io/cluster-api-operator/api/v1alpha2"
"sigs.k8s.io/cluster-api/util/conditions"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/controller"
. "sigs.k8s.io/controller-runtime/pkg/envtest/komega"
)

Expand All @@ -53,7 +54,7 @@ var _ = Describe("Reconcile CAPIProvider", func() {
Scheme: testEnv.GetScheme(),
}

Expect(r.SetupWithManager(ctx, testEnv.Manager)).ToNot(HaveOccurred())
Expect(r.SetupWithManager(ctx, testEnv.Manager, controller.Options{})).ToNot(HaveOccurred())
})

It("Should create infrastructure docker provider and secret", func() {
Expand Down
11 changes: 9 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,7 @@ func setupReconcilers(ctx context.Context, mgr ctrl.Manager) {
RancherClient: rancherClient,
}).SetupWithManager(ctx, mgr, controller.Options{
MaxConcurrentReconciles: concurrencyNumber,
CacheSyncTimeout: maxDuration,
}); err != nil {
setupLog.Error(err, "unable to create rancher management v3 cleanup controller")
os.Exit(1)
Expand All @@ -272,7 +273,10 @@ func setupReconcilers(ctx context.Context, mgr ctrl.Manager) {
if err := (&controllers.RancherKubeconfigSecretReconciler{
Client: mgr.GetClient(),
WatchFilterValue: watchFilterValue,
}).SetupWithManager(ctx, mgr, controller.Options{MaxConcurrentReconciles: concurrencyNumber}); err != nil {
}).SetupWithManager(ctx, mgr, controller.Options{
MaxConcurrentReconciles: concurrencyNumber,
CacheSyncTimeout: maxDuration,
}); err != nil {
setupLog.Error(err, "unable to create Rancher kubeconfig secret controller")
os.Exit(1)
}
Expand All @@ -283,7 +287,10 @@ func setupReconcilers(ctx context.Context, mgr ctrl.Manager) {
if err := (&controllers.CAPIProviderReconciler{
Client: mgr.GetClient(),
Scheme: scheme,
}).SetupWithManager(ctx, mgr); err != nil {
}).SetupWithManager(ctx, mgr, controller.Options{
MaxConcurrentReconciles: concurrencyNumber,
CacheSyncTimeout: maxDuration,
}); err != nil {
setupLog.Error(err, "unable to create CAPI Provider controller")
os.Exit(1)
}
Expand Down

0 comments on commit faf8d23

Please sign in to comment.