@@ -15,6 +15,7 @@ import (
1515 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1616 utilerrors "k8s.io/apimachinery/pkg/util/errors"
1717 "k8s.io/apimachinery/pkg/util/wait"
18+ "k8s.io/utils/ptr"
1819 clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
1920 utilkubeconfig "sigs.k8s.io/cluster-api/util/kubeconfig"
2021 "sigs.k8s.io/controller-runtime/pkg/client"
@@ -269,36 +270,39 @@ func (i *InfraProvider) Provision(ctx context.Context, dir string, parents asset
269270 masterIgnSecret := IgnitionSecret (masterIgnAsset .Files ()[0 ].Data , clusterID .InfraID , "master" )
270271 machineManifests = append (machineManifests , bootstrapIgnSecret , masterIgnSecret )
271272
272- timer .StartTimer (machineStage )
273273 // Create the machine manifests.
274+ timer .StartTimer (machineStage )
275+ machineNames := []string {}
276+
274277 for _ , m := range machineManifests {
275278 m .SetNamespace (capiutils .Namespace )
276279 if err := cl .Create (ctx , m ); err != nil {
277280 return fileList , fmt .Errorf ("failed to create control-plane manifest: %w" , err )
278281 }
279282 i .appliedManifests = append (i .appliedManifests , m )
283+
284+ if machine , ok := m .(* clusterv1.Machine ); ok {
285+ machineNames = append (machineNames , machine .Name )
286+ }
280287 logrus .Infof ("Created manifest %+T, namespace=%s name=%s" , m , m .GetNamespace (), m .GetName ())
281288 }
282289
283290 {
284- masterCount := int64 (1 )
285- if reps := installConfig .Config .ControlPlane .Replicas ; reps != nil {
286- masterCount = * reps
287- }
288-
289291 untilTime := time .Now ().Add (timeout )
290292 timezone , _ := untilTime .Zone ()
291- logrus .Infof ("Waiting up to %v (until %v %s) for machines to provision..." , timeout , untilTime .Format (time .Kitchen ), timezone )
293+ reqBootstrapPubIP := installConfig .Config .Publish == types .ExternalPublishingStrategy && i .impl .BootstrapHasPublicIP ()
294+ logrus .Infof ("Waiting up to %v (until %v %s) for machines %v to provision..." , timeout , untilTime .Format (time .Kitchen ), timezone , machineNames )
292295 if err := wait .ExponentialBackoffWithContext (ctx , wait.Backoff {
293296 Duration : time .Second * 10 ,
294297 Factor : float64 (1.5 ),
295298 Steps : 32 ,
296299 Cap : timeout ,
297300 }, func (ctx context.Context ) (bool , error ) {
298- for i := int64 (0 ); i < masterCount ; i ++ {
301+ allReady := true
302+ for _ , machineName := range machineNames {
299303 machine := & clusterv1.Machine {}
300304 if err := cl .Get (ctx , client.ObjectKey {
301- Name : fmt . Sprintf ( "%s-%s-%d" , clusterID . InfraID , "master" , i ) ,
305+ Name : machineName ,
302306 Namespace : capiutils .Namespace ,
303307 }, machine ); err != nil {
304308 if apierrors .IsNotFound (err ) {
@@ -307,15 +311,18 @@ func (i *InfraProvider) Provision(ctx context.Context, dir string, parents asset
307311 }
308312 return false , err
309313 }
310- if machine .Status .Phase != string (clusterv1 .MachinePhaseProvisioned ) &&
311- machine .Status .Phase != string (clusterv1 .MachinePhaseRunning ) {
312- return false , nil
313- } else if machine .Status .Phase == string (clusterv1 .MachinePhaseFailed ) {
314- return false , fmt .Errorf ("machine %s failed to provision: %q" , machine .Name , * machine .Status .FailureMessage )
314+ reqPubIP := reqBootstrapPubIP && machineName == capiutils .GenerateBoostrapMachineName (clusterID .InfraID )
315+ ready , err := checkMachineReady (machine , reqPubIP )
316+ if err != nil {
317+ return false , fmt .Errorf ("failed waiting for machines: %w" , err )
318+ }
319+ if ! ready {
320+ allReady = false
321+ } else {
322+ logrus .Debugf ("Machine %s is ready. Phase: %s" , machine .Name , machine .Status .Phase )
315323 }
316- logrus .Debugf ("Machine %s is ready. Phase: %s" , machine .Name , machine .Status .Phase )
317324 }
318- return true , nil
325+ return allReady , nil
319326 }); err != nil {
320327 if wait .Interrupted (err ) {
321328 return fileList , fmt .Errorf ("control-plane machines were not provisioned within %v: %w" , timeout , err )
@@ -550,3 +557,37 @@ func (i *InfraProvider) collectManifests(ctx context.Context, cl client.Client)
550557 }
551558 return fileList , errorList
552559}
560+
561+ func checkMachineReady (machine * clusterv1.Machine , requirePublicIP bool ) (bool , error ) {
562+ logrus .Debugf ("Checking that machine %s has provisioned..." , machine .Name )
563+ if machine .Status .Phase != string (clusterv1 .MachinePhaseProvisioned ) &&
564+ machine .Status .Phase != string (clusterv1 .MachinePhaseRunning ) {
565+ logrus .Debugf ("Machine %s has not yet provisioned: %s" , machine .Name , machine .Status .Phase )
566+ return false , nil
567+ } else if machine .Status .Phase == string (clusterv1 .MachinePhaseFailed ) {
568+ msg := ptr .Deref (machine .Status .FailureMessage , "machine.Status.FailureMessage was not set" )
569+ return false , fmt .Errorf ("machine %s failed to provision: %s" , machine .Name , msg )
570+ }
571+ logrus .Debugf ("Machine %s has status: %s" , machine .Name , machine .Status .Phase )
572+ return hasRequiredIP (machine , requirePublicIP ), nil
573+ }
574+
575+ func hasRequiredIP (machine * clusterv1.Machine , requirePublicIP bool ) bool {
576+ logrus .Debugf ("Checking that IP addresses are populated in the status of machine %s..." , machine .Name )
577+
578+ for _ , addr := range machine .Status .Addresses {
579+ switch {
580+ case len (addr .Address ) == 0 :
581+ continue
582+ case addr .Type == clusterv1 .MachineExternalIP :
583+ logrus .Debugf ("Found external IP address: %s" , addr .Address )
584+ return true
585+ case addr .Type == clusterv1 .MachineInternalIP && ! requirePublicIP :
586+ logrus .Debugf ("Found internal IP address: %s" , addr .Address )
587+ return true
588+ }
589+ logrus .Debugf ("Checked IP %s: %s" , addr .Type , addr .Address )
590+ }
591+ logrus .Debugf ("Still waiting for machine %s to get required IPs" , machine .Name )
592+ return false
593+ }
0 commit comments