@@ -3,21 +3,10 @@ package clusterapi
33import (
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-
198func getAPIAddressName (infraID string ) string {
20- return fmt .Sprintf ("%s-cluster-ip " , infraID )
9+ return fmt .Sprintf ("%s-api-internal " , infraID )
2110}
2211
2312func 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