Skip to content

Commit

Permalink
swap reconciler <--> Reconciler names
Browse files Browse the repository at this point in the history
  • Loading branch information
nojnhuh committed Sep 29, 2023
1 parent aa3d8d0 commit 291b7d9
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 57 deletions.
16 changes: 8 additions & 8 deletions azure/services/aso/aso.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,25 +53,25 @@ 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,
}
}

// 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()

Expand Down Expand Up @@ -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()

Expand Down Expand Up @@ -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()

Expand Down
4 changes: 2 additions & 2 deletions azure/services/aso/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
40 changes: 20 additions & 20 deletions azure/services/aso/mock_aso/aso_mock.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions azure/services/aso/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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,
}

Check warning on line 49 in azure/services/aso/service.go

View check run for this annotation

Codecov / codecov/patch

azure/services/aso/service.go#L44-L49

Added lines #L44 - L49 were not covered by tests
}

Expand Down
48 changes: 24 additions & 24 deletions azure/services/aso/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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",
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 291b7d9

Please sign in to comment.