@@ -17,6 +17,7 @@ limitations under the License.
1717package l4lb
1818
1919import (
20+ ctx "context"
2021 "fmt"
2122 "math/rand"
2223 "reflect"
@@ -29,13 +30,15 @@ import (
2930 "github.com/GoogleCloudPlatform/k8s-cloud-provider/pkg/cloud/meta"
3031 "github.com/google/go-cmp/cmp"
3132 v1 "k8s.io/api/core/v1"
33+ metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
3234 "k8s.io/apimachinery/pkg/types"
3335 "k8s.io/apimachinery/pkg/util/wait"
3436 "k8s.io/client-go/tools/cache"
3537 "k8s.io/ingress-gce/pkg/annotations"
3638 "k8s.io/ingress-gce/pkg/backends"
3739 "k8s.io/ingress-gce/pkg/common/operator"
3840 "k8s.io/ingress-gce/pkg/context"
41+
3942 "k8s.io/ingress-gce/pkg/flags"
4043 "k8s.io/ingress-gce/pkg/forwardingrules"
4144 "k8s.io/ingress-gce/pkg/instancegroups"
@@ -59,7 +62,7 @@ const (
5962 instanceGroupLink backendLinkType = 0
6063 negLink backendLinkType = 1
6164
62- delayDurationForLegacyOwnershipPriority : = 5 * time.Second // Configurable via flag if needed
65+ delayDurationForLegacyOwnershipPriority = 5 * time .Second // Configurable via flag if needed
6366)
6467
6568type backendLinkType int64
@@ -416,13 +419,13 @@ func (lc *L4NetLBController) isRBSBasedService(svc *v1.Service, svcLogger klog.L
416419}
417420
418421func (lc * L4NetLBController ) hasLegacyControllerOwnership (svc * v1.Service , svcLogger klog.Logger ) bool {
419- // Check for legacy finalizer
420- if utils .HasL4NetLBFinalizerV1 (svc ) {
421- return true
422- }
422+ // Check for legacy finalizer
423+ if utils .HasL4NetLBFinalizerV1 (svc ) {
424+ return true
425+ }
423426
424- // Check if forwarding rule points to a target pool
425- return lc .hasTargetPoolForwardingRule (svc , svcLogger )
427+ // Check if forwarding rule points to a target pool
428+ return lc .hasTargetPoolForwardingRule (svc , svcLogger )
426429}
427430
428431// refreshServiceFromK8s fetches the latest version of the service from Kubernetes
@@ -434,7 +437,7 @@ func (lc *L4NetLBController) refreshServiceFromK8s(service *v1.Service, svcLogge
434437
435438 // Get the latest service from Kubernetes
436439 refreshedService , err := lc .ctx .KubeClient .CoreV1 ().Services (service .Namespace ).Get (
437- context .TODO (),
440+ ctx .TODO (),
438441 service .Name ,
439442 metav1.GetOptions {},
440443 )
@@ -453,7 +456,7 @@ func (lc *L4NetLBController) refreshServiceFromK8s(service *v1.Service, svcLogge
453456func (lc * L4NetLBController ) preventLegacyServiceHandling (service * v1.Service , key string , svcLogger klog.Logger ) (bool , error ) {
454457 svcLogger .Info ("Checking for legacy target pool service with RBS annotation or finalizers" , "finalizers" , service .ObjectMeta .Finalizers )
455458 if lc .isRBSBasedService (service , svcLogger ) && lc .hasLegacyControllerOwnership (service , svcLogger ) {
456- if utils .HasL4NetLBFinalizerV2 ( service ) || utils . HasL4NetLBFinalizerV3 (service ) {
459+ if utils .HasL4NetLBRBSFinalizers (service ) {
457460 // If we found that RBS finalizer was attached to service, it means that RBS controller
458461 // had a race condition on Service creation with Legacy Controller.
459462 // It should only happen during service creation, and we should clean up RBS resources
@@ -675,9 +678,7 @@ func (lc *L4NetLBController) syncInternal(service *v1.Service, svcLogger klog.Lo
675678 svcLogger .Info ("Finished syncing L4 NetLB RBS service" , "timeTaken" , time .Since (startTime ))
676679 }()
677680
678- hasRBSFinalizer := utils .HasL4NetLBFinalizerV2 (service ) || utils .HasL4NetLBFinalizerV3 (service )
679-
680- if ! hasRBSFinalizer && lc .enableRBSDefault {
681+ if ! utils .HasL4NetLBRBSFinalizers (service ) && lc .enableRBSDefault {
681682 // Add a delay to allow legacy controller to potentially claim the service first
682683
683684 svcLogger .Info ("Service does not have RBS finalizer yet and RBS is default. Adding delay to allow legacy controller to act first" ,
0 commit comments