From 5bd729a1b6c38923261e3b8c16cdaf26cc77f1a5 Mon Sep 17 00:00:00 2001 From: Manuel de Brito Fontes Date: Sun, 9 Apr 2017 16:14:20 -0300 Subject: [PATCH] Detect if the ingress controller is running with multiple replicas --- core/pkg/ingress/status/status.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/core/pkg/ingress/status/status.go b/core/pkg/ingress/status/status.go index 05af3329e..704acf5a8 100644 --- a/core/pkg/ingress/status/status.go +++ b/core/pkg/ingress/status/status.go @@ -111,6 +111,11 @@ func (s statusSync) Shutdown() { return } + if s.isRunningMultiplePods() { + glog.V(2).Infof("skipping Ingress status update (multiple pods running - another one will be elected as master)") + return + } + glog.Infof("removing address from ingress status (%v)", addrs) s.updateStatus([]api_v1.LoadBalancerIngress{}) } @@ -232,6 +237,17 @@ func (s *statusSync) runningAddresess() ([]string, error) { return addrs, nil } +func (s *statusSync) isRunningMultiplePods() bool { + pods, err := s.Client.Core().Pods(s.pod.Namespace).List(meta_v1.ListOptions{ + LabelSelector: labels.SelectorFromSet(s.pod.Labels).String(), + }) + if err != nil { + return false + } + + return len(pods.Items) > 1 +} + // sliceToStatus converts a slice of IP and/or hostnames to LoadBalancerIngress func sliceToStatus(endpoints []string) []api_v1.LoadBalancerIngress { lbi := []api_v1.LoadBalancerIngress{}