Skip to content

Commit

Permalink
Refactor bootstrap succeeded condition in VM extension
Browse files Browse the repository at this point in the history
  • Loading branch information
Jont828 committed Apr 5, 2022
1 parent 05653ab commit e309bbb
Showing 1 changed file with 9 additions and 16 deletions.
25 changes: 9 additions & 16 deletions azure/services/vmextensions/vmextensions.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,8 @@ package vmextensions
import (
"context"

"github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2021-04-01/compute"
"github.com/Azure/go-autorest/autorest/to"
"github.com/pkg/errors"
infrav1 "sigs.k8s.io/cluster-api-provider-azure/api/v1beta1"
"sigs.k8s.io/cluster-api-provider-azure/azure"
"sigs.k8s.io/cluster-api-provider-azure/azure/services/async"
"sigs.k8s.io/cluster-api-provider-azure/util/reconciler"
Expand All @@ -34,9 +33,7 @@ const serviceName = "vmextensions"
type VMExtensionScope interface {
azure.Authorizer
azure.AsyncStatusUpdater
azure.ClusterDescriber
VMExtensionSpecs() []azure.ResourceSpecGetter
SetBootstrapConditions(context.Context, string, string) error
}

// Service provides operations on Azure resources.
Expand Down Expand Up @@ -77,25 +74,21 @@ func (s *Service) Reconcile(ctx context.Context) error {
// 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)
var resultErr error
for _, extensionSpec := range specs {
result, err := s.CreateResource(ctx, extensionSpec, serviceName)
_, err := s.CreateResource(ctx, extensionSpec, serviceName)
if err != nil {
if !azure.IsOperationNotDoneError(err) || resultErr == nil {
resultErr = err
}
} else {
vmextension, ok := result.(compute.VirtualMachineExtension)
if !ok {
return errors.Errorf("%T is not a compute.VirtualMachineExtension", result)
}

// check the extension status and set the associated conditions.
if retErr := s.Scope.SetBootstrapConditions(ctx, to.String(vmextension.ProvisioningState), extensionSpec.ResourceName()); retErr != nil {
// TODO: what precedence should this error have?
return retErr
}
}
}

if azure.IsOperationNotDoneError(resultErr) {
resultErr = errors.Wrapf(resultErr, "extension is still in provisioning state. This likely means that bootstrapping has not yet completed on the VM")
} else if resultErr != nil {
resultErr = errors.Wrapf(resultErr, "extension state failed. This likely means the Kubernetes node bootstrapping process failed or timed out. Check VM boot diagnostics logs to learn more")
}

s.Scope.UpdatePutStatus(infrav1.BootstrapSucceededCondition, serviceName, resultErr)
return resultErr
}

Expand Down

0 comments on commit e309bbb

Please sign in to comment.