Skip to content

Commit 4971b30

Browse files
Merge pull request openshift#8759 from jcpowermac/OCPBUGS-37427
OCPBUGS-37427: bootstrap gather fails in vsphere, only ipv6 address used
2 parents 81fb9eb + 1ab6f6c commit 4971b30

File tree

2 files changed

+37
-16
lines changed

2 files changed

+37
-16
lines changed

pkg/infrastructure/clusterapi/clusterapi.go

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -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

pkg/infrastructure/clusterapi/helpers.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@ package clusterapi
33
import (
44
"encoding/json"
55
"fmt"
6+
"net"
67

78
igntypes "github.com/coreos/ignition/v2/config/v3_2/types"
89

910
"github.com/openshift/installer/pkg/asset/ignition"
1011
"github.com/openshift/installer/pkg/asset/openshiftinstall"
12+
"github.com/openshift/installer/pkg/types"
1113
)
1214

1315
// injectInstallInfo adds information about the installer and its invoker as a
@@ -32,3 +34,20 @@ func injectInstallInfo(bootstrap []byte) ([]byte, error) {
3234

3335
return ign, nil
3436
}
37+
38+
func prioritizeIPv4(config *types.InstallConfig, addresses []string) string {
39+
if len(addresses) == 0 {
40+
return ""
41+
}
42+
43+
if config.Platform.Name() == "vsphere" {
44+
for _, a := range addresses {
45+
ip := net.ParseIP(a)
46+
if ip.To4() != nil {
47+
return a
48+
}
49+
}
50+
}
51+
52+
return addresses[0]
53+
}

0 commit comments

Comments
 (0)