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: Josh Horwitz <horwitzja@gmail.com>
This commit is contained in:
Zihong Zheng
2019-05-23 00:01:08 -07:00
parent e44fb7333e
commit aa3f81d657
2 changed files with 180 additions and 84 deletions

View File

@@ -20,7 +20,7 @@ import (
"fmt"
"strings"
"k8s.io/api/core/v1"
v1 "k8s.io/api/core/v1"
utilnet "k8s.io/utils/net"
)
@@ -31,6 +31,11 @@ in order for in-tree cloud providers to not depend on internal packages.
const (
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
@@ -100,3 +105,13 @@ func NeedsHealthCheck(service *v1.Service) bool {
}
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
}