Skip to content

Commit

Permalink
add azuremachinepool and azuremanagedcontrolplane controllers
Browse files Browse the repository at this point in the history
  • Loading branch information
Cecile Robert-Michon committed Mar 8, 2022
1 parent 2dd3bdf commit 4e0dca5
Show file tree
Hide file tree
Showing 13 changed files with 282 additions and 162 deletions.
11 changes: 4 additions & 7 deletions azure/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,16 @@ import (
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
)

// Reconciler is a generic interface used by components offering a type of service.
// Example: virtualnetworks service would offer Reconcile/Delete methods.
// Reconciler is a generic interface for a controller reconciler which has Reconcile and Delete methods.
type Reconciler interface {
Name() string
Reconcile(ctx context.Context) error
Delete(ctx context.Context) error
}

// CredentialGetter is a Service which knows how to retrieve credentials for an Azure
// resource in a resource group.
type CredentialGetter interface {
// ServiceReconciler is an Azure service reconciler which can reconcile an Azure service.
type ServiceReconciler interface {
Name() string
Reconciler
GetCredentials(ctx context.Context, group string, cluster string) ([]byte, error)
}

// Authorizer is an interface which can get the subscription ID, base URI, and authorizer for an Azure service.
Expand Down
69 changes: 20 additions & 49 deletions azure/mock_azure/azure_mock.go

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

4 changes: 2 additions & 2 deletions azure/services/scalesets/scalesets.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ type (
}
)

