@@ -41,12 +41,30 @@ import (
41
41
const (
42
42
// Used to list instances in all states(RUNNING and other) - https://cloud.google.com/compute/docs/reference/rest/v1/instanceGroups/listInstances
43
43
allInstances = "ALL"
44
+ // ILBFinalizerV1 key is used to identify ILB services whose resources are managed by service controller.
45
+ ILBFinalizerV1 = "gke.networking.io/l4-ilb-v1"
46
+ // ILBFinalizerV2 is the finalizer used by newer controllers that implement Internal LoadBalancer services.
47
+ ILBFinalizerV2 = "gke.networking.io/l4-ilb-v2"
44
48
)
45
49
46
50
func (g * Cloud ) ensureInternalLoadBalancer (clusterName , clusterID string , svc * v1.Service , existingFwdRule * compute.ForwardingRule , nodes []* v1.Node ) (* v1.LoadBalancerStatus , error ) {
47
- if g .AlphaFeatureGate .Enabled (AlphaFeatureILBSubsets ) {
51
+ if g .AlphaFeatureGate .Enabled (AlphaFeatureILBSubsets ) && existingFwdRule == nil {
52
+ // When ILBSubsets is enabled, new ILB services will not be processed here.
53
+ // Services that have existing GCE resources created by this controller will continue to update.
54
+ g .eventRecorder .Eventf (svc , v1 .EventTypeNormal , "SkippingEnsureInternalLoadBalancer" ,
55
+ "Skipped ensureInternalLoadBalancer since %s feature is enabled." , AlphaFeatureILBSubsets )
56
+ return nil , cloudprovider .ImplementedElsewhere
57
+ }
58
+ if hasFinalizer (svc , ILBFinalizerV2 ) {
59
+ // Another controller is handling the resources for this service.
60
+ g .eventRecorder .Eventf (svc , v1 .EventTypeNormal , "SkippingEnsureInternalLoadBalancer" ,
61
+ "Skipped ensureInternalLoadBalancer as service contains '%s' finalizer." , ILBFinalizerV2 )
48
62
return nil , cloudprovider .ImplementedElsewhere
49
63
}
64
+ if err := addFinalizer (svc , g .client .CoreV1 (), ILBFinalizerV1 ); err != nil {
65
+ klog .Errorf ("Failed to attach finalizer '%s' on service %s/%s - %v" , ILBFinalizerV1 , svc .Namespace , svc .Name , err )
66
+ return nil , err
67
+ }
50
68
51
69
nm := types.NamespacedName {Name : svc .Name , Namespace : svc .Namespace }
52
70
ports , _ , protocol := getPortsAndProtocol (svc .Spec .Ports )
@@ -298,6 +316,11 @@ func (g *Cloud) ensureInternalLoadBalancerDeleted(clusterName, clusterID string,
298
316
return err
299
317
}
300
318
319
+ if err := removeFinalizer (svc , g .client .CoreV1 (), ILBFinalizerV1 ); err != nil {
320
+ klog .Errorf ("Failed to remove finalizer '%s' on service %s/%s - %v" , ILBFinalizerV1 , svc .Namespace , svc .Name , err )
321
+ return err
322
+ }
323
+
301
324
return nil
302
325
}
303
326
0 commit comments