From 3cf89a5de7a2cdf48329cfded3669d51324c359f Mon Sep 17 00:00:00 2001 From: FengyunPan Date: Fri, 20 Oct 2017 12:04:02 +0800 Subject: [PATCH] Check the count of cloud node for LoadBalancer service If there is no available node for LoadBalancer service, the LoadBlancer service will become unavailable, we should update service status. This is part of #53193 --- pkg/controller/service/service_controller.go | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/pkg/controller/service/service_controller.go b/pkg/controller/service/service_controller.go index 0f7c1f686b8..4e1bf41a855 100644 --- a/pkg/controller/service/service_controller.go +++ b/pkg/controller/service/service_controller.go @@ -356,6 +356,11 @@ func (s *ServiceController) ensureLoadBalancer(service *v1.Service) (*v1.LoadBal return nil, err } + // If there are no available nodes for LoadBalancer service, make a EventTypeWarning event for it. + if len(nodes) == 0 { + s.eventRecorder.Eventf(service, v1.EventTypeWarning, "UnAvailableLoadBalancer", "There are no available nodes for LoadBalancer service %s/%s", service.Namespace, service.Name) + } + // - Only one protocol supported per service // - Not all cloud providers support all protocols and the next step is expected to return // an error for unsupported protocols @@ -683,7 +688,12 @@ func (s *ServiceController) lockedUpdateLoadBalancerHosts(service *v1.Service, h // This operation doesn't normally take very long (and happens pretty often), so we only record the final event err := s.balancer.UpdateLoadBalancer(s.clusterName, service, hosts) if err == nil { - s.eventRecorder.Event(service, v1.EventTypeNormal, "UpdatedLoadBalancer", "Updated load balancer with new hosts") + // If there are no available nodes for LoadBalancer service, make a EventTypeWarning event for it. + if len(hosts) == 0 { + s.eventRecorder.Eventf(service, v1.EventTypeWarning, "UnAvailableLoadBalancer", "There are no available nodes for LoadBalancer service %s/%s", service.Namespace, service.Name) + } else { + s.eventRecorder.Event(service, v1.EventTypeNormal, "UpdatedLoadBalancer", "Updated load balancer with new hosts") + } return nil }