@@ -448,32 +448,33 @@ type machineManifest struct {
448448// extractIPAddress extracts the IP address from a machine manifest file in a
449449// provider-agnostic way by reading only the "status" stanza, which should be
450450// present in all providers.
451- func extractIPAddress (manifestPath string ) (string , error ) {
451+ func extractIPAddress (manifestPath string ) ([] string , error ) {
452452 data , err := os .ReadFile (manifestPath )
453453 if err != nil {
454- return "" , fmt .Errorf ("failed to read machine manifest %s: %w" , manifestPath , err )
454+ return [] string {} , fmt .Errorf ("failed to read machine manifest %s: %w" , manifestPath , err )
455455 }
456456 var manifest machineManifest
457457 if err := yaml .Unmarshal (data , & manifest ); err != nil {
458- return "" , fmt .Errorf ("failed to unmarshal manifest %s: %w" , manifestPath , err )
458+ return [] string {} , fmt .Errorf ("failed to unmarshal manifest %s: %w" , manifestPath , err )
459459 }
460460
461- var ipAddr string
461+ var externalIPAddrs []string
462+ var internalIPAddrs []string
462463 for _ , addr := range manifest .Status .Addresses {
463464 switch addr .Type {
464465 case clusterv1 .MachineExternalIP :
465- ipAddr = addr .Address
466+ externalIPAddrs = append ( externalIPAddrs , addr .Address )
466467 case clusterv1 .MachineInternalIP :
467- // Prefer external IP when present
468- if len (ipAddr ) == 0 {
469- ipAddr = addr .Address
470- }
468+ internalIPAddrs = append (internalIPAddrs , addr .Address )
471469 default :
472470 continue
473471 }
474472 }
475473
476- return ipAddr , nil
474+ // prioritize the external address in the front of the list
475+ externalIPAddrs = append (externalIPAddrs , internalIPAddrs ... )
476+
477+ return externalIPAddrs , nil
477478}
478479
479480// ExtractHostAddresses extracts the IPs of the bootstrap and control plane machines.
@@ -490,13 +491,13 @@ func (i *InfraProvider) ExtractHostAddresses(dir string, config *types.InstallCo
490491 if len (bootstrapFiles ) != 1 {
491492 return fmt .Errorf ("wrong number of bootstrap manifests found: %v. Expected exactly one" , bootstrapFiles )
492493 }
493- addr , err := extractIPAddress (bootstrapFiles [0 ])
494+ addrs , err := extractIPAddress (bootstrapFiles [0 ])
494495 if err != nil {
495496 return fmt .Errorf ("failed to extract IP address for bootstrap: %w" , err )
496497 }
497- logrus .Debugf ("found bootstrap address: %s" , addr )
498- ha .Bootstrap = addr
498+ logrus .Debugf ("found bootstrap address: %s" , addrs )
499499
500+ ha .Bootstrap = prioritizeIPv4 (config , addrs )
500501 masterFiles , err := filepath .Glob (filepath .Join (manifestsDir , "Machine\\ -openshift\\ -cluster\\ -api\\ -guests\\ -*\\ -master\\ -?.yaml" ))
501502 if err != nil {
502503 return fmt .Errorf ("failed to list master machine manifests: %w" , err )
@@ -507,14 +508,15 @@ func (i *InfraProvider) ExtractHostAddresses(dir string, config *types.InstallCo
507508 logrus .Warnf ("not all master manifests found: %d. Expected %d." , len (masterFiles ), replicas )
508509 }
509510 for _ , manifest := range masterFiles {
510- addr , err := extractIPAddress (manifest )
511+ addrs , err := extractIPAddress (manifest )
511512 if err != nil {
512513 // Log the error but keep parsing the remaining files
513514 logrus .Warnf ("failed to extract IP address for %s: %v" , manifest , err )
514515 continue
515516 }
516- logrus .Debugf ("found master address: %s" , addr )
517- ha .Masters = append (ha .Masters , addr )
517+ logrus .Debugf ("found master address: %s" , addrs )
518+
519+ ha .Masters = append (ha .Masters , prioritizeIPv4 (config , addrs ))
518520 }
519521
520522 return nil
0 commit comments