Skip to content

Commit 8002370

Browse files
committed
Power VS: Configure load balancers for the private scenario
1 parent 7dd2fbc commit 8002370

File tree

2 files changed

+67
-36
lines changed

2 files changed

+67
-36
lines changed

pkg/asset/manifests/cloudproviderconfig.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,18 @@ func (cpc *CloudProviderConfig) Generate(dependencies asset.Parents) error {
253253
vpcSubnets := installConfig.Config.PowerVS.VPCSubnets
254254
if vpc == "" {
255255
vpc = fmt.Sprintf("vpc-%s", clusterID.InfraID)
256+
} else {
257+
existingSubnets, err := installConfig.PowerVS.GetVPCSubnets(context.TODO(), vpc)
258+
if err != nil {
259+
return err
260+
}
261+
262+
// cluster-api-provider-ibm requires any existing VPC subnet to be specified in the cluster
263+
// manifest and as such we need to also specify these in the cloudproviderconfig.
264+
// @TODO: Deprecate platform.powervs.vpcSubnets?
265+
for _, subnet := range existingSubnets {
266+
vpcSubnets = append(vpcSubnets, *subnet.Name)
267+
}
256268
}
257269

258270
if len(vpcSubnets) == 0 {

pkg/infrastructure/powervs/clusterapi/powervs.go

Lines changed: 55 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
powervsconfig "github.com/openshift/installer/pkg/asset/installconfig/powervs"
2222
"github.com/openshift/installer/pkg/asset/manifests/capiutils"
2323
"github.com/openshift/installer/pkg/infrastructure/clusterapi"
24+
"github.com/openshift/installer/pkg/types"
2425
powervstypes "github.com/openshift/installer/pkg/types/powervs"
2526
)
2627

@@ -49,9 +50,13 @@ func leftInContext(ctx context.Context) time.Duration {
4950
return duration
5051
}
5152

53+
const privatePrefix = "api-int."
54+
const publicPrefix = "api."
55+
5256
// InfraReady is called once cluster.Status.InfrastructureReady
5357
// is true, typically after load balancers have been provisioned. It can be used
5458
// to create DNS records.
59+
// nolint:gocyclo
5560
func (p Provider) InfraReady(ctx context.Context, in clusterapi.InfraReadyInput) error {
5661
var (
5762
client *powervsconfig.Client
@@ -137,11 +142,11 @@ func (p Provider) InfraReady(ctx context.Context, in clusterapi.InfraReadyInput)
137142

138143
for lbKey, loadBalancerStatus := range powerVSCluster.Status.LoadBalancers {
139144
var (
140-
idx int
141-
substr string
142-
infraID string
143-
hostname string
144-
prefix string
145+
idx int
146+
substr string
147+
infraID string
148+
hostnames []string
149+
prefix string
145150
)
146151

147152
// The infra id is "rdr-hamzy-test-dal10-846vd" and we need "rdr-hamzy-test-dal10"
@@ -157,42 +162,53 @@ func (p Provider) InfraReady(ctx context.Context, in clusterapi.InfraReadyInput)
157162
logrus.Debugf("lbKey = %s", lbKey)
158163
switch {
159164
case lbExtExp.MatchString(lbKey):
160-
prefix = "api."
165+
if in.InstallConfig.Config.Publish == types.ExternalPublishingStrategy {
166+
hostnames = append(hostnames, fmt.Sprintf("%s%s", publicPrefix, infraID))
167+
}
161168
case lbIntExp.MatchString(lbKey):
162-
prefix = "api-int."
169+
hostnames = append(hostnames, fmt.Sprintf("%s%s", privatePrefix, infraID))
170+
// In the private cluster scenario, also point api.* to internal LB
171+
if in.InstallConfig.Config.Publish == types.InternalPublishingStrategy {
172+
hostnames = append(hostnames, fmt.Sprintf("%s%s", publicPrefix, infraID))
173+
}
163174
}
164175
logrus.Debugf("prefix = %s", prefix)
165176

166-
hostname = fmt.Sprintf("%s%s", prefix, infraID)
167-
168-
logrus.Debugf("InfraReady: crn = %s, base domain = %s, hostname = %s, cname = %s",
169-
instanceCRN,
170-
in.InstallConfig.PowerVS.BaseDomain,
171-
hostname,
172-
*loadBalancerStatus.Hostname)
173-
174-
backoff := wait.Backoff{
175-
Duration: 15 * time.Second,
176-
Factor: 1.1,
177-
Cap: leftInContext(ctx),
178-
Steps: math.MaxInt32}
179-
err = wait.ExponentialBackoffWithContext(ctx, backoff, func(context.Context) (bool, error) {
180-
err2 := client.CreateDNSRecord(ctx,
181-
in.InstallConfig.Config.Publish,
177+
for _, hostname := range hostnames {
178+
logrus.Debugf("InfraReady: crn = %s, base domain = %s, hostname = %s, cname = %s",
182179
instanceCRN,
183180
in.InstallConfig.PowerVS.BaseDomain,
184181
hostname,
185182
*loadBalancerStatus.Hostname)
186-
if err2 == nil {
187-
return true, nil
183+
184+
backoff := wait.Backoff{
185+
Duration: 15 * time.Second,
186+
Factor: 1.1,
187+
Cap: leftInContext(ctx),
188+
Steps: math.MaxInt32}
189+
var lastErr error
190+
err = wait.ExponentialBackoffWithContext(ctx, backoff, func(context.Context) (bool, error) {
191+
lastErr = client.CreateDNSRecord(ctx,
192+
in.InstallConfig.Config.Publish,
193+
instanceCRN,
194+
in.InstallConfig.PowerVS.BaseDomain,
195+
hostname,
196+
*loadBalancerStatus.Hostname)
197+
if lastErr == nil {
198+
return true, nil
199+
}
200+
return false, nil
201+
})
202+
203+
if err != nil {
204+
if lastErr != nil {
205+
err = lastErr
206+
}
207+
return fmt.Errorf("failed to create a DNS CNAME record (%s, %s): %w",
208+
hostname,
209+
*loadBalancerStatus.Hostname,
210+
err)
188211
}
189-
return false, err2
190-
})
191-
if err != nil {
192-
return fmt.Errorf("failed to create a DNS CNAME record (%s, %s): %w",
193-
hostname,
194-
*loadBalancerStatus.Hostname,
195-
err)
196212
}
197213
}
198214

@@ -262,20 +278,23 @@ func (p Provider) InfraReady(ctx context.Context, in clusterapi.InfraReadyInput)
262278
Direction: ptr.To("inbound"),
263279
Protocol: ptr.To("icmp"),
264280
}
265-
266281
backoff := wait.Backoff{
267282
Duration: 15 * time.Second,
268283
Factor: 1.1,
269284
Cap: leftInContext(ctx),
270285
Steps: math.MaxInt32}
286+
var lastErr error
271287
err = wait.ExponentialBackoffWithContext(ctx, backoff, func(context.Context) (bool, error) {
272-
err2 := client.AddSecurityGroupRule(ctx, *powerVSCluster.Status.VPC.ID, rule)
273-
if err2 == nil {
288+
lastErr = client.AddSecurityGroupRule(ctx, *powerVSCluster.Status.VPC.ID, rule)
289+
if lastErr == nil {
274290
return true, nil
275291
}
276-
return false, err2
292+
return false, nil
277293
})
278294
if err != nil {
295+
if lastErr != nil {
296+
err = lastErr
297+
}
279298
return fmt.Errorf("failed to add security group rule for icmp: %w", err)
280299
}
281300

0 commit comments

Comments
 (0)