Commit aa3f81d6 authored by Zihong Zheng's avatar Zihong Zheng

Add Load Balancer finalizer support

- Always try to remove finalizer upon load balancer cleanup - Add finalizer prior to load balancer creation (feature gated) - Cache logic fix-ups - Event type/message fix-ups - Use runtime.HandleError() on eaten errors Co-authored-by: 's avatarJosh Horwitz <horwitzja@gmail.com>
parent e44fb733
...@@ -20,7 +20,7 @@ import ( ...@@ -20,7 +20,7 @@ import (
"fmt" "fmt"
"strings" "strings"
"k8s.io/api/core/v1" v1 "k8s.io/api/core/v1"
utilnet "k8s.io/utils/net" utilnet "k8s.io/utils/net"
) )
...@@ -31,6 +31,11 @@ in order for in-tree cloud providers to not depend on internal packages. ...@@ -31,6 +31,11 @@ in order for in-tree cloud providers to not depend on internal packages.
const ( const (
defaultLoadBalancerSourceRanges = "0.0.0.0/0" defaultLoadBalancerSourceRanges = "0.0.0.0/0"
// LoadBalancerCleanupFinalizer is the finalizer added to load balancer
// services to ensure the Service resource is not fully deleted until
// the correlating load balancer resources are deleted.
LoadBalancerCleanupFinalizer = "service.kubernetes.io/load-balancer-cleanup"
) )
// IsAllowAll checks whether the utilnet.IPNet allows traffic from 0.0.0.0/0 // IsAllowAll checks whether the utilnet.IPNet allows traffic from 0.0.0.0/0
...@@ -100,3 +105,13 @@ func NeedsHealthCheck(service *v1.Service) bool { ...@@ -100,3 +105,13 @@ func NeedsHealthCheck(service *v1.Service) bool {
} }
return RequestsOnlyLocalTraffic(service) return RequestsOnlyLocalTraffic(service)
} }
// HasLBFinalizer checks if service contains LoadBalancerCleanupFinalizer.
func HasLBFinalizer(service *v1.Service) bool {
for _, finalizer := range service.ObjectMeta.Finalizers {
if finalizer == LoadBalancerCleanupFinalizer {
return true
}
}
return false
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment