Skip to content

Commit

Permalink
Add check for if scaleset exists first before fetching instances
Browse files Browse the repository at this point in the history
  • Loading branch information
Jont828 committed Jul 17, 2023
1 parent 14f0baf commit d351197
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions azure/services/scalesets/scalesets.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,19 +91,22 @@ func (s *Service) Reconcile(ctx context.Context) (retErr error) {
var resultErr error

spec := s.Scope.ScaleSetSpec(ctx)

vmssInstances, err := s.Client.ListInstances(ctx, spec.ResourceGroupName(), spec.ResourceName())
if err != nil {
resultErr = errors.Wrapf(err, "failed to get existing instances")
s.Scope.UpdatePutStatus(infrav1.BootstrapSucceededCondition, serviceName, resultErr)
return resultErr
}

scaleSetSpec, ok := spec.(*ScaleSetSpec)
if !ok {
return errors.Errorf("%T is not of type ScaleSetSpec", spec)
}
scaleSetSpec.VMSSInstances = vmssInstances

_, err = s.Client.Get(ctx, spec)
if err == nil {
scaleSetSpec.VMSSInstances, err = s.Client.ListInstances(ctx, spec.ResourceGroupName(), spec.ResourceName())
if err != nil {
resultErr = errors.Wrapf(err, "failed to get existing instances")
s.Scope.UpdatePutStatus(infrav1.BootstrapSucceededCondition, serviceName, resultErr)
return resultErr
}
} else if !azure.ResourceNotFound(err) {
return errors.Wrapf(err, "failed to get existing VMSS")
}

result, err := s.CreateOrUpdateResource(ctx, scaleSetSpec, serviceName)
s.Scope.UpdatePutStatus(infrav1.BootstrapSucceededCondition, serviceName, err)
Expand All @@ -114,7 +117,7 @@ func (s *Service) Reconcile(ctx context.Context) (retErr error) {
return errors.Errorf("%T is not a compute.VirtualMachineScaleSet", result)
}

fetchedVMSS := converters.SDKToVMSS(vmss, vmssInstances)
fetchedVMSS := converters.SDKToVMSS(vmss, scaleSetSpec.VMSSInstances)
// Note: converters.SDKToVMSS() will never return nil but we should check anyway
if fetchedVMSS != nil {
if err := s.Scope.ReconcileReplicas(ctx, fetchedVMSS); err != nil {
Expand Down

0 comments on commit d351197

Please sign in to comment.