Skip to content

Commit 1422bf7

Browse files
committed
WIP CORS-3296: CAPG - configure Internal LoadBalancer in the provider
Remove the configuration of the GCP Internal Load Balancer from the installer as its now being done in the CAPG provider. This allows only the Internal LB to be created to support Private Clusters. This depends on kubernetes-sigs/cluster-api-provider-gcp#1222 which is still under review.
1 parent fcaa07d commit 1422bf7

File tree

3 files changed

+13
-179
lines changed

3 files changed

+13
-179
lines changed

pkg/asset/manifests/gcp/cluster.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import (
1616
"github.com/openshift/installer/pkg/asset/installconfig"
1717
"github.com/openshift/installer/pkg/asset/manifests/capiutils"
1818
gcpconsts "github.com/openshift/installer/pkg/constants/gcp"
19+
"github.com/openshift/installer/pkg/types"
1920
"github.com/openshift/installer/pkg/types/gcp"
2021
)
2122

@@ -101,6 +102,11 @@ func GenerateClusterAssets(installConfig *installconfig.InstallConfig, clusterID
101102
labels[label.Key] = label.Value
102103
}
103104

105+
capgLoadBalancerType := capg.InternalExternal
106+
if installConfig.Config.Publish == types.InternalPublishingStrategy {
107+
capgLoadBalancerType = capg.Internal
108+
}
109+
104110
gcpCluster := &capg.GCPCluster{
105111
ObjectMeta: metav1.ObjectMeta{
106112
Name: clusterID.InfraID,
@@ -121,6 +127,7 @@ func GenerateClusterAssets(installConfig *installconfig.InstallConfig, clusterID
121127
FailureDomains: findFailureDomains(installConfig),
122128
LoadBalancer: capg.LoadBalancerSpec{
123129
APIServerInstanceGroupTagOverride: ptr.To(InstanceGroupRoleTag),
130+
LoadBalancerType: ptr.To(capgLoadBalancerType),
124131
},
125132
},
126133
}

pkg/infrastructure/gcp/clusterapi/clusterapi.go

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -186,17 +186,6 @@ func (p Provider) InfraReady(ctx context.Context, in clusterapi.InfraReadyInput)
186186
return fmt.Errorf("could not find master subnet %s in subnets %v", masterSubnetName, subnets)
187187
}
188188

189-
zones := gcpCluster.Status.FailureDomains.GetIDs()
190-
191-
// Currently, the internal/private load balancer is not created by CAPG. The load balancer will be created
192-
// by the installer for now.
193-
// TODO: remove the creation of the LB and health check here when supported by CAPG.
194-
// https://github.com/kubernetes-sigs/cluster-api-provider-gcp/issues/903
195-
apiIntIPAddress, err := createInternalLB(ctx, in, masterSubnetSelflink, networkSelfLink, zones)
196-
if err != nil {
197-
return fmt.Errorf("failed to create internal load balancer address: %w", err)
198-
}
199-
200189
// The firewall for masters, aka control-plane, is created by CAPG
201190
// Create the ones needed for worker to master communication
202191
if err = createFirewallRules(ctx, in, *gcpCluster.Status.Network.SelfLink); err != nil {
@@ -214,6 +203,11 @@ func (p Provider) InfraReady(ctx context.Context, in clusterapi.InfraReadyInput)
214203
return fmt.Errorf("failed to create the private managed zone: %w", err)
215204
}
216205

