@@ -27,6 +27,7 @@ import (
27
27
28
28
"github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2021-11-01/compute"
29
29
"github.com/Azure/go-autorest/autorest"
30
+ autorestazure "github.com/Azure/go-autorest/autorest/azure"
30
31
machinev1 "github.com/openshift/api/machine/v1beta1"
31
32
machinecontroller "github.com/openshift/machine-api-operator/pkg/controller/machine"
32
33
"github.com/openshift/machine-api-operator/pkg/metrics"
@@ -139,6 +140,13 @@ func (s *Reconciler) CreateMachine(ctx context.Context) error {
139
140
return fmt .Errorf ("failed to create vm %s: %w" , s .scope .Machine .Name , err )
140
141
}
141
142
143
+ // Once we have created the machine, attempt to update it.
144
+ // This should set the network addresses and provider ID which should be set as soon
145
+ // as the machine is created, moving it to the provisioned phase.
146
+ if err := s .Update (ctx ); err != nil {
147
+ return fmt .Errorf ("failed to update machine %s: %w" , s .scope .Machine .Name , err )
148
+ }
149
+
142
150
return nil
143
151
}
144
152
@@ -700,8 +708,8 @@ func (s *Reconciler) createVirtualMachine(ctx context.Context, nicName, asName s
700
708
vmSpec .CustomData = userData
701
709
}
702
710
703
- err = s . virtualMachinesSvc . CreateOrUpdate ( ctx , vmSpec )
704
- if err != nil {
711
+ // If we get an AsynOpIncompleteError, this means the VM is being created and we completed the request successfully.
712
+ if err := s . virtualMachinesSvc . CreateOrUpdate ( ctx , vmSpec ); err != nil && ! errors . Is ( err , autorestazure . NewAsyncOpIncompleteError ( "compute.VirtualMachinesCreateOrUpdateFuture" )) {
705
713
metrics .RegisterFailedInstanceCreate (& metrics.MachineLabels {
706
714
Name : s .scope .Machine .Name ,
707
715
Namespace : s .scope .Machine .Namespace ,
@@ -712,6 +720,7 @@ func (s *Reconciler) createVirtualMachine(ctx context.Context, nicName, asName s
712
720
if errors .As (err , & detailedError ) && detailedError .Message == "Failure sending request" {
713
721
return machinecontroller .InvalidMachineConfiguration ("failure sending request for machine %s: %v" , s .scope .Machine .Name , err )
714
722
}
723
+
715
724
return fmt .Errorf ("failed to create VM: %w" , err )
716
725
}
717
726
} else if err != nil {
0 commit comments