@@ -125,23 +125,27 @@ func (g *Cloud) ensureInternalLoadBalancer(clusterName, clusterID string, svc *v
125125 }
126126 }
127127
128- // Lock the sharedResourceLock to prevent any deletions of shared resources while assembling shared resources here
129- g .sharedResourceLock .Lock ()
130- defer g .sharedResourceLock .Unlock ()
131-
132- // Ensure health check exists before creating the backend service. The health check is shared
133- // if externalTrafficPolicy=Cluster.
134- sharedHealthCheck := ! servicehelpers .RequestsOnlyLocalTraffic (svc )
135- hcName := makeHealthCheckName (loadBalancerName , clusterID , sharedHealthCheck )
136- hcPath , hcPort := GetNodesHealthCheckPath (), GetNodesHealthCheckPort ()
137- if ! sharedHealthCheck {
138- // Service requires a special health check, retrieve the OnlyLocal port & path
139- hcPath , hcPort = servicehelpers .GetServiceHealthCheckPathPort (svc )
140- }
141- hc , err := g .ensureInternalHealthCheck (hcName , nm , sharedHealthCheck , hcPath , hcPort )
128+ hc , hcPort , sharedHealthCheck , err := func () (* compute.HealthCheck , int32 , bool , error ) {
129+ // Lock the sharedResourceLock to prevent any deletions of shared resources while assembling shared resources here
130+ g .sharedResourceLock .Lock ()
131+ defer g .sharedResourceLock .Unlock ()
132+
133+ // Ensure health check exists before creating the backend service. The health check is shared
134+ // if externalTrafficPolicy=Cluster.
135+ sharedHealthCheck := ! servicehelpers .RequestsOnlyLocalTraffic (svc )
136+ hcName := makeHealthCheckName (loadBalancerName , clusterID , sharedHealthCheck )
137+ hcPath , hcPort := GetNodesHealthCheckPath (), GetNodesHealthCheckPort ()
138+ if ! sharedHealthCheck {
139+ // Service requires a special health check, retrieve the OnlyLocal port & path
140+ hcPath , hcPort = servicehelpers .GetServiceHealthCheckPathPort (svc )
141+ }
142+ hc , err := g .ensureInternalHealthCheck (hcName , nm , sharedHealthCheck , hcPath , hcPort )
143+ return hc , hcPort , sharedHealthCheck , err
144+ }()
142145 if err != nil {
143146 return nil , err
144147 }
148+ hcName := hc .Name
145149
146150 subnetworkURL := g .SubnetworkURL ()
147151 // Any subnet specified using the subnet annotation will be picked up and reflected in the forwarding rule.
@@ -1046,8 +1050,9 @@ func ilbIPToUse(svc *v1.Service, fwdRule *compute.ForwardingRule, requestedSubne
10461050}
10471051
10481052func getILBOptions (svc * v1.Service ) ILBOptions {
1049- return ILBOptions {AllowGlobalAccess : GetLoadBalancerAnnotationAllowGlobalAccess (svc ),
1050- SubnetName : GetLoadBalancerAnnotationSubnet (svc ),
1053+ return ILBOptions {
1054+ AllowGlobalAccess : GetLoadBalancerAnnotationAllowGlobalAccess (svc ),
1055+ SubnetName : GetLoadBalancerAnnotationSubnet (svc ),
10511056 }
10521057}
10531058
0 commit comments