// NewService creates a new service.
func NewService(scope ScaleSetScope, skuCache *resourceskus.Cache) *Service {
// New creates a new service.
func New(scope ScaleSetScope, skuCache *resourceskus.Cache) *Service {
return &Service{
Client: NewClient(scope),
Scope: scope,
Expand Down
2 changes: 1 addition & 1 deletion azure/services/scalesets/scalesets_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ func TestNewService(t *testing.T) {
ClusterScope: s,
})
g.Expect(err).NotTo(HaveOccurred())
actual := NewService(mps, resourceskus.NewStaticCache(nil, ""))
actual := New(mps, resourceskus.NewStaticCache(nil, ""))
g.Expect(actual).ToNot(BeNil())
}

Expand Down
4 changes: 2 additions & 2 deletions controllers/azurecluster_reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ type azureClusterService struct {
scope *scope.ClusterScope
// services is the list of services that are reconciled by this controller.
// The order of the services is important as it determines the order in which the services are reconciled.
services []azure.Reconciler
services []azure.ServiceReconciler
skuCache *resourceskus.Cache
}

Expand All @@ -56,7 +56,7 @@ func newAzureClusterService(scope *scope.ClusterScope) (*azureClusterService, er
}
return &azureClusterService{
scope: scope,
services: []azure.Reconciler{
services: []azure.ServiceReconciler{
groups.New(scope),
virtualnetworks.New(scope),
securitygroups.New(scope),
Expand Down
34 changes: 17 additions & 17 deletions controllers/azurecluster_reconciler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ import (
func TestAzureClusterServiceReconcile(t *testing.T) {
cases := map[string]struct {
expectedError string
expect func(one *mock_azure.MockReconcilerMockRecorder, two *mock_azure.MockReconcilerMockRecorder, three *mock_azure.MockReconcilerMockRecorder)
expect func(one *mock_azure.MockServiceReconcilerMockRecorder, two *mock_azure.MockServiceReconcilerMockRecorder, three *mock_azure.MockServiceReconcilerMockRecorder)
}{
"all services are reconciled in order": {
expectedError: "",
expect: func(one *mock_azure.MockReconcilerMockRecorder, two *mock_azure.MockReconcilerMockRecorder, three *mock_azure.MockReconcilerMockRecorder) {
expect: func(one *mock_azure.MockServiceReconcilerMockRecorder, two *mock_azure.MockServiceReconcilerMockRecorder, three *mock_azure.MockServiceReconcilerMockRecorder) {
gomock.InOrder(
one.Reconcile(gomockinternal.AContext()).Return(nil),
two.Reconcile(gomockinternal.AContext()).Return(nil),
Expand All @@ -50,7 +50,7 @@ func TestAzureClusterServiceReconcile(t *testing.T) {
},
"service reconcile fails": {
expectedError: "failed to reconcile AzureCluster service two: some error happened",
expect: func(one *mock_azure.MockReconcilerMockRecorder, two *mock_azure.MockReconcilerMockRecorder, three *mock_azure.MockReconcilerMockRecorder) {
expect: func(one *mock_azure.MockServiceReconcilerMockRecorder, two *mock_azure.MockServiceReconcilerMockRecorder, three *mock_azure.MockServiceReconcilerMockRecorder) {
gomock.InOrder(
one.Reconcile(gomockinternal.AContext()).Return(nil),
two.Reconcile(gomockinternal.AContext()).Return(errors.New("some error happened")),
Expand All @@ -67,9 +67,9 @@ func TestAzureClusterServiceReconcile(t *testing.T) {
t.Parallel()
mockCtrl := gomock.NewController(t)
defer mockCtrl.Finish()
svcOneMock := mock_azure.NewMockReconciler(mockCtrl)
svcTwoMock := mock_azure.NewMockReconciler(mockCtrl)
svcThreeMock := mock_azure.NewMockReconciler(mockCtrl)
svcOneMock := mock_azure.NewMockServiceReconciler(mockCtrl)
svcTwoMock := mock_azure.NewMockServiceReconciler(mockCtrl)
svcThreeMock := mock_azure.NewMockServiceReconciler(mockCtrl)

tc.expect(svcOneMock.EXPECT(), svcTwoMock.EXPECT(), svcThreeMock.EXPECT())

Expand All @@ -78,7 +78,7 @@ func TestAzureClusterServiceReconcile(t *testing.T) {
Cluster: &clusterv1.Cluster{},
AzureCluster: &infrav1.AzureCluster{},
},
services: []azure.Reconciler{
services: []azure.ServiceReconciler{
svcOneMock,
svcTwoMock,
svcThreeMock,
Expand All @@ -100,27 +100,27 @@ func TestAzureClusterServiceReconcile(t *testing.T) {
func TestAzureClusterServiceDelete(t *testing.T) {
cases := map[string]struct {
expectedError string
expect func(grp *mock_azure.MockReconcilerMockRecorder, one *mock_azure.MockReconcilerMockRecorder, two *mock_azure.MockReconcilerMockRecorder, three *mock_azure.MockReconcilerMockRecorder)
expect func(grp *mock_azure.MockServiceReconcilerMockRecorder, one *mock_azure.MockServiceReconcilerMockRecorder, two *mock_azure.MockServiceReconcilerMockRecorder, three *mock_azure.MockServiceReconcilerMockRecorder)
}{
"Resource Group is deleted successfully": {
expectedError: "",
expect: func(grp *mock_azure.MockReconcilerMockRecorder, one *mock_azure.MockReconcilerMockRecorder, two *mock_azure.MockReconcilerMockRecorder, three *mock_azure.MockReconcilerMockRecorder) {
expect: func(grp *mock_azure.MockServiceReconcilerMockRecorder, one *mock_azure.MockServiceReconcilerMockRecorder, two *mock_azure.MockServiceReconcilerMockRecorder, three *mock_azure.MockServiceReconcilerMockRecorder) {
gomock.InOrder(
grp.Name().Return(groups.ServiceName),
grp.Delete(gomockinternal.AContext()).Return(nil))
},
},
"Resource Group delete fails": {
expectedError: "failed to delete resource group: internal error",
expect: func(grp *mock_azure.MockReconcilerMockRecorder, one *mock_azure.MockReconcilerMockRecorder, two *mock_azure.MockReconcilerMockRecorder, three *mock_azure.MockReconcilerMockRecorder) {
expect: func(grp *mock_azure.MockServiceReconcilerMockRecorder, one *mock_azure.MockServiceReconcilerMockRecorder, two *mock_azure.MockServiceReconcilerMockRecorder, three *mock_azure.MockServiceReconcilerMockRecorder) {
gomock.InOrder(
grp.Name().Return(groups.ServiceName),
grp.Delete(gomockinternal.AContext()).Return(errors.New("internal error")))
},
},
"Resource Group not owned by cluster": {
expectedError: "",
expect: func(grp *mock_azure.MockReconcilerMockRecorder, one *mock_azure.MockReconcilerMockRecorder, two *mock_azure.MockReconcilerMockRecorder, three *mock_azure.MockReconcilerMockRecorder) {
expect: func(grp *mock_azure.MockServiceReconcilerMockRecorder, one *mock_azure.MockServiceReconcilerMockRecorder, two *mock_azure.MockServiceReconcilerMockRecorder, three *mock_azure.MockServiceReconcilerMockRecorder) {
gomock.InOrder(
grp.Name().Return(groups.ServiceName),
grp.Delete(gomockinternal.AContext()).Return(azure.ErrNotOwned),
Expand All @@ -131,7 +131,7 @@ func TestAzureClusterServiceDelete(t *testing.T) {
},
"service delete fails": {
expectedError: "failed to delete AzureCluster service two: some error happened",
expect: func(grp *mock_azure.MockReconcilerMockRecorder, one *mock_azure.MockReconcilerMockRecorder, two *mock_azure.MockReconcilerMockRecorder, three *mock_azure.MockReconcilerMockRecorder) {
expect: func(grp *mock_azure.MockServiceReconcilerMockRecorder, one *mock_azure.MockServiceReconcilerMockRecorder, two *mock_azure.MockServiceReconcilerMockRecorder, three *mock_azure.MockServiceReconcilerMockRecorder) {
gomock.InOrder(
grp.Name().Return(groups.ServiceName),
grp.Delete(gomockinternal.AContext()).Return(azure.ErrNotOwned),
Expand All @@ -150,18 +150,18 @@ func TestAzureClusterServiceDelete(t *testing.T) {
t.Parallel()
mockCtrl := gomock.NewController(t)
defer mockCtrl.Finish()
groupsMock := mock_azure.NewMockReconciler(mockCtrl)
svcOneMock := mock_azure.NewMockReconciler(mockCtrl)
svcTwoMock := mock_azure.NewMockReconciler(mockCtrl)
svcThreeMock := mock_azure.NewMockReconciler(mockCtrl)
groupsMock := mock_azure.NewMockServiceReconciler(mockCtrl)
svcOneMock := mock_azure.NewMockServiceReconciler(mockCtrl)
svcTwoMock := mock_azure.NewMockServiceReconciler(mockCtrl)
svcThreeMock := mock_azure.NewMockServiceReconciler(mockCtrl)

tc.expect(groupsMock.EXPECT(), svcOneMock.EXPECT(), svcTwoMock.EXPECT(), svcThreeMock.EXPECT())

s := &azureClusterService{
scope: &scope.ClusterScope{
AzureCluster: &infrav1.AzureCluster{},
},
services: []azure.Reconciler{
services: []azure.ServiceReconciler{
groupsMock,
svcOneMock,
svcTwoMock,
Expand Down
4 changes: 2 additions & 2 deletions controllers/azuremachine_reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ type azureMachineService struct {
scope *scope.MachineScope
// services is the list of services to be reconciled.
// The order of the services is important as it determines the order in which the services are reconciled.
services []azure.Reconciler
services []azure.ServiceReconciler
skuCache *resourceskus.Cache
}

Expand All @@ -53,7 +53,7 @@ func newAzureMachineService(machineScope *scope.MachineScope) (*azureMachineServ

return &azureMachineService{
scope: machineScope,
services: []azure.Reconciler{
services: []azure.ServiceReconciler{
publicips.New(machineScope),
inboundnatrules.New(machineScope),
networkinterfaces.New(machineScope, cache),
Expand Down
Loading

0 comments on commit 4e0dca5

Please sign in to comment.