Skip to content

Commit

Permalink
Add availability sets, bastion hosts, and route tables
Browse files Browse the repository at this point in the history
  • Loading branch information
Jont828 committed Feb 15, 2022
1 parent 8775b18 commit e6c42de
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 11 deletions.
2 changes: 2 additions & 0 deletions azure/services/availabilitysets/availabilitysets.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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 {
Expand Down
4 changes: 4 additions & 0 deletions azure/services/bastionhosts/bastionhosts.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down
3 changes: 0 additions & 3 deletions azure/services/inboundnatrules/inboundnatrules.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,6 @@ func (s *Service) Reconcile(ctx context.Context) error {
// Externally managed clusters might not have an LB
if s.Scope.APIServerLBName() == "" {
log.V(4).Info("Skipping InboundNatRule reconciliation as the cluster has no LB configured")
// Until https://github.com/kubernetes-sigs/cluster-api-provider-azure/issues/1868 is
// resolved, this needs to be set for the machine to be able to reach the ready condition:
// https://github.com/kubernetes-sigs/cluster-api-provider-azure/pull/2066#discussion_r806150004
return nil
}

Expand Down
20 changes: 15 additions & 5 deletions azure/services/routetables/routetables.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
4 changes: 1 addition & 3 deletions azure/services/virtualmachines/virtualmachines.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit e6c42de

Please sign in to comment.