Skip to content

Commit f2a205b

Browse files
committed
CAPI Azure: gather bootstrap through LB
The Azure bootstrap node cannot have a public IP address, as Azure does not allow a public IP when the VM is attached to a load balancer with an outbound rule. Instead, CAPZ creates an inbound nat rule to allow SSH access through the load balancer. This commit encapsulates the logic for gathering the bootstrap host address into its own function and adds a condition to use the API LB hostname when the bootstrap node cannot have a public ip. Fixes: OCPBUGS-37540
1 parent 3811fa0 commit f2a205b

File tree

1 file changed

+27
-13
lines changed

1 file changed

+27
-13
lines changed

pkg/infrastructure/clusterapi/clusterapi.go

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -482,22 +482,12 @@ func (i *InfraProvider) ExtractHostAddresses(dir string, config *types.InstallCo
482482
manifestsDir := filepath.Join(dir, clusterapi.ArtifactsDir)
483483
logrus.Debugf("Looking for machine manifests in %s", manifestsDir)
484484

485-
bootstrapFiles, err := filepath.Glob(filepath.Join(manifestsDir, "Machine\\-openshift\\-cluster\\-api\\-guests\\-*\\-bootstrap.yaml"))
486-
if err != nil {
487-
return fmt.Errorf("failed to list bootstrap manifests: %w", err)
488-
}
489-
logrus.Debugf("bootstrap manifests found: %v", bootstrapFiles)
490-
491-
if len(bootstrapFiles) != 1 {
492-
return fmt.Errorf("wrong number of bootstrap manifests found: %v. Expected exactly one", bootstrapFiles)
493-
}
494-
addrs, err := extractIPAddress(bootstrapFiles[0])
485+
addr, err := i.getBootstrapAddress(config, manifestsDir)
495486
if err != nil {
496-
return fmt.Errorf("failed to extract IP address for bootstrap: %w", err)
487+
return fmt.Errorf("failed to get bootstrap address: %w", err)
497488
}
498-
logrus.Debugf("found bootstrap address: %s", addrs)
489+
ha.Bootstrap = addr
499490

500-
ha.Bootstrap = prioritizeIPv4(config, addrs)
501491
masterFiles, err := filepath.Glob(filepath.Join(manifestsDir, "Machine\\-openshift\\-cluster\\-api\\-guests\\-*\\-master\\-?.yaml"))
502492
if err != nil {
503493
return fmt.Errorf("failed to list master machine manifests: %w", err)
@@ -522,6 +512,30 @@ func (i *InfraProvider) ExtractHostAddresses(dir string, config *types.InstallCo
522512
return nil
523513
}
524514

515+
func (i *InfraProvider) getBootstrapAddress(config *types.InstallConfig, manifestsDir string) (string, error) {
516+
// If the bootstrap node cannot have a public IP address, we
517+
// SSH through the load balancer, as is this case on Azure.
518+
if i.impl.PublicGatherEndpoint() == APILoadBalancer && config.Publish != types.InternalPublishingStrategy {
519+
return fmt.Sprintf("api.%s", config.ClusterDomain()), nil
520+
}
521+
522+
bootstrapFiles, err := filepath.Glob(filepath.Join(manifestsDir, "Machine\\-openshift\\-cluster\\-api\\-guests\\-*\\-bootstrap.yaml"))
523+
if err != nil {
524+
return "", fmt.Errorf("failed to list bootstrap manifests: %w", err)
525+
}
526+
logrus.Debugf("bootstrap manifests found: %v", bootstrapFiles)
527+
528+
if len(bootstrapFiles) != 1 {
529+
return "", fmt.Errorf("wrong number of bootstrap manifests found: %v. Expected exactly one", bootstrapFiles)
530+
}
531+
addrs, err := extractIPAddress(bootstrapFiles[0])
532+
if err != nil {
533+
return "", fmt.Errorf("failed to extract IP address for bootstrap: %w", err)
534+
}
535+
logrus.Debugf("found bootstrap address: %s", addrs)
536+
return prioritizeIPv4(config, addrs), nil
537+
}
538+
525539
// IgnitionSecret provides the basic formatting for creating the
526540
// ignition secret.
527541
func IgnitionSecret(ign []byte, infraID, role string) *corev1.Secret {

0 commit comments

Comments
 (0)