From 291b7d9ad2981b077f9c6268a4e7820c39b08a57 Mon Sep 17 00:00:00 2001 From: Jon Huhn Date: Fri, 29 Sep 2023 12:00:59 -0500 Subject: [PATCH] swap reconciler <--> Reconciler names --- azure/services/aso/aso.go | 16 ++++----- azure/services/aso/interfaces.go | 4 +-- azure/services/aso/mock_aso/aso_mock.go | 40 ++++++++++----------- azure/services/aso/service.go | 6 ++-- azure/services/aso/service_test.go | 48 ++++++++++++------------- 5 files changed, 57 insertions(+), 57 deletions(-) diff --git a/azure/services/aso/aso.go b/azure/services/aso/aso.go index 49cf0134465..751f3d2eac6 100644 --- a/azure/services/aso/aso.go +++ b/azure/services/aso/aso.go @@ -53,17 +53,17 @@ type deepCopier[T any] interface { DeepCopy() T } -// Reconciler is an implementation of the Reconciler interface. It handles creation +// reconciler is an implementation of the Reconciler interface. It handles creation // and deletion of resources using ASO. -type Reconciler[T deepCopier[T]] struct { +type reconciler[T deepCopier[T]] struct { client.Client clusterName string } -// New creates a new ASO service. -func New[T deepCopier[T]](ctrlClient client.Client, clusterName string) *Reconciler[T] { - return &Reconciler[T]{ +// New creates a new ASO reconciler. +func New[T deepCopier[T]](ctrlClient client.Client, clusterName string) Reconciler[T] { + return &reconciler[T]{ Client: ctrlClient, clusterName: clusterName, } @@ -71,7 +71,7 @@ func New[T deepCopier[T]](ctrlClient client.Client, clusterName string) *Reconci // CreateOrUpdateResource implements the logic for creating a new or updating an // existing resource with ASO. -func (r *Reconciler[T]) CreateOrUpdateResource(ctx context.Context, spec azure.ASOResourceSpecGetter[T], serviceName string) (T, error) { +func (r *reconciler[T]) CreateOrUpdateResource(ctx context.Context, spec azure.ASOResourceSpecGetter[T], serviceName string) (T, error) { ctx, log, done := tele.StartSpanWithLogger(ctx, "services.aso.CreateOrUpdateResource") defer done() @@ -232,7 +232,7 @@ func (r *Reconciler[T]) CreateOrUpdateResource(ctx context.Context, spec azure.A } // DeleteResource implements the logic for deleting a resource Asynchronously. -func (r *Reconciler[T]) DeleteResource(ctx context.Context, spec azure.ASOResourceSpecGetter[T], serviceName string) (err error) { +func (r *reconciler[T]) DeleteResource(ctx context.Context, spec azure.ASOResourceSpecGetter[T], serviceName string) (err error) { ctx, log, done := tele.StartSpanWithLogger(ctx, "services.aso.DeleteResource") defer done() @@ -294,7 +294,7 @@ func ownedByCluster(labels map[string]string, clusterName string) bool { } // PauseResource pauses an ASO resource by updating its `reconcile-policy` to `skip`. -func (r *Reconciler[T]) PauseResource(ctx context.Context, spec azure.ASOResourceSpecGetter[T], serviceName string) error { +func (r *reconciler[T]) PauseResource(ctx context.Context, spec azure.ASOResourceSpecGetter[T], serviceName string) error { ctx, log, done := tele.StartSpanWithLogger(ctx, "services.aso.PauseResource") defer done() diff --git a/azure/services/aso/interfaces.go b/azure/services/aso/interfaces.go index 0a34e85839a..92c059b9447 100644 --- a/azure/services/aso/interfaces.go +++ b/azure/services/aso/interfaces.go @@ -25,8 +25,8 @@ import ( "sigs.k8s.io/controller-runtime/pkg/client" ) -// reconciler is a generic interface used to perform reconciliation of Azure resources backed by ASO. -type reconciler[T genruntime.MetaObject] interface { +// Reconciler is a generic interface used to perform reconciliation of Azure resources backed by ASO. +type Reconciler[T genruntime.MetaObject] interface { CreateOrUpdateResource(ctx context.Context, spec azure.ASOResourceSpecGetter[T], serviceName string) (result T, err error) DeleteResource(ctx context.Context, spec azure.ASOResourceSpecGetter[T], serviceName string) (err error) PauseResource(ctx context.Context, spec azure.ASOResourceSpecGetter[T], serviceName string) (err error) diff --git a/azure/services/aso/mock_aso/aso_mock.go b/azure/services/aso/mock_aso/aso_mock.go index b4f979bca98..3806a18f417 100644 --- a/azure/services/aso/mock_aso/aso_mock.go +++ b/azure/services/aso/mock_aso/aso_mock.go @@ -36,31 +36,31 @@ import ( client "sigs.k8s.io/controller-runtime/pkg/client" ) -// Mockreconciler is a mock of reconciler interface. -type Mockreconciler[T genruntime.MetaObject] struct { +// MockReconciler is a mock of Reconciler interface. +type MockReconciler[T genruntime.MetaObject] struct { ctrl *gomock.Controller - recorder *MockreconcilerMockRecorder[T] + recorder *MockReconcilerMockRecorder[T] } -// MockreconcilerMockRecorder is the mock recorder for Mockreconciler. -type MockreconcilerMockRecorder[T genruntime.MetaObject] struct { - mock *Mockreconciler[T] +// MockReconcilerMockRecorder is the mock recorder for MockReconciler. +type MockReconcilerMockRecorder[T genruntime.MetaObject] struct { + mock *MockReconciler[T] } -// NewMockreconciler creates a new mock instance. -func NewMockreconciler[T genruntime.MetaObject](ctrl *gomock.Controller) *Mockreconciler[T] { - mock := &Mockreconciler[T]{ctrl: ctrl} - mock.recorder = &MockreconcilerMockRecorder[T]{mock} +// NewMockReconciler creates a new mock instance. +func NewMockReconciler[T genruntime.MetaObject](ctrl *gomock.Controller) *MockReconciler[T] { + mock := &MockReconciler[T]{ctrl: ctrl} + mock.recorder = &MockReconcilerMockRecorder[T]{mock} return mock } // EXPECT returns an object that allows the caller to indicate expected use. -func (m *Mockreconciler[T]) EXPECT() *MockreconcilerMockRecorder[T] { +func (m *MockReconciler[T]) EXPECT() *MockReconcilerMockRecorder[T] { return m.recorder } // CreateOrUpdateResource mocks base method. -func (m *Mockreconciler[T]) CreateOrUpdateResource(ctx context.Context, spec azure.ASOResourceSpecGetter[T], serviceName string) (T, error) { +func (m *MockReconciler[T]) CreateOrUpdateResource(ctx context.Context, spec azure.ASOResourceSpecGetter[T], serviceName string) (T, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "CreateOrUpdateResource", ctx, spec, serviceName) ret0, _ := ret[0].(T) @@ -69,13 +69,13 @@ func (m *Mockreconciler[T]) CreateOrUpdateResource(ctx context.Context, spec azu } // CreateOrUpdateResource indicates an expected call of CreateOrUpdateResource. -func (mr *MockreconcilerMockRecorder[T]) CreateOrUpdateResource(ctx, spec, serviceName any) *gomock.Call { +func (mr *MockReconcilerMockRecorder[T]) CreateOrUpdateResource(ctx, spec, serviceName any) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "CreateOrUpdateResource", reflect.TypeOf((*Mockreconciler[T])(nil).CreateOrUpdateResource), ctx, spec, serviceName) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "CreateOrUpdateResource", reflect.TypeOf((*MockReconciler[T])(nil).CreateOrUpdateResource), ctx, spec, serviceName) } // DeleteResource mocks base method. -func (m *Mockreconciler[T]) DeleteResource(ctx context.Context, spec azure.ASOResourceSpecGetter[T], serviceName string) error { +func (m *MockReconciler[T]) DeleteResource(ctx context.Context, spec azure.ASOResourceSpecGetter[T], serviceName string) error { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "DeleteResource", ctx, spec, serviceName) ret0, _ := ret[0].(error) @@ -83,13 +83,13 @@ func (m *Mockreconciler[T]) DeleteResource(ctx context.Context, spec azure.ASORe } // DeleteResource indicates an expected call of DeleteResource. -func (mr *MockreconcilerMockRecorder[T]) DeleteResource(ctx, spec, serviceName any) *gomock.Call { +func (mr *MockReconcilerMockRecorder[T]) DeleteResource(ctx, spec, serviceName any) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DeleteResource", reflect.TypeOf((*Mockreconciler[T])(nil).DeleteResource), ctx, spec, serviceName) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DeleteResource", reflect.TypeOf((*MockReconciler[T])(nil).DeleteResource), ctx, spec, serviceName) } // PauseResource mocks base method. -func (m *Mockreconciler[T]) PauseResource(ctx context.Context, spec azure.ASOResourceSpecGetter[T], serviceName string) error { +func (m *MockReconciler[T]) PauseResource(ctx context.Context, spec azure.ASOResourceSpecGetter[T], serviceName string) error { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "PauseResource", ctx, spec, serviceName) ret0, _ := ret[0].(error) @@ -97,9 +97,9 @@ func (m *Mockreconciler[T]) PauseResource(ctx context.Context, spec azure.ASORes } // PauseResource indicates an expected call of PauseResource. -func (mr *MockreconcilerMockRecorder[T]) PauseResource(ctx, spec, serviceName any) *gomock.Call { +func (mr *MockReconcilerMockRecorder[T]) PauseResource(ctx, spec, serviceName any) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "PauseResource", reflect.TypeOf((*Mockreconciler[T])(nil).PauseResource), ctx, spec, serviceName) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "PauseResource", reflect.TypeOf((*MockReconciler[T])(nil).PauseResource), ctx, spec, serviceName) } // MockTagsGetterSetter is a mock of TagsGetterSetter interface. diff --git a/azure/services/aso/service.go b/azure/services/aso/service.go index 0eab90f1626..c89cb01a9bd 100644 --- a/azure/services/aso/service.go +++ b/azure/services/aso/service.go @@ -27,7 +27,7 @@ import ( // Service provides operations on Azure resources. type Service[T deepCopier[T], S Scope] struct { - reconciler[T] + Reconciler[T] Scope S Specs []azure.ASOResourceSpecGetter[T] @@ -43,9 +43,9 @@ type Service[T deepCopier[T], S Scope] struct { // NewService creates a new Service. func NewService[T deepCopier[T], S Scope](name string, scope S) *Service[T, S] { return &Service[T, S]{ - name: name, + Reconciler: New[T](scope.GetClient(), scope.ClusterName()), Scope: scope, - reconciler: New[T](scope.GetClient(), scope.ClusterName()), + name: name, } } diff --git a/azure/services/aso/service_test.go b/azure/services/aso/service_test.go index 1e00baa5e83..0ef537366a0 100644 --- a/azure/services/aso/service_test.go +++ b/azure/services/aso/service_test.go @@ -50,12 +50,12 @@ func TestServiceReconcile(t *testing.T) { } reconcileErr := errors.New("CreateOrUpdateResource error") - reconciler := mock_aso.NewMockreconciler[*asoresourcesv1.ResourceGroup](mockCtrl) + reconciler := mock_aso.NewMockReconciler[*asoresourcesv1.ResourceGroup](mockCtrl) reconciler.EXPECT().CreateOrUpdateResource(gomockinternal.AContext(), specs[0], serviceName).Return(nil, reconcileErr) scope.EXPECT().UpdatePutStatus(conditionType, serviceName, reconcileErr) s := &Service[*asoresourcesv1.ResourceGroup, *mock_aso.MockScope]{ - reconciler: reconciler, + Reconciler: reconciler, Scope: scope, Specs: specs, name: serviceName, @@ -78,14 +78,14 @@ func TestServiceReconcile(t *testing.T) { mock_azure.NewMockASOResourceSpecGetter[*asoresourcesv1.ResourceGroup](mockCtrl), } - reconciler := mock_aso.NewMockreconciler[*asoresourcesv1.ResourceGroup](mockCtrl) + reconciler := mock_aso.NewMockReconciler[*asoresourcesv1.ResourceGroup](mockCtrl) reconciler.EXPECT().CreateOrUpdateResource(gomockinternal.AContext(), specs[0], serviceName).Return(nil, nil) reconciler.EXPECT().CreateOrUpdateResource(gomockinternal.AContext(), specs[1], serviceName).Return(nil, nil) reconciler.EXPECT().CreateOrUpdateResource(gomockinternal.AContext(), specs[2], serviceName).Return(nil, nil) scope.EXPECT().UpdatePutStatus(conditionType, serviceName, nil) s := &Service[*asoresourcesv1.ResourceGroup, *mock_aso.MockScope]{ - reconciler: reconciler, + Reconciler: reconciler, Scope: scope, Specs: specs, name: serviceName, @@ -109,14 +109,14 @@ func TestServiceReconcile(t *testing.T) { } reconcileErr := azure.NewOperationNotDoneError(&infrav1.Future{}) - reconciler := mock_aso.NewMockreconciler[*asoresourcesv1.ResourceGroup](mockCtrl) + reconciler := mock_aso.NewMockReconciler[*asoresourcesv1.ResourceGroup](mockCtrl) reconciler.EXPECT().CreateOrUpdateResource(gomockinternal.AContext(), specs[0], serviceName).Return(nil, nil) reconciler.EXPECT().CreateOrUpdateResource(gomockinternal.AContext(), specs[1], serviceName).Return(nil, reconcileErr) reconciler.EXPECT().CreateOrUpdateResource(gomockinternal.AContext(), specs[2], serviceName).Return(nil, nil) scope.EXPECT().UpdatePutStatus(conditionType, serviceName, reconcileErr) s := &Service[*asoresourcesv1.ResourceGroup, *mock_aso.MockScope]{ - reconciler: reconciler, + Reconciler: reconciler, Scope: scope, Specs: specs, name: serviceName, @@ -140,14 +140,14 @@ func TestServiceReconcile(t *testing.T) { } reconcileErr := errors.New("non-not done error") - reconciler := mock_aso.NewMockreconciler[*asoresourcesv1.ResourceGroup](mockCtrl) + reconciler := mock_aso.NewMockReconciler[*asoresourcesv1.ResourceGroup](mockCtrl) reconciler.EXPECT().CreateOrUpdateResource(gomockinternal.AContext(), specs[0], serviceName).Return(nil, azure.NewOperationNotDoneError(&infrav1.Future{})) reconciler.EXPECT().CreateOrUpdateResource(gomockinternal.AContext(), specs[1], serviceName).Return(nil, reconcileErr) reconciler.EXPECT().CreateOrUpdateResource(gomockinternal.AContext(), specs[2], serviceName).Return(nil, azure.NewOperationNotDoneError(&infrav1.Future{})) scope.EXPECT().UpdatePutStatus(conditionType, serviceName, reconcileErr) s := &Service[*asoresourcesv1.ResourceGroup, *mock_aso.MockScope]{ - reconciler: reconciler, + Reconciler: reconciler, Scope: scope, Specs: specs, name: serviceName, @@ -170,7 +170,7 @@ func TestServiceReconcile(t *testing.T) { reconcileErr := errors.New("CreateOrUpdateResource error") postErr := errors.New("PostReconcile error") - reconciler := mock_aso.NewMockreconciler[*asoresourcesv1.ResourceGroup](mockCtrl) + reconciler := mock_aso.NewMockReconciler[*asoresourcesv1.ResourceGroup](mockCtrl) reconciler.EXPECT().CreateOrUpdateResource(gomockinternal.AContext(), specs[0], serviceName).Return(&asoresourcesv1.ResourceGroup{ ObjectMeta: metav1.ObjectMeta{ Name: "a very special name", @@ -179,7 +179,7 @@ func TestServiceReconcile(t *testing.T) { scope.EXPECT().UpdatePutStatus(conditionType, serviceName, postErr) s := &Service[*asoresourcesv1.ResourceGroup, *mock_aso.MockScope]{ - reconciler: reconciler, + Reconciler: reconciler, Scope: scope, Specs: specs, name: serviceName, @@ -213,12 +213,12 @@ func TestServiceDelete(t *testing.T) { } deleteErr := errors.New("DeleteResource error") - reconciler := mock_aso.NewMockreconciler[*asoresourcesv1.ResourceGroup](mockCtrl) + reconciler := mock_aso.NewMockReconciler[*asoresourcesv1.ResourceGroup](mockCtrl) reconciler.EXPECT().DeleteResource(gomockinternal.AContext(), specs[0], serviceName).Return(deleteErr) scope.EXPECT().UpdateDeleteStatus(conditionType, serviceName, deleteErr) s := &Service[*asoresourcesv1.ResourceGroup, *mock_aso.MockScope]{ - reconciler: reconciler, + Reconciler: reconciler, Scope: scope, Specs: specs, name: serviceName, @@ -241,14 +241,14 @@ func TestServiceDelete(t *testing.T) { mock_azure.NewMockASOResourceSpecGetter[*asoresourcesv1.ResourceGroup](mockCtrl), } - reconciler := mock_aso.NewMockreconciler[*asoresourcesv1.ResourceGroup](mockCtrl) + reconciler := mock_aso.NewMockReconciler[*asoresourcesv1.ResourceGroup](mockCtrl) reconciler.EXPECT().DeleteResource(gomockinternal.AContext(), specs[0], serviceName).Return(nil) reconciler.EXPECT().DeleteResource(gomockinternal.AContext(), specs[1], serviceName).Return(nil) reconciler.EXPECT().DeleteResource(gomockinternal.AContext(), specs[2], serviceName).Return(nil) scope.EXPECT().UpdateDeleteStatus(conditionType, serviceName, nil) s := &Service[*asoresourcesv1.ResourceGroup, *mock_aso.MockScope]{ - reconciler: reconciler, + Reconciler: reconciler, Scope: scope, Specs: specs, name: serviceName, @@ -272,14 +272,14 @@ func TestServiceDelete(t *testing.T) { } deleteErr := azure.NewOperationNotDoneError(&infrav1.Future{}) - reconciler := mock_aso.NewMockreconciler[*asoresourcesv1.ResourceGroup](mockCtrl) + reconciler := mock_aso.NewMockReconciler[*asoresourcesv1.ResourceGroup](mockCtrl) reconciler.EXPECT().DeleteResource(gomockinternal.AContext(), specs[0], serviceName).Return(nil) reconciler.EXPECT().DeleteResource(gomockinternal.AContext(), specs[1], serviceName).Return(deleteErr) reconciler.EXPECT().DeleteResource(gomockinternal.AContext(), specs[2], serviceName).Return(nil) scope.EXPECT().UpdateDeleteStatus(conditionType, serviceName, deleteErr) s := &Service[*asoresourcesv1.ResourceGroup, *mock_aso.MockScope]{ - reconciler: reconciler, + Reconciler: reconciler, Scope: scope, Specs: specs, name: serviceName, @@ -303,14 +303,14 @@ func TestServiceDelete(t *testing.T) { } deleteErr := errors.New("non-not done error") - reconciler := mock_aso.NewMockreconciler[*asoresourcesv1.ResourceGroup](mockCtrl) + reconciler := mock_aso.NewMockReconciler[*asoresourcesv1.ResourceGroup](mockCtrl) reconciler.EXPECT().DeleteResource(gomockinternal.AContext(), specs[0], serviceName).Return(azure.NewOperationNotDoneError(&infrav1.Future{})) reconciler.EXPECT().DeleteResource(gomockinternal.AContext(), specs[1], serviceName).Return(deleteErr) reconciler.EXPECT().DeleteResource(gomockinternal.AContext(), specs[2], serviceName).Return(azure.NewOperationNotDoneError(&infrav1.Future{})) scope.EXPECT().UpdateDeleteStatus(conditionType, serviceName, deleteErr) s := &Service[*asoresourcesv1.ResourceGroup, *mock_aso.MockScope]{ - reconciler: reconciler, + Reconciler: reconciler, Scope: scope, Specs: specs, name: serviceName, @@ -333,12 +333,12 @@ func TestServiceDelete(t *testing.T) { deleteErr := errors.New("DeleteResource error") postErr := errors.New("PostDeleteHook error") - reconciler := mock_aso.NewMockreconciler[*asoresourcesv1.ResourceGroup](mockCtrl) + reconciler := mock_aso.NewMockReconciler[*asoresourcesv1.ResourceGroup](mockCtrl) reconciler.EXPECT().DeleteResource(gomockinternal.AContext(), specs[0], serviceName).Return(deleteErr) scope.EXPECT().UpdateDeleteStatus(conditionType, serviceName, postErr) s := &Service[*asoresourcesv1.ResourceGroup, *mock_aso.MockScope]{ - reconciler: reconciler, + Reconciler: reconciler, Scope: scope, Specs: specs, name: serviceName, @@ -368,13 +368,13 @@ func TestServicePause(t *testing.T) { mock_azure.NewMockASOResourceSpecGetter[*asoresourcesv1.ResourceGroup](mockCtrl), } - reconciler := mock_aso.NewMockreconciler[*asoresourcesv1.ResourceGroup](mockCtrl) + reconciler := mock_aso.NewMockReconciler[*asoresourcesv1.ResourceGroup](mockCtrl) reconciler.EXPECT().PauseResource(gomockinternal.AContext(), specs[0], serviceName).Return(nil) reconciler.EXPECT().PauseResource(gomockinternal.AContext(), specs[1], serviceName).Return(nil) reconciler.EXPECT().PauseResource(gomockinternal.AContext(), specs[2], serviceName).Return(nil) s := &Service[*asoresourcesv1.ResourceGroup, *mock_aso.MockScope]{ - reconciler: reconciler, + Reconciler: reconciler, Scope: scope, Specs: specs, name: serviceName, @@ -404,12 +404,12 @@ func TestServicePause(t *testing.T) { mock_azure.NewMockASOResourceSpecGetter[*asoresourcesv1.ResourceGroup](mockCtrl), } - reconciler := mock_aso.NewMockreconciler[*asoresourcesv1.ResourceGroup](mockCtrl) + reconciler := mock_aso.NewMockReconciler[*asoresourcesv1.ResourceGroup](mockCtrl) reconciler.EXPECT().PauseResource(gomockinternal.AContext(), specs[0], serviceName).Return(nil) reconciler.EXPECT().PauseResource(gomockinternal.AContext(), specs[1], serviceName).Return(errors.New("Pause error")) s := &Service[*asoresourcesv1.ResourceGroup, *mock_aso.MockScope]{ - reconciler: reconciler, + Reconciler: reconciler, Scope: scope, Specs: specs, name: serviceName,