From d04f9d22a113503a8e51e84554b2f0437602d64f Mon Sep 17 00:00:00 2001 From: Jonathan Tong Date: Tue, 15 Feb 2022 17:46:26 -0500 Subject: [PATCH] Add availability sets, bastion hosts, and route tables --- .../availabilitysets/availabilitysets.go | 2 ++ azure/services/bastionhosts/bastionhosts.go | 4 ++++ azure/services/routetables/routetables.go | 20 ++++++++++++++----- .../virtualmachines/virtualmachines.go | 4 +--- 4 files changed, 22 insertions(+), 8 deletions(-) diff --git a/azure/services/availabilitysets/availabilitysets.go b/azure/services/availabilitysets/availabilitysets.go index dccde1b9b87c..4e974fb83a53 100644 --- a/azure/services/availabilitysets/availabilitysets.go +++ b/azure/services/availabilitysets/availabilitysets.go @@ -70,6 +70,7 @@ func (s *Service) Reconcile(ctx context.Context) error { _, err = s.CreateResource(ctx, setSpec, serviceName) } else { log.V(2).Info("skip creation when no availability set spec is found") + return nil } s.Scope.UpdatePutStatus(infrav1.AvailabilitySetReadyCondition, serviceName, err) @@ -87,6 +88,7 @@ func (s *Service) Delete(ctx context.Context) error { var resultingErr error if setSpec := s.Scope.AvailabilitySetSpec(); setSpec == nil { log.V(2).Info("skip deletion when no availability set spec is found") + return nil } else { existingSet, err := s.Get(ctx, setSpec) if err != nil { diff --git a/azure/services/bastionhosts/bastionhosts.go b/azure/services/bastionhosts/bastionhosts.go index 2922f4f0c807..396a663f67ed 100644 --- a/azure/services/bastionhosts/bastionhosts.go +++ b/azure/services/bastionhosts/bastionhosts.go @@ -61,6 +61,8 @@ func (s *Service) Reconcile(ctx context.Context) error { var resultingErr error if bastionSpec := s.Scope.AzureBastionSpec(); bastionSpec != nil { _, resultingErr = s.CreateResource(ctx, bastionSpec, serviceName) + } else { + return nil } s.Scope.UpdatePutStatus(infrav1.BastionHostReadyCondition, serviceName, resultingErr) @@ -78,6 +80,8 @@ func (s *Service) Delete(ctx context.Context) error { var resultingErr error if bastionSpec := s.Scope.AzureBastionSpec(); bastionSpec != nil { resultingErr = s.DeleteResource(ctx, bastionSpec, serviceName) + } else { + return nil } s.Scope.UpdateDeleteStatus(infrav1.BastionHostReadyCondition, serviceName, resultingErr) diff --git a/azure/services/routetables/routetables.go b/azure/services/routetables/routetables.go index 0a7690529068..e48a2f41a9ed 100644 --- a/azure/services/routetables/routetables.go +++ b/azure/services/routetables/routetables.go @@ -63,11 +63,17 @@ func (s *Service) Reconcile(ctx context.Context) error { if !s.Scope.IsVnetManaged() { log.V(4).Info("Skipping route tables reconcile in custom vnet mode") + return nil } else { + specs := s.Scope.RouteTableSpecs() // We go through the list of route tables to reconcile each one, independently of the result of the previous one. + if len(specs) == 0 { + return nil + } + // If multiple errors occur, we return the most pressing one. - // Order of precedence (highest -> lowest) is: error that is not an operationNotDoneError (ie. error creating) -> operationNotDoneError (ie. creating in progress) -> no error (ie. created) - for _, rtSpec := range s.Scope.RouteTableSpecs() { + // Order of precedence (highest -> lowest) is: error that is not an operationNotDoneError (i.e. error creating) -> operationNotDoneError (i.e. creating in progress) -> no error (i.e. created) + for _, rtSpec := range specs { if _, err := s.CreateResource(ctx, rtSpec, serviceName); err != nil { if !azure.IsOperationNotDoneError(err) || resErr == nil { resErr = err @@ -94,12 +100,16 @@ func (s *Service) Delete(ctx context.Context) error { return nil } - var result error + specs := s.Scope.RouteTableSpecs() + if len(specs) == 0 { + return nil + } // We go through the list of RouteTableSpecs to delete each one, independently of the result of the previous one. - // If multiple erros occur, we return the most pressing one + // If multiple errors occur, we return the most pressing one // order of precedence is: error deleting -> deleting in progress -> deleted (no error) - for _, rtSpec := range s.Scope.RouteTableSpecs() { + var result error + for _, rtSpec := range specs { if err := s.DeleteResource(ctx, rtSpec, serviceName); err != nil { if !azure.IsOperationNotDoneError(err) || result == nil { result = err diff --git a/azure/services/virtualmachines/virtualmachines.go b/azure/services/virtualmachines/virtualmachines.go index cd771bdb1676..2457261eab23 100644 --- a/azure/services/virtualmachines/virtualmachines.go +++ b/azure/services/virtualmachines/virtualmachines.go @@ -84,9 +84,7 @@ func (s *Service) Reconcile(ctx context.Context) error { result, err := s.CreateResource(ctx, vmSpec, serviceName) s.Scope.UpdatePutStatus(infrav1.VMRunningCondition, serviceName, err) // Set the DiskReady condition here since the disk gets created with the VM. - if len(s.Scope.DiskSpecs()) > 0 { - s.Scope.UpdatePutStatus(infrav1.DisksReadyCondition, serviceName, err) - } + s.Scope.UpdatePutStatus(infrav1.DisksReadyCondition, serviceName, err) if err == nil && result != nil { vm, ok := result.(compute.VirtualMachine) if !ok {