206+
apiIntIPAddress, err := getInternalLBAddress(ctx, in.InstallConfig.Config.GCP.ProjectID, in.InstallConfig.Config.GCP.Region, getAPIAddressName(in.InfraID))
207+
if err != nil {
208+
return fmt.Errorf("failed to get the internal load balancer address: %w", err)
209+
}
210+
217211
// Create the public (optional) and private dns records
218212
if err := createDNSRecords(ctx, in.InstallConfig, in.InfraID, apiIPAddress, apiIntIPAddress); err != nil {
219213
return fmt.Errorf("failed to create DNS records: %w", err)

pkg/infrastructure/gcp/clusterapi/network.go

Lines changed: 1 addition & 168 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,10 @@ package clusterapi
33
import (
44
"context"
55
"fmt"
6-
"time"
7-
8-
"github.com/sirupsen/logrus"
9-
"google.golang.org/api/compute/v1"
10-
11-
"github.com/openshift/installer/pkg/asset/manifests/gcp"
12-
"github.com/openshift/installer/pkg/infrastructure/clusterapi"
136
)
147

15-
func getAPIInternalResourceName(infraID string) string {
16-
return fmt.Sprintf("%s-api-internal", infraID)
17-
}
18-
198
func getAPIAddressName(infraID string) string {
20-
return fmt.Sprintf("%s-cluster-ip", infraID)
9+
return fmt.Sprintf("%s-api-internal", infraID)
2110
}
2211

2312
func getInternalLBAddress(ctx context.Context, project, region, name string) (string, error) {
@@ -32,159 +21,3 @@ func getInternalLBAddress(ctx context.Context, project, region, name string) (st
3221
}
3322
return addrOutput.Address, nil
3423
}
35-
36-
// createInternalLB creates a static ip address for the internal load balancer.
37-
// Returns the IP address of the created load balancer.
38-
func createInternalLB(ctx context.Context, in clusterapi.InfraReadyInput, subnetSelfLink, networkSelfLink string, zones []*string) (string, error) {
39-
projectID := in.InstallConfig.Config.GCP.ProjectID
40-
region := in.InstallConfig.Config.GCP.Region
41-
name := getAPIAddressName(in.InfraID)
42-
labels := mergeLabels(in.InstallConfig, in.InfraID)
43-
44-
service, err := NewComputeService()
45-
if err != nil {
46-
return "", err
47-
}
48-
49-
ctx, cancel := context.WithTimeout(ctx, time.Minute*3)
50-
defer cancel()
51-
52-
// Patch the balancing mode on CAPG proxy classic load balancer backends
53-
// to match the CONNECTION balancing mode used by installer-created
54-
// internal passthrough LB, because:
55-
// "all backend services that reference the instance group must use the same balancing mode"
56-
// cf: https://cloud.google.com/load-balancing/docs/backend-service
57-
logrus.Debug("Patching external load balancer")
58-
extBesvcName := fmt.Sprintf("%s-apiserver", in.InfraID)
59-
extBesvc, err := service.BackendServices.Get(projectID, extBesvcName).Context(ctx).Do()
60-
if err != nil {
61-
return "", fmt.Errorf("failed to get backend service: %w", err)
62-
}
63-
64-
for _, be := range extBesvc.Backends {
65-
be.BalancingMode = "CONNECTION"
66-
be.MaxConnections = int64(2 ^ 32)
67-
}
68-
69-
op, err := service.BackendServices.Patch(projectID, extBesvcName, extBesvc).Context(ctx).Do()
70-
if err != nil {
71-
return "", fmt.Errorf("failed to patch external load balancer: %w", err)
72-
}
73-
74-
if err := WaitForOperationGlobal(ctx, projectID, op); err != nil {
75-
return "", fmt.Errorf("failed to wait for patching external load balancer: %w", err)
76-
}
77-
logrus.Debug("Successfully patched external load balancer")
78-
79-
logrus.Debug("Creating internal load balancer")
80-
addr := &compute.Address{
81-
Name: name,
82-
AddressType: "INTERNAL",
83-
Subnetwork: subnetSelfLink,
84-
Description: resourceDescription,
85-
Labels: labels,
86-
Region: region,
87-
}
88-
89-
op, err = service.Addresses.Insert(projectID, region, addr).Context(ctx).Do()
90-
if err != nil {
91-
return "", fmt.Errorf("failed to create internal compute address: %w", err)
92-
}
93-
94-
if err := WaitForOperationRegional(ctx, projectID, region, op); err != nil {
95-
return "", fmt.Errorf("failed to wait for compute address creation: %w", err)
96-
}
97-
98-
ipAddress, err := getInternalLBAddress(ctx, projectID, region, name)
99-
if err != nil {
100-
return "", fmt.Errorf("failed to get internal load balancer IP address: %w", err)
101-
}
102-
103-
hcName := getAPIInternalResourceName(in.InfraID)
104-
healthCheck := &compute.HealthCheck{
105-
Region: region,
106-
Name: hcName,
107-
Description: resourceDescription,
108-
HealthyThreshold: 3,
109-
UnhealthyThreshold: 3,
110-
CheckIntervalSec: 2,
111-
TimeoutSec: 2,
112-
Type: "HTTPS",
113-
HttpsHealthCheck: &compute.HTTPSHealthCheck{
114-
Port: 6443,
115-
RequestPath: "/readyz",
116-
},
117-
}
118-
119-
_, err = service.RegionHealthChecks.Insert(projectID, region, healthCheck).Context(ctx).Do()
120-
if err != nil {
121-
return "", fmt.Errorf("failed to create api-internal health check: %w", err)
122-
}
123-
124-
if err := WaitForOperationRegional(ctx, projectID, region, op); err != nil {
125-
return "", fmt.Errorf("failed to wait for health check creation: %w", err)
126-
}
127-
128-
hc, err := service.RegionHealthChecks.Get(projectID, region, hcName).Context(ctx).Do()
129-
if err != nil {
130-
return "", fmt.Errorf("error getting health check: %w", err)
131-
}
132-
backends := []*compute.Backend{}
133-
for _, zone := range zones {
134-
igName := fmt.Sprintf("%s-%s-%s", in.InfraID, gcp.InstanceGroupRoleTag, *zone)
135-
ig, err := service.InstanceGroups.Get(projectID, *zone, igName).Context(ctx).Do()
136-
if err != nil {
137-
return "", fmt.Errorf("error getting instance group %s in zone %s: %w", igName, *zone, err)
138-
}
139-
backends = append(backends, &compute.Backend{
140-
BalancingMode: "CONNECTION",
141-
Group: ig.SelfLink,
142-
})
143-
}
144-
145-
besvcName := fmt.Sprintf("%s-api-internal", in.InfraID)
146-
op, err = service.RegionBackendServices.Insert(projectID, region, &compute.BackendService{
147-
Backends: backends,
148-
Name: besvcName,
149-
LoadBalancingScheme: "INTERNAL",
150-
Protocol: "TCP",
151-
TimeoutSec: int64((10 * time.Minute).Seconds()),
152-
HealthChecks: []string{hc.SelfLink},
153-
Region: region,
154-
Network: networkSelfLink,
155-
}).Context(ctx).Do()
156-
if err != nil {
157-
return "", fmt.Errorf("failed to create internal backend service: %w", err)
158-
}
159-
160-
if err := WaitForOperationRegional(ctx, projectID, region, op); err != nil {
161-
return "", fmt.Errorf("failed to wait for internal backend service creation: %w", err)
162-
}
163-
164-
besvc, err := service.RegionBackendServices.Get(projectID, region, besvcName).Context(ctx).Do()
165-
if err != nil {
166-
return "", fmt.Errorf("failed to get backend service: %w", err)
167-
}
168-
169-
op, err = service.ForwardingRules.Insert(projectID, region, &compute.ForwardingRule{
170-
Name: fmt.Sprintf("%s-api-internal", in.InfraID),
171-
IPProtocol: "TCP",
172-
IPAddress: ipAddress,
173-
LoadBalancingScheme: "INTERNAL",
174-
Ports: []string{"6443", "22623"},
175-
BackendService: besvc.SelfLink,
176-
Network: networkSelfLink,
177-
Subnetwork: subnetSelfLink,
178-
Region: region,
179-
Labels: labels,
180-
}).Context(ctx).Do()
181-
if err != nil {
182-
return "", fmt.Errorf("failed to create forwarding rule: %w", err)
183-
}
184-
185-
if err := WaitForOperationRegional(ctx, projectID, region, op); err != nil {
186-
return "", fmt.Errorf("failed to wait for forwarding rule creation: %w", err)
187-
}
188-
logrus.Debug("Successfully created internal load balancer")
189-
return ipAddress, nil
190-
}

0 commit comments

Comments
 (0)