Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use a list for Azure services in reconcilers #2146

Merged
merged 2 commits into from
Mar 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions azure/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,6 @@ import (
infrav1 "sigs.k8s.io/cluster-api-provider-azure/api/v1beta1"
)

// ErrNotOwned is returned when a resource can't be deleted because it isn't owned.
var ErrNotOwned = errors.New("resource is not managed and cannot be deleted")

const codeResourceGroupNotFound = "ResourceGroupNotFound"

// ResourceGroupNotFound parses the error to check if it's a resource group not found error.
Expand Down
11 changes: 5 additions & 6 deletions azure/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,17 @@ 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 {
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 {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this wasn't used anymore

// ServiceReconciler is an Azure service reconciler which can reconcile an Azure service.
type ServiceReconciler interface {
Name() string
IsManaged(ctx context.Context) (bool, error)
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
62 changes: 38 additions & 24 deletions azure/mock_azure/azure_mock.go

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

6 changes: 0 additions & 6 deletions azure/scope/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -860,8 +860,6 @@ func (s *ClusterScope) UpdateDeleteStatus(condition clusterv1.ConditionType, ser
switch {
case err == nil:
conditions.MarkFalse(s.AzureCluster, condition, infrav1.DeletedReason, clusterv1.ConditionSeverityInfo, "%s successfully deleted", service)
case errors.Is(err, azure.ErrNotOwned):
// do nothing
case azure.IsOperationNotDoneError(err):
conditions.MarkFalse(s.AzureCluster, condition, infrav1.DeletingReason, clusterv1.ConditionSeverityInfo, "%s deleting", service)
default:
Expand All @@ -874,8 +872,6 @@ func (s *ClusterScope) UpdatePutStatus(condition clusterv1.ConditionType, servic
switch {
case err == nil:
conditions.MarkTrue(s.AzureCluster, condition)
case errors.Is(err, azure.ErrNotOwned):
// do nothing
case azure.IsOperationNotDoneError(err):
conditions.MarkFalse(s.AzureCluster, condition, infrav1.CreatingReason, clusterv1.ConditionSeverityInfo, "%s creating or updating", service)
default:
Expand All @@ -888,8 +884,6 @@ func (s *ClusterScope) UpdatePatchStatus(condition clusterv1.ConditionType, serv
switch {
case err == nil:
conditions.MarkTrue(s.AzureCluster, condition)
case errors.Is(err, azure.ErrNotOwned):
// do nothing
case azure.IsOperationNotDoneError(err):
conditions.MarkFalse(s.AzureCluster, condition, infrav1.UpdatingReason, clusterv1.ConditionSeverityInfo, "%s updating", service)
default:
Expand Down
6 changes: 0 additions & 6 deletions azure/scope/machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -665,8 +665,6 @@ func (m *MachineScope) UpdateDeleteStatus(condition clusterv1.ConditionType, ser
switch {
case err == nil:
conditions.MarkFalse(m.AzureMachine, condition, infrav1.DeletedReason, clusterv1.ConditionSeverityInfo, "%s successfully deleted", service)
case errors.Is(err, azure.ErrNotOwned):
// do nothing
case azure.IsOperationNotDoneError(err):
conditions.MarkFalse(m.AzureMachine, condition, infrav1.DeletingReason, clusterv1.ConditionSeverityInfo, "%s deleting", service)
default:
Expand All @@ -679,8 +677,6 @@ func (m *MachineScope) UpdatePutStatus(condition clusterv1.ConditionType, servic
switch {
case err == nil:
conditions.MarkTrue(m.AzureMachine, condition)
case errors.Is(err, azure.ErrNotOwned):
// do nothing
case azure.IsOperationNotDoneError(err):
conditions.MarkFalse(m.AzureMachine, condition, infrav1.CreatingReason, clusterv1.ConditionSeverityInfo, "%s creating or updating", service)
default:
Expand All @@ -693,8 +689,6 @@ func (m *MachineScope) UpdatePatchStatus(condition clusterv1.ConditionType, serv
switch {
case err == nil:
conditions.MarkTrue(m.AzureMachine, condition)
case errors.Is(err, azure.ErrNotOwned):
// do nothing
case azure.IsOperationNotDoneError(err):
conditions.MarkFalse(m.AzureMachine, condition, infrav1.UpdatingReason, clusterv1.ConditionSeverityInfo, "%s updating", service)
default:
Expand Down
6 changes: 0 additions & 6 deletions azure/scope/machinepool.go
Original file line number Diff line number Diff line change
Expand Up @@ -626,8 +626,6 @@ func (m *MachinePoolScope) UpdateDeleteStatus(condition clusterv1.ConditionType,
switch {
case err == nil:
conditions.MarkFalse(m.AzureMachinePool, condition, infrav1.DeletedReason, clusterv1.ConditionSeverityInfo, "%s successfully deleted", service)
case errors.Is(err, azure.ErrNotOwned):
// do nothing
case azure.IsOperationNotDoneError(err):
conditions.MarkFalse(m.AzureMachinePool, condition, infrav1.DeletingReason, clusterv1.ConditionSeverityInfo, "%s deleting", service)
default:
Expand All @@ -640,8 +638,6 @@ func (m *MachinePoolScope) UpdatePutStatus(condition clusterv1.ConditionType, se
switch {
case err == nil:
conditions.MarkTrue(m.AzureMachinePool, condition)
case errors.Is(err, azure.ErrNotOwned):
// do nothing
case azure.IsOperationNotDoneError(err):
conditions.MarkFalse(m.AzureMachinePool, condition, infrav1.CreatingReason, clusterv1.ConditionSeverityInfo, "%s creating or updating", service)
default:
Expand All @@ -654,8 +650,6 @@ func (m *MachinePoolScope) UpdatePatchStatus(condition clusterv1.ConditionType,
switch {
case err == nil:
conditions.MarkTrue(m.AzureMachinePool, condition)
case errors.Is(err, azure.ErrNotOwned):
// do nothing
case azure.IsOperationNotDoneError(err):
conditions.MarkFalse(m.AzureMachinePool, condition, infrav1.UpdatingReason, clusterv1.ConditionSeverityInfo, "%s updating", service)
default:
Expand Down
6 changes: 0 additions & 6 deletions azure/scope/machinepoolmachine.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,6 @@ func (s *MachinePoolMachineScope) UpdateDeleteStatus(condition clusterv1.Conditi
switch {
case err == nil:
conditions.MarkFalse(s.AzureMachinePoolMachine, condition, infrav1.DeletedReason, clusterv1.ConditionSeverityInfo, "%s successfully deleted", service)
case errors.Is(err, azure.ErrNotOwned):
// do nothing
case azure.IsOperationNotDoneError(err):
conditions.MarkFalse(s.AzureMachinePoolMachine, condition, infrav1.DeletingReason, clusterv1.ConditionSeverityInfo, "%s deleting", service)
default:
Expand All @@ -198,8 +196,6 @@ func (s *MachinePoolMachineScope) UpdatePutStatus(condition clusterv1.ConditionT
switch {
case err == nil:
conditions.MarkTrue(s.AzureMachinePoolMachine, condition)
case errors.Is(err, azure.ErrNotOwned):
// do nothing
case azure.IsOperationNotDoneError(err):
conditions.MarkFalse(s.AzureMachinePoolMachine, condition, infrav1.CreatingReason, clusterv1.ConditionSeverityInfo, "%s creating or updating", service)
default:
Expand All @@ -212,8 +208,6 @@ func (s *MachinePoolMachineScope) UpdatePatchStatus(condition clusterv1.Conditio
switch {
case err == nil:
conditions.MarkTrue(s.AzureMachinePoolMachine, condition)
case errors.Is(err, azure.ErrNotOwned):
// do nothing
case azure.IsOperationNotDoneError(err):
conditions.MarkFalse(s.AzureMachinePoolMachine, condition, infrav1.UpdatingReason, clusterv1.ConditionSeverityInfo, "%s updating", service)
default:
Expand Down
6 changes: 0 additions & 6 deletions azure/scope/managedcontrolplane.go
Original file line number Diff line number Diff line change
Expand Up @@ -695,8 +695,6 @@ func (s *ManagedControlPlaneScope) UpdateDeleteStatus(condition clusterv1.Condit
switch {
case err == nil:
conditions.MarkFalse(s.PatchTarget, condition, infrav1.DeletedReason, clusterv1.ConditionSeverityInfo, "%s successfully deleted", service)
case errors.Is(err, azure.ErrNotOwned):
// do nothing
case azure.IsOperationNotDoneError(err):
conditions.MarkFalse(s.PatchTarget, condition, infrav1.DeletingReason, clusterv1.ConditionSeverityInfo, "%s deleting", service)
default:
Expand All @@ -709,8 +707,6 @@ func (s *ManagedControlPlaneScope) UpdatePutStatus(condition clusterv1.Condition
switch {
case err == nil:
conditions.MarkTrue(s.PatchTarget, condition)
case errors.Is(err, azure.ErrNotOwned):
// do nothing
case azure.IsOperationNotDoneError(err):
conditions.MarkFalse(s.PatchTarget, condition, infrav1.CreatingReason, clusterv1.ConditionSeverityInfo, "%s creating or updating", service)
default:
Expand All @@ -723,8 +719,6 @@ func (s *ManagedControlPlaneScope) UpdatePatchStatus(condition clusterv1.Conditi
switch {
case err == nil:
conditions.MarkTrue(s.PatchTarget, condition)
case errors.Is(err, azure.ErrNotOwned):
// do nothing
case azure.IsOperationNotDoneError(err):
conditions.MarkFalse(s.PatchTarget, condition, infrav1.UpdatingReason, clusterv1.ConditionSeverityInfo, "%s updating", service)
default:
Expand Down
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
10 changes: 10 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 Expand Up @@ -114,3 +119,8 @@ func (s *Service) Delete(ctx context.Context) error {
s.Scope.UpdateDeleteStatus(infrav1.AvailabilitySetReadyCondition, serviceName, resultingErr)
return resultingErr
}

// IsManaged returns always returns true as CAPZ does not support BYO availability set.
func (s *Service) IsManaged(ctx context.Context) (bool, error) {
return true, nil
}
10 changes: 10 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 Expand Up @@ -87,3 +92,8 @@ func (s *Service) Delete(ctx context.Context) error {
s.Scope.UpdateDeleteStatus(infrav1.BastionHostReadyCondition, serviceName, resultingErr)
return resultingErr
}

// IsManaged returns always returns true as CAPZ does not support BYO bastion.
func (s *Service) IsManaged(ctx context.Context) (bool, error) {
return true, nil
}
10 changes: 10 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 Expand Up @@ -86,3 +91,8 @@ func (s *Service) Delete(ctx context.Context) error {
s.Scope.UpdateDeleteStatus(infrav1.DisksReadyCondition, serviceName, result)
return result
}

// IsManaged returns always returns true as CAPZ does not support BYO disk.
func (s *Service) IsManaged(ctx context.Context) (bool, error) {
return true, nil
}
Loading