@@ -125,23 +125,31 @@ 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 ()
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+ klog .V (2 ).Infof ("ensureInternalLoadBalancer(%v): Locked shared resource lock to assemble shared health check" , loadBalancerName )
132+ defer func () {
133+ g .sharedResourceLock .Unlock ()
134+ klog .V (2 ).Infof ("ensureInternalLoadBalancer(%v): Unlocked shared resource lock after assembling shared health check" , loadBalancerName )
135+ }()
131136
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 )
137+ // Ensure health check exists before creating the backend service. The health check is shared
138+ // if externalTrafficPolicy=Cluster.
139+ sharedHealthCheck := ! servicehelpers .RequestsOnlyLocalTraffic (svc )
140+ hcName := makeHealthCheckName (loadBalancerName , clusterID , sharedHealthCheck )
141+ hcPath , hcPort := GetNodesHealthCheckPath (), GetNodesHealthCheckPort ()
142+ if ! sharedHealthCheck {
143+ // Service requires a special health check, retrieve the OnlyLocal port & path
144+ hcPath , hcPort = servicehelpers .GetServiceHealthCheckPathPort (svc )
145+ }
146+ hc , err := g .ensureInternalHealthCheck (hcName , nm , sharedHealthCheck , hcPath , hcPort )
147+ return hc , hcPort , sharedHealthCheck , err
148+ }()
142149 if err != nil {
143150 return nil , err
144151 }
152+ hcName := hc .Name
145153
146154 subnetworkURL := g .SubnetworkURL ()
147155 // Any subnet specified using the subnet annotation will be picked up and reflected in the forwarding rule.
@@ -1046,8 +1054,9 @@ func ilbIPToUse(svc *v1.Service, fwdRule *compute.ForwardingRule, requestedSubne
10461054}
10471055
10481056func getILBOptions (svc * v1.Service ) ILBOptions {
1049- return ILBOptions {AllowGlobalAccess : GetLoadBalancerAnnotationAllowGlobalAccess (svc ),
1050- SubnetName : GetLoadBalancerAnnotationSubnet (svc ),
1057+ return ILBOptions {
1058+ AllowGlobalAccess : GetLoadBalancerAnnotationAllowGlobalAccess (svc ),
1059+ SubnetName : GetLoadBalancerAnnotationSubnet (svc ),
10511060 }
10521061}
10531062
0 commit comments