Skip to content

Commit

Permalink
#81 - fix tests in main_internal_test
Browse files Browse the repository at this point in the history
  • Loading branch information
meiserloh committed Oct 7, 2024
1 parent 033f9b7 commit 0ec151a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
13 changes: 9 additions & 4 deletions main_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
}
11 changes: 10 additions & 1 deletion pkg/adapter/reconciler/blueprint_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
}

0 comments on commit 0ec151a

Please sign in to comment.