From 813d264c86ba461c20c741c28b7890f712392491 Mon Sep 17 00:00:00 2001 From: Brendan Burns Date: Fri, 11 Aug 2017 16:49:38 -0700 Subject: [PATCH] Delete load balancers if the UIDs for services don't match. --- pkg/controller/service/service_controller.go | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/pkg/controller/service/service_controller.go b/pkg/controller/service/service_controller.go index 52f3c64998a..9303290071d 100644 --- a/pkg/controller/service/service_controller.go +++ b/pkg/controller/service/service_controller.go @@ -223,7 +223,14 @@ func (s *ServiceController) init() error { // indicating whether processing should be retried; zero means no-retry; otherwise // we should retry in that Duration. func (s *ServiceController) processServiceUpdate(cachedService *cachedService, service *v1.Service, key string) (error, time.Duration) { - + if cachedService.state != nil { + if cachedService.state.UID != service.UID { + err, retry := s.processLoadBalancerDelete(cachedService, key) + if err != nil { + return err, retry + } + } + } // cache the service, we need the info for service deletion cachedService.state = service err, retry := s.createLoadBalancerIfNeeded(key, service) @@ -765,6 +772,10 @@ func (s *ServiceController) processServiceDeletion(key string) (error, time.Dura if !ok { return fmt.Errorf("Service %s not in cache even though the watcher thought it was. Ignoring the deletion.", key), doNotRetry } + return s.processLoadBalancerDelete(cachedService, key) +} + +func (s *ServiceController) processLoadBalancerDelete(cachedService *cachedService, key string) (error, time.Duration) { service := cachedService.state // delete load balancer info only if the service type is LoadBalancer if !wantsLoadBalancer(service) {