From 5cb8e8e1d6dc8d3e06b86fccb2c5ad7aafdf6f37 Mon Sep 17 00:00:00 2001 From: bprashanth Date: Mon, 10 Oct 2016 11:31:12 -0700 Subject: [PATCH] Fix health check node port leak --- pkg/proxy/iptables/proxier.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/pkg/proxy/iptables/proxier.go b/pkg/proxy/iptables/proxier.go index 0feda54e011..c9a886004b1 100644 --- a/pkg/proxy/iptables/proxier.go +++ b/pkg/proxy/iptables/proxier.go @@ -455,18 +455,20 @@ func (proxier *Proxier) OnServiceUpdate(allServices []api.Service) { info.loadBalancerStatus = *api.LoadBalancerStatusDeepCopy(&service.Status.LoadBalancer) info.sessionAffinityType = service.Spec.SessionAffinity info.loadBalancerSourceRanges = service.Spec.LoadBalancerSourceRanges - info.onlyNodeLocalEndpoints = apiservice.NeedsHealthCheck(service) && featuregate.DefaultFeatureGate.ExternalTrafficLocalOnly() + info.onlyNodeLocalEndpoints = apiservice.NeedsHealthCheck(service) && featuregate.DefaultFeatureGate.ExternalTrafficLocalOnly() && (service.Spec.Type == api.ServiceTypeLoadBalancer || service.Spec.Type == api.ServiceTypeNodePort) if info.onlyNodeLocalEndpoints { p := apiservice.GetServiceHealthCheckNodePort(service) if p == 0 { glog.Errorf("Service does not contain necessary annotation %v", apiservice.AnnotationHealthCheckNodePort) } else { + glog.V(4).Infof("Adding health check for %+v, port %v", serviceName.NamespacedName, p) info.healthCheckNodePort = int(p) // Turn on healthcheck responder to listen on the health check nodePort healthcheck.AddServiceListener(serviceName.NamespacedName, info.healthCheckNodePort) } } else { + glog.V(4).Infof("Deleting health check for %+v", serviceName.NamespacedName) // Delete healthcheck responders, if any, previously listening for this service healthcheck.DeleteServiceListener(serviceName.NamespacedName, 0) } @@ -488,6 +490,7 @@ func (proxier *Proxier) OnServiceUpdate(allServices []api.Service) { if info.onlyNodeLocalEndpoints && info.healthCheckNodePort > 0 { // Remove ServiceListener health check nodePorts from the health checker // TODO - Stats + glog.V(4).Infof("Deleting health check for %+v, port %v", name.NamespacedName, info.healthCheckNodePort) healthcheck.DeleteServiceListener(name.NamespacedName, info.healthCheckNodePort) } }