Skip to content

Commit

Permalink
Add service name to azure.Reconciler
Browse files Browse the repository at this point in the history
  • Loading branch information
Cecile Robert-Michon committed Mar 8, 2022
1 parent eb6756e commit 2dd3bdf
Show file tree
Hide file tree
Showing 33 changed files with 223 additions and 39 deletions.
1 change: 1 addition & 0 deletions azure/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
// Reconciler is a generic interface used by components offering a type of service.
// Example: virtualnetworks service would offer Reconcile/Delete methods.
type Reconciler interface {
Name() string
Reconcile(ctx context.Context) error
Delete(ctx context.Context) error
}
Expand Down
28 changes: 28 additions & 0 deletions azure/mock_azure/azure_mock.go

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

7 changes: 7 additions & 0 deletions azure/services/agentpools/agentpools.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ import (
"sigs.k8s.io/cluster-api-provider-azure/util/tele"
)

const serviceName = "agentpools"

// ManagedMachinePoolScope defines the scope interface for a managed machine pool.
type ManagedMachinePoolScope interface {
azure.ClusterDescriber
Expand All @@ -57,6 +59,11 @@ func New(scope ManagedMachinePoolScope) *Service {
}
}

// Name returns the service name.
func (s *Service) Name() string {
return serviceName
}

// Reconcile idempotently creates or updates a agent pool, if possible.
func (s *Service) Reconcile(ctx context.Context) error {
ctx, log, done := tele.StartSpanWithLogger(
Expand Down
5 changes: 5 additions & 0 deletions azure/services/availabilitysets/availabilitysets.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ func New(scope AvailabilitySetScope, skuCache *resourceskus.Cache) *Service {
}
}

// Name returns the service name.
func (s *Service) Name() string {
return serviceName
}

// Reconcile creates or updates availability sets.
func (s *Service) Reconcile(ctx context.Context) error {
ctx, log, done := tele.StartSpanWithLogger(ctx, "availabilitysets.Service.Reconcile")
Expand Down
5 changes: 5 additions & 0 deletions azure/services/bastionhosts/bastionhosts.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ func New(scope BastionScope) *Service {
}
}

// Name returns the service name.
func (s *Service) Name() string {
return serviceName
}

// Reconcile gets/creates/updates a bastion host.
func (s *Service) Reconcile(ctx context.Context) error {
ctx, _, done := tele.StartSpanWithLogger(ctx, "bastionhosts.Service.Reconcile")
Expand Down
5 changes: 5 additions & 0 deletions azure/services/disks/disks.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ func New(scope DiskScope) *Service {
}
}

// Name returns the service name.
func (s *Service) Name() string {
return serviceName
}

// Reconcile on disk is currently no-op. OS disks should only be deleted and will create with the VM automatically.
func (s *Service) Reconcile(ctx context.Context) error {
_, _, done := tele.StartSpanWithLogger(ctx, "disks.Service.Reconcile")
Expand Down
19 changes: 12 additions & 7 deletions azure/services/groups/groups.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import (
"sigs.k8s.io/cluster-api-provider-azure/util/tele"
)

const serviceName = "group"
const ServiceName = "group"

// Service provides operations on Azure resources.
type Service struct {
Expand All @@ -56,6 +56,11 @@ func New(scope GroupScope) *Service {
}
}

// Name returns the service name.
func (s *Service) Name() string {
return ServiceName
}

// Reconcile gets/creates/updates a resource group.
func (s *Service) Reconcile(ctx context.Context) error {
ctx, _, done := tele.StartSpanWithLogger(ctx, "groups.Service.Reconcile")
Expand All @@ -69,8 +74,8 @@ func (s *Service) Reconcile(ctx context.Context) error {
return nil
}

_, err := s.CreateResource(ctx, groupSpec, serviceName)
s.Scope.UpdatePutStatus(infrav1.ResourceGroupReadyCondition, serviceName, err)
_, err := s.CreateResource(ctx, groupSpec, ServiceName)
s.Scope.UpdatePutStatus(infrav1.ResourceGroupReadyCondition, ServiceName, err)
return err
}

Expand All @@ -92,8 +97,8 @@ func (s *Service) Delete(ctx context.Context) error {
if err != nil {
if azure.ResourceNotFound(err) {
// already deleted or doesn't exist, cleanup status and return.
s.Scope.DeleteLongRunningOperationState(groupSpec.ResourceName(), serviceName)
s.Scope.UpdateDeleteStatus(infrav1.ResourceGroupReadyCondition, serviceName, nil)
s.Scope.DeleteLongRunningOperationState(groupSpec.ResourceName(), ServiceName)
s.Scope.UpdateDeleteStatus(infrav1.ResourceGroupReadyCondition, ServiceName, nil)
return nil
}
return errors.Wrap(err, "could not get resource group management state")
Expand All @@ -103,8 +108,8 @@ func (s *Service) Delete(ctx context.Context) error {
return azure.ErrNotOwned
}

err = s.DeleteResource(ctx, groupSpec, serviceName)
s.Scope.UpdateDeleteStatus(infrav1.ResourceGroupReadyCondition, serviceName, err)
err = s.DeleteResource(ctx, groupSpec, ServiceName)
s.Scope.UpdateDeleteStatus(infrav1.ResourceGroupReadyCondition, ServiceName, err)
return err
}

Expand Down
20 changes: 10 additions & 10 deletions azure/services/groups/groups_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,17 +74,17 @@ func TestReconcileGroups(t *testing.T) {
expectedError: "",
expect: func(s *mock_groups.MockGroupScopeMockRecorder, m *mock_groups.MockclientMockRecorder, r *mock_async.MockReconcilerMockRecorder) {
s.GroupSpec().Return(&fakeGroupSpec)
r.CreateResource(gomockinternal.AContext(), &fakeGroupSpec, serviceName).Return(nil, nil)
s.UpdatePutStatus(infrav1.ResourceGroupReadyCondition, serviceName, nil)
r.CreateResource(gomockinternal.AContext(), &fakeGroupSpec, ServiceName).Return(nil, nil)
s.UpdatePutStatus(infrav1.ResourceGroupReadyCondition, ServiceName, nil)
},
},
{
name: "create resource group fails",
expectedError: "#: Internal Server Error: StatusCode=500",
expect: func(s *mock_groups.MockGroupScopeMockRecorder, m *mock_groups.MockclientMockRecorder, r *mock_async.MockReconcilerMockRecorder) {
s.GroupSpec().Return(&fakeGroupSpec)
r.CreateResource(gomockinternal.AContext(), &fakeGroupSpec, serviceName).Return(nil, internalError)
s.UpdatePutStatus(infrav1.ResourceGroupReadyCondition, serviceName, internalError)
r.CreateResource(gomockinternal.AContext(), &fakeGroupSpec, ServiceName).Return(nil, internalError)
s.UpdatePutStatus(infrav1.ResourceGroupReadyCondition, ServiceName, internalError)
},
},
}
Expand Down Expand Up @@ -140,8 +140,8 @@ func TestDeleteGroups(t *testing.T) {
s.GroupSpec().AnyTimes().Return(&fakeGroupSpec)
m.Get(gomockinternal.AContext(), &fakeGroupSpec).Return(sampleManagedGroup, nil)
s.ClusterName().Return("test-cluster")
r.DeleteResource(gomockinternal.AContext(), &fakeGroupSpec, serviceName).Return(nil)
s.UpdateDeleteStatus(infrav1.ResourceGroupReadyCondition, serviceName, nil)
r.DeleteResource(gomockinternal.AContext(), &fakeGroupSpec, ServiceName).Return(nil)
s.UpdateDeleteStatus(infrav1.ResourceGroupReadyCondition, ServiceName, nil)
},
},
{
Expand All @@ -167,8 +167,8 @@ func TestDeleteGroups(t *testing.T) {
expect: func(s *mock_groups.MockGroupScopeMockRecorder, m *mock_groups.MockclientMockRecorder, r *mock_async.MockReconcilerMockRecorder) {
s.GroupSpec().AnyTimes().Return(&fakeGroupSpec)
m.Get(gomockinternal.AContext(), &fakeGroupSpec).Return(resources.Group{}, notFoundError)
s.DeleteLongRunningOperationState("test-group", serviceName)
s.UpdateDeleteStatus(infrav1.ResourceGroupReadyCondition, serviceName, nil)
s.DeleteLongRunningOperationState("test-group", ServiceName)
s.UpdateDeleteStatus(infrav1.ResourceGroupReadyCondition, ServiceName, nil)
},
},
{
Expand All @@ -178,8 +178,8 @@ func TestDeleteGroups(t *testing.T) {
s.GroupSpec().AnyTimes().Return(&fakeGroupSpec)
m.Get(gomockinternal.AContext(), &fakeGroupSpec).Return(sampleManagedGroup, nil)
s.ClusterName().Return("test-cluster")
r.DeleteResource(gomockinternal.AContext(), &fakeGroupSpec, serviceName).Return(internalError)
s.UpdateDeleteStatus(infrav1.ResourceGroupReadyCondition, serviceName, gomockinternal.ErrStrEq("#: Internal Server Error: StatusCode=500"))
r.DeleteResource(gomockinternal.AContext(), &fakeGroupSpec, ServiceName).Return(internalError)
s.UpdateDeleteStatus(infrav1.ResourceGroupReadyCondition, ServiceName, gomockinternal.ErrStrEq("#: Internal Server Error: StatusCode=500"))
},
},
}
Expand Down
5 changes: 5 additions & 0 deletions azure/services/inboundnatrules/inboundnatrules.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ func New(scope InboundNatScope) *Service {
}
}

// Name returns the service name.
func (s *Service) Name() string {
return serviceName
}

// Reconcile gets/creates/updates an inbound NAT rule.
func (s *Service) Reconcile(ctx context.Context) error {
ctx, log, done := tele.StartSpanWithLogger(ctx, "inboundnatrules.Service.Reconcile")
Expand Down
5 changes: 5 additions & 0 deletions azure/services/loadbalancers/loadbalancers.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ func New(scope LBScope) *Service {
}
}

// Name returns the service name.
func (s *Service) Name() string {
return serviceName
}

// Reconcile gets/creates/updates a load balancer.
func (s *Service) Reconcile(ctx context.Context) error {
ctx, _, done := tele.StartSpanWithLogger(ctx, "loadbalancers.Service.Reconcile")
Expand Down
7 changes: 7 additions & 0 deletions azure/services/managedclusters/managedclusters.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ import (
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
)

const serviceName = "managedclusters"

var (
defaultUser = "azureuser"
managedIdentity = "msi"
Expand Down Expand Up @@ -145,6 +147,11 @@ func New(scope ManagedClusterScope) *Service {
}
}

// Name returns the service name.
func (s *Service) Name() string {
return serviceName
}

// Reconcile idempotently creates or updates a managed cluster, if possible.
func (s *Service) Reconcile(ctx context.Context) error {
ctx, _, done := tele.StartSpanWithLogger(ctx, "managedclusters.Service.Reconcile")
Expand Down
5 changes: 5 additions & 0 deletions azure/services/natgateways/natgateways.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ func New(scope NatGatewayScope) *Service {
}
}

// Name returns the service name.
func (s *Service) Name() string {
return serviceName
}

// Reconcile gets/creates/updates a NAT gateway.
// Only when the NAT gateway 'Name' property is defined we create the NAT gateway: it's opt-in.
func (s *Service) Reconcile(ctx context.Context) error {
Expand Down
5 changes: 5 additions & 0 deletions azure/services/networkinterfaces/networkinterfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ func New(scope NICScope, skuCache *resourceskus.Cache) *Service {
}
}

// Name returns the service name.
func (s *Service) Name() string {
return serviceName
}

// Reconcile gets/creates/updates a network interface.
func (s *Service) Reconcile(ctx context.Context) error {
ctx, _, done := tele.StartSpanWithLogger(ctx, "networkinterfaces.Service.Reconcile")
Expand Down
7 changes: 7 additions & 0 deletions azure/services/privatedns/privatedns.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ import (
"sigs.k8s.io/cluster-api-provider-azure/util/tele"
)

const serviceName = "privatedns"

// Scope defines the scope interface for a private dns service.
type Scope interface {
azure.ClusterDescriber
Expand All @@ -48,6 +50,11 @@ func New(scope Scope) *Service {
}
}

// Name returns the service name.
func (s *Service) Name() string {
return serviceName
}

// Reconcile creates or updates the private zone, links it to the vnet, and creates DNS records.
func (s *Service) Reconcile(ctx context.Context) error {
ctx, log, done := tele.StartSpanWithLogger(ctx, "privatedns.Service.Reconcile")
Expand Down
7 changes: 7 additions & 0 deletions azure/services/publicips/publicips.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ import (
"sigs.k8s.io/cluster-api-provider-azure/util/tele"
)

const serviceName = "publicips"

// PublicIPScope defines the scope interface for a public IP service.
type PublicIPScope interface {
azure.ClusterDescriber
Expand All @@ -49,6 +51,11 @@ func New(scope PublicIPScope) *Service {
}
}

// Name returns the service name.
func (s *Service) Name() string {
return serviceName
}

// Reconcile gets/creates/updates a public ip.
func (s *Service) Reconcile(ctx context.Context) error {
ctx, log, done := tele.StartSpanWithLogger(ctx, "publicips.Service.Reconcile")
Expand Down
10 changes: 9 additions & 1 deletion azure/services/roleassignments/roleassignments.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@ import (
"sigs.k8s.io/cluster-api-provider-azure/util/tele"
)

const azureBuiltInContributorID = "b24988ac-6180-42a0-ab88-20f7382dd24c"
const (
azureBuiltInContributorID = "b24988ac-6180-42a0-ab88-20f7382dd24c"
serviceName = "roleassignments"
)

// RoleAssignmentScope defines the scope interface for a role assignment service.
type RoleAssignmentScope interface {
Expand All @@ -57,6 +60,11 @@ func New(scope RoleAssignmentScope) *Service {
}
}

// Name returns the service name.
func (s *Service) Name() string {
return serviceName
}

// Reconcile creates a role assignment.
func (s *Service) Reconcile(ctx context.Context) error {
ctx, _, done := tele.StartSpanWithLogger(ctx, "roleassignments.Service.Reconcile")
Expand Down
5 changes: 5 additions & 0 deletions azure/services/routetables/routetables.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ func New(scope RouteTableScope) *Service {
}
}

// Name returns the service name.
func (s *Service) Name() string {
return serviceName
}

// Reconcile gets/creates/updates route tables.
func (s *Service) Reconcile(ctx context.Context) error {
ctx, log, done := tele.StartSpanWithLogger(ctx, "routetables.Service.Reconcile")
Expand Down
7 changes: 7 additions & 0 deletions azure/services/scalesets/scalesets.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ import (
"sigs.k8s.io/cluster-api-provider-azure/util/tele"
)

const serviceName = "scalesets"

type (
// ScaleSetScope defines the scope interface for a scale sets service.
ScaleSetScope interface {
Expand Down Expand Up @@ -68,6 +70,11 @@ func NewService(scope ScaleSetScope, skuCache *resourceskus.Cache) *Service {
}
}

// Name returns the service name.
func (s *Service) Name() string {
return serviceName
}

// Reconcile idempotently gets, creates, and updates a scale set.
func (s *Service) Reconcile(ctx context.Context) (retErr error) {
ctx, log, done := tele.StartSpanWithLogger(ctx, "scalesets.Service.Reconcile")
Expand Down
5 changes: 5 additions & 0 deletions azure/services/scalesetvms/scalesetvms.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ func NewService(scope ScaleSetVMScope) *Service {
}
}

// Name returns the service name.
func (s *Service) Name() string {
return serviceName
}

// Reconcile idempotently gets, creates, and updates a scale set.
func (s *Service) Reconcile(ctx context.Context) error {
ctx, _, done := tele.StartSpanWithLogger(ctx, "scalesetvms.Service.Reconcile")
Expand Down
Loading

0 comments on commit 2dd3bdf

Please sign in to comment.