Skip to content

Commit 642bf15

Browse files
Merge pull request openshift#8812 from patrickdillon/capi-gather-interface
OCPBUGS-37540: Gather Azure Logs through load balancer
2 parents 1264c98 + f2a205b commit 642bf15

File tree

10 files changed

+75
-43
lines changed

10 files changed

+75
-43
lines changed

pkg/infrastructure/aws/clusterapi/aws.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,9 @@ type Provider struct {
4646
// Name gives the name of the provider, AWS.
4747
func (*Provider) Name() string { return awstypes.Name }
4848

49-
// BootstrapHasPublicIP indicates that machine ready checks
50-
// should wait for an ExternalIP in the status.
51-
func (*Provider) BootstrapHasPublicIP() bool { return true }
49+
// PublicGatherEndpoint indicates that machine ready checks should wait for an ExternalIP
50+
// in the status and use that when gathering bootstrap log bundles.
51+
func (*Provider) PublicGatherEndpoint() clusterapi.GatherEndpoint { return clusterapi.ExternalIP }
5252

5353
// PreProvision creates the IAM roles used by all nodes in the cluster.
5454
func (*Provider) PreProvision(ctx context.Context, in clusterapi.PreProvisionInput) error {

pkg/infrastructure/azure/azure.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,9 @@ func (p *Provider) Name() string {
6767
return aztypes.Name
6868
}
6969

70-
// BootstrapHasPublicIP indicates that an ExternalIP is not
71-
// required in the machine ready checks.
72-
func (*Provider) BootstrapHasPublicIP() bool { return false }
70+
// PublicGatherEndpoint indicates that machine ready checks should NOT wait for an ExternalIP
71+
// in the status and should use the API load balancer when gathering bootstrap log bundles.
72+
func (*Provider) PublicGatherEndpoint() clusterapi.GatherEndpoint { return clusterapi.APILoadBalancer }
7373

7474
// PreProvision is called before provisioning using CAPI controllers has begun.
7575
func (p *Provider) PreProvision(ctx context.Context, in clusterapi.PreProvisionInput) error {

pkg/infrastructure/clusterapi/clusterapi.go

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ func (i *InfraProvider) Provision(ctx context.Context, dir string, parents asset
325325
{
326326
untilTime := time.Now().Add(provisionTimeout)
327327
timezone, _ := untilTime.Zone()
328-
reqBootstrapPubIP := installConfig.Config.Publish == types.ExternalPublishingStrategy && i.impl.BootstrapHasPublicIP()
328+
reqBootstrapPubIP := installConfig.Config.Publish == types.ExternalPublishingStrategy && i.impl.PublicGatherEndpoint() == ExternalIP
329329
logrus.Infof("Waiting up to %v (until %v %s) for machines %v to provision...", provisionTimeout, untilTime.Format(time.Kitchen), timezone, machineNames)
330330
if err := wait.PollUntilContextTimeout(ctx, 15*time.Second, provisionTimeout, true,
331331
func(ctx context.Context) (bool, error) {
@@ -504,22 +504,12 @@ func (i *InfraProvider) ExtractHostAddresses(dir string, config *types.InstallCo
504504
manifestsDir := filepath.Join(dir, clusterapi.ArtifactsDir)
505505
logrus.Debugf("Looking for machine manifests in %s", manifestsDir)
506506

507-
bootstrapFiles, err := filepath.Glob(filepath.Join(manifestsDir, "Machine\\-openshift\\-cluster\\-api\\-guests\\-*\\-bootstrap.yaml"))
508-
if err != nil {
509-
return fmt.Errorf("failed to list bootstrap manifests: %w", err)
510-
}
511-
logrus.Debugf("bootstrap manifests found: %v", bootstrapFiles)
512-
513-
if len(bootstrapFiles) != 1 {
514-
return fmt.Errorf("wrong number of bootstrap manifests found: %v. Expected exactly one", bootstrapFiles)
515-
}
516-
addrs, err := extractIPAddress(bootstrapFiles[0])
507+
addr, err := i.getBootstrapAddress(config, manifestsDir)
517508
if err != nil {
518-
return fmt.Errorf("failed to extract IP address for bootstrap: %w", err)
509+
return fmt.Errorf("failed to get bootstrap address: %w", err)
519510
}
520-
logrus.Debugf("found bootstrap address: %s", addrs)
511+
ha.Bootstrap = addr
521512

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

537+
func (i *InfraProvider) getBootstrapAddress(config *types.InstallConfig, manifestsDir string) (string, error) {
538+
// If the bootstrap node cannot have a public IP address, we
539+
// SSH through the load balancer, as is this case on Azure.
540+
if i.impl.PublicGatherEndpoint() == APILoadBalancer && config.Publish != types.InternalPublishingStrategy {
541+
return fmt.Sprintf("api.%s", config.ClusterDomain()), nil
542+
}
543+
544+
bootstrapFiles, err := filepath.Glob(filepath.Join(manifestsDir, "Machine\\-openshift\\-cluster\\-api\\-guests\\-*\\-bootstrap.yaml"))
545+
if err != nil {
546+
return "", fmt.Errorf("failed to list bootstrap manifests: %w", err)
547+
}
548+
logrus.Debugf("bootstrap manifests found: %v", bootstrapFiles)
549+
550+
if len(bootstrapFiles) != 1 {
551+
return "", fmt.Errorf("wrong number of bootstrap manifests found: %v. Expected exactly one", bootstrapFiles)
552+
}
553+
addrs, err := extractIPAddress(bootstrapFiles[0])
554+
if err != nil {
555+
return "", fmt.Errorf("failed to extract IP address for bootstrap: %w", err)
556+
}
557+
logrus.Debugf("found bootstrap address: %s", addrs)
558+
return prioritizeIPv4(config, addrs), nil
559+
}
560+
547561
// IgnitionSecret provides the basic formatting for creating the
548562
// ignition secret.
549563
func IgnitionSecret(ign []byte, infraID, role string) *corev1.Secret {

pkg/infrastructure/clusterapi/types.go

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,14 @@ type Provider interface {
2020
// Name provides the name for the cloud platform.
2121
Name() string
2222

23-
// BootstrapHasPublicIP indicates whether a public IP address
24-
// is expected on the bootstrap node in a public cluster.
25-
// When BootstrapHasPublicIP returns true, the machine ready checks
26-
// wait for an ExternalIP address to be populated in the machine status.
27-
BootstrapHasPublicIP() bool
23+
// PublicGatherEndpoint returns how the cloud platform expects the installer
24+
// to connect to the bootstrap node for log gathering. CAPI providers are not
25+
// consistent in how public IP addresses are represented in the machine status.
26+
// Furthermore, Azure cannot attach a public IP to the bootstrap node, so SSH
27+
// must be performed through the API load balancer.
28+
// When a platform returns ExternalIP, the installer will require an ExternalIP
29+
// to be present in the status, before it declares the machine ready.
30+
PublicGatherEndpoint() GatherEndpoint
2831
}
2932

3033
// PreProvider defines the PreProvision hook, which is called prior to
@@ -126,3 +129,18 @@ type Timeouts interface {
126129
// When waiting for the machines to provision.
127130
ProvisionTimeout() time.Duration
128131
}
132+
133+
// GatherEndpoint represents the valid values for connecting to the bootstrap nude
134+
// in a public cluster to gather logs.
135+
type GatherEndpoint string
136+
137+
const (
138+
// ExternalIP indicates that the machine status will include an ExternalIP that can be used for gather.
139+
ExternalIP GatherEndpoint = "ExternalIP"
140+
141+
// InternalIP indicates that the machine status will only include InternalIPs.
142+
InternalIP GatherEndpoint = "InternalIP"
143+
144+
// APILoadBalancer indicates that gather bootstrap should connect to the API load balancer.
145+
APILoadBalancer GatherEndpoint = "APILoadBalancer"
146+
)

pkg/infrastructure/gcp/clusterapi/clusterapi.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@ func (p Provider) Name() string {
3737
return gcptypes.Name
3838
}
3939

40-
// BootstrapHasPublicIP indicates that machine ready checks
41-
// should wait for an ExternalIP in the status.
42-
func (Provider) BootstrapHasPublicIP() bool { return true }
40+
// PublicGatherEndpoint indicates that machine ready checks should wait for an ExternalIP
41+
// in the status and use that when gathering bootstrap log bundles.
42+
func (Provider) PublicGatherEndpoint() clusterapi.GatherEndpoint { return clusterapi.ExternalIP }
4343

4444
// PreProvision is called before provisioning using CAPI controllers has initiated.
4545
// GCP resources that are not created by CAPG (and are required for other stages of the install) are

pkg/infrastructure/ibmcloud/clusterapi/clusterapi.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ func (p Provider) Name() string {
1818
return ibmcloudtypes.Name
1919
}
2020

21-
// BootstrapHasPublicIP indicates that an ExternalIP is not
22-
// required in the machine ready checks.
23-
func (Provider) BootstrapHasPublicIP() bool { return false }
21+
// PublicGatherEndpoint indicates that machine ready checks should NOT wait for an ExternalIP
22+
// in the status when declaring machines ready.
23+
func (Provider) PublicGatherEndpoint() clusterapi.GatherEndpoint { return clusterapi.InternalIP }
2424

2525
// PreProvision creates the IBM Cloud objects required prior to running capibmcloud.
2626
func (p Provider) PreProvision(ctx context.Context, in clusterapi.PreProvisionInput) error {

pkg/infrastructure/nutanix/clusterapi/clusterapi.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ func (p Provider) Name() string {
2626
return nutanixtypes.Name
2727
}
2828

29-
// BootstrapHasPublicIP indicates that an ExternalIP is not
30-
// required in the machine ready checks.
31-
func (Provider) BootstrapHasPublicIP() bool { return false }
29+
// PublicGatherEndpoint indicates that machine ready checks should NOT wait for an ExternalIP
30+
// in the status when declaring machines ready.
31+
func (Provider) PublicGatherEndpoint() infracapi.GatherEndpoint { return infracapi.InternalIP }
3232

3333
// PreProvision creates the resources required prior to running capi nutanix controller.
3434
func (p Provider) PreProvision(ctx context.Context, in infracapi.PreProvisionInput) error {

pkg/infrastructure/openstack/clusterapi/clusterapi.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ func (p Provider) Name() string {
3131
return openstack.Name
3232
}
3333

34-
// BootstrapHasPublicIP indicates that an ExternalIP is not
35-
// required in the machine ready checks.
36-
func (Provider) BootstrapHasPublicIP() bool { return false }
34+
// PublicGatherEndpoint indicates that machine ready checks should NOT wait for an ExternalIP
35+
// in the status when declaring machines ready.
36+
func (Provider) PublicGatherEndpoint() clusterapi.GatherEndpoint { return clusterapi.InternalIP }
3737

3838
var _ clusterapi.PreProvider = Provider{}
3939

pkg/infrastructure/powervs/clusterapi/powervs.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@ func (p Provider) Name() string {
3939
return powervstypes.Name
4040
}
4141

42-
// BootstrapHasPublicIP indicates that an ExternalIP is not
43-
// required in the machine ready checks.
44-
func (Provider) BootstrapHasPublicIP() bool { return false }
42+
// PublicGatherEndpoint indicates that machine ready checks should NOT wait for an ExternalIP
43+
// in the status when declaring machines ready.
44+
func (Provider) PublicGatherEndpoint() clusterapi.GatherEndpoint { return clusterapi.InternalIP }
4545

4646
func leftInContext(ctx context.Context) time.Duration {
4747
deadline, ok := ctx.Deadline()

pkg/infrastructure/vsphere/clusterapi/clusterapi.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ func (p Provider) Name() string {
2828
return vsphere.Name
2929
}
3030

31-
// BootstrapHasPublicIP indicates that an ExternalIP is not
32-
// required in the machine ready checks.
33-
func (Provider) BootstrapHasPublicIP() bool { return false }
31+
// PublicGatherEndpoint indicates that machine ready checks should NOT wait for an ExternalIP
32+
// in the status when declaring machines ready.
33+
func (Provider) PublicGatherEndpoint() clusterapi.GatherEndpoint { return clusterapi.InternalIP }
3434

3535
func initializeFoldersAndTemplates(ctx context.Context, cachedImage string, failureDomain vsphere.FailureDomain, session *session.Session, diskType vsphere.DiskType, clusterID, tagID string) error {
3636
finder := session.Finder

0 commit comments

Comments
 (0)