diff --git a/main_internal_test.go b/main_internal_test.go index b45fcb7..03a58a8 100644 --- a/main_internal_test.go +++ b/main_internal_test.go @@ -237,7 +237,7 @@ func Test_startOperator(t *testing.T) { recorderMock := newMockEventRecorder(t) ctrlManMock := newMockControllerManager(t) ctrlManMock.EXPECT().GetEventRecorderFor("k8s-blueprint-operator").Return(recorderMock) - ctrlManMock.EXPECT().GetControllerOptions().Return(config.Controller{}) + ctrlManMock.EXPECT().GetControllerOptions().Return(config.Controller{SkipNameValidation: newTrue()}) ctrlManMock.EXPECT().GetScheme().Return(createScheme(t)) ctrlManMock.EXPECT().GetLogger().Return(logr.New(logMock)) ctrlManMock.EXPECT().Add(mock.Anything).Return(nil) @@ -285,7 +285,7 @@ func Test_startOperator(t *testing.T) { recorderMock := newMockEventRecorder(t) ctrlManMock := newMockControllerManager(t) ctrlManMock.EXPECT().GetEventRecorderFor("k8s-blueprint-operator").Return(recorderMock) - ctrlManMock.EXPECT().GetControllerOptions().Return(config.Controller{}) + ctrlManMock.EXPECT().GetControllerOptions().Return(config.Controller{SkipNameValidation: newTrue()}) ctrlManMock.EXPECT().GetScheme().Return(createScheme(t)) ctrlManMock.EXPECT().GetLogger().Return(logr.New(logMock)) ctrlManMock.EXPECT().Add(mock.Anything).Return(nil) @@ -336,7 +336,7 @@ func Test_startOperator(t *testing.T) { recorderMock := newMockEventRecorder(t) ctrlManMock := newMockControllerManager(t) ctrlManMock.EXPECT().GetEventRecorderFor("k8s-blueprint-operator").Return(recorderMock) - ctrlManMock.EXPECT().GetControllerOptions().Return(config.Controller{}) + ctrlManMock.EXPECT().GetControllerOptions().Return(config.Controller{SkipNameValidation: newTrue()}) ctrlManMock.EXPECT().GetScheme().Return(createScheme(t)) ctrlManMock.EXPECT().GetLogger().Return(logr.New(logMock)) ctrlManMock.EXPECT().Add(mock.Anything).Return(nil) @@ -391,7 +391,7 @@ func Test_startOperator(t *testing.T) { recorderMock := newMockEventRecorder(t) ctrlManMock := newMockControllerManager(t) ctrlManMock.EXPECT().GetEventRecorderFor("k8s-blueprint-operator").Return(recorderMock) - ctrlManMock.EXPECT().GetControllerOptions().Return(config.Controller{}) + ctrlManMock.EXPECT().GetControllerOptions().Return(config.Controller{SkipNameValidation: newTrue()}) ctrlManMock.EXPECT().GetScheme().Return(createScheme(t)) ctrlManMock.EXPECT().GetLogger().Return(logr.New(logMock)) ctrlManMock.EXPECT().Add(mock.Anything).Return(nil) @@ -430,3 +430,8 @@ func createScheme(t *testing.T) *runtime.Scheme { scheme.AddKnownTypes(gv, &v1.Blueprint{}) return scheme } + +func newTrue() *bool { + b := true + return &b +} diff --git a/pkg/adapter/reconciler/blueprint_controller.go b/pkg/adapter/reconciler/blueprint_controller.go index 6bf068b..c7ae703 100644 --- a/pkg/adapter/reconciler/blueprint_controller.go +++ b/pkg/adapter/reconciler/blueprint_controller.go @@ -3,7 +3,9 @@ package reconciler import ( "context" "errors" + "sigs.k8s.io/controller-runtime/pkg/controller" "sigs.k8s.io/controller-runtime/pkg/predicate" + "sigs.k8s.io/controller-runtime/pkg/reconcile" "time" "github.com/go-logr/logr" @@ -77,8 +79,15 @@ func decideRequeueForError(logger logr.Logger, err error) (ctrl.Result, error) { // SetupWithManager sets up the controller with the Manager. func (r *BlueprintReconciler) SetupWithManager(mgr ctrl.Manager) error { + controllerOptions := mgr.GetControllerOptions() + options := controller.TypedOptions[reconcile.Request]{ + SkipNameValidation: controllerOptions.SkipNameValidation, + RecoverPanic: controllerOptions.RecoverPanic, + NeedLeaderElection: controllerOptions.NeedLeaderElection, + } return ctrl.NewControllerManagedBy(mgr). - For(&k8sv1.Blueprint{}). WithEventFilter(predicate.GenerationChangedPredicate{}). + WithOptions(options). + For(&k8sv1.Blueprint{}). Complete(r) }