From 60e2e5f9ad8b842c87534085d37e79246b392413 Mon Sep 17 00:00:00 2001 From: Manuel de Brito Fontes Date: Thu, 31 Mar 2016 14:59:28 -0300 Subject: [PATCH] Avoid sync Ingress updates --- controllers/nginx/controller.go | 51 +++++++++++++------ .../rc-custom-configuration.yaml | 2 +- .../examples/daemonset/as-daemonset.yaml | 2 +- .../nginx/examples/default/rc-default.yaml | 2 +- controllers/nginx/examples/full/rc-full.yaml | 2 +- controllers/nginx/examples/tcp/rc-tcp.yaml | 2 +- controllers/nginx/examples/tls/rc-ssl.yaml | 2 +- controllers/nginx/examples/udp/rc-udp.yaml | 2 +- 8 files changed, 42 insertions(+), 23 deletions(-) diff --git a/controllers/nginx/controller.go b/controllers/nginx/controller.go index 08bd13776..55d696238 100644 --- a/controllers/nginx/controller.go +++ b/controllers/nginx/controller.go @@ -68,6 +68,7 @@ type loadBalancerController struct { recorder record.EventRecorder syncQueue *taskQueue + ingQueue *taskQueue // stopLock is used to enforce only a single call to Stop is active. // Needed because we allow stopping through an http endpoint and @@ -98,12 +99,13 @@ func newLoadBalancerController(kubeClient *client.Client, resyncPeriod time.Dura } lbc.syncQueue = NewTaskQueue(lbc.sync) + lbc.ingQueue = NewTaskQueue(lbc.syncIngress) ingEventHandler := framework.ResourceEventHandlerFuncs{ AddFunc: func(obj interface{}) { addIng := obj.(*extensions.Ingress) lbc.recorder.Eventf(addIng, api.EventTypeNormal, "CREATE", fmt.Sprintf("%s/%s", addIng.Namespace, addIng.Name)) - lbc.updateIngressStatus(addIng) + lbc.ingQueue.enqueue(obj) lbc.syncQueue.enqueue(obj) }, DeleteFunc: func(obj interface{}) { @@ -115,7 +117,7 @@ func newLoadBalancerController(kubeClient *client.Client, resyncPeriod time.Dura if !reflect.DeepEqual(old, cur) { upIng := cur.(*extensions.Ingress) lbc.recorder.Eventf(upIng, api.EventTypeNormal, "UPDATE", fmt.Sprintf("%s/%s", upIng.Namespace, upIng.Name)) - lbc.updateIngressStatus(upIng) + lbc.ingQueue.enqueue(cur) lbc.syncQueue.enqueue(cur) } }, @@ -237,26 +239,42 @@ func (lbc *loadBalancerController) sync(key string) { }) } -func (lbc *loadBalancerController) updateIngressStatus(ing *extensions.Ingress) { - ingClient := lbc.client.Extensions().Ingress(ing.Namespace) - currIng, err := ingClient.Get(ing.Name) - if err != nil { - glog.Errorf("unexpected error searching Ingress %v/%v: %v", ing.Namespace, ing.Name, err) +func (lbc *loadBalancerController) syncIngress(key string) { + if !lbc.controllersInSync() { + lbc.ingQueue.requeue(key, fmt.Errorf("deferring sync till endpoints controller has synced")) return } - lbIPs := ing.Status.LoadBalancer.Ingress - if len(lbIPs) > 0 && !lbc.isStatusIPDefined(lbIPs) { - glog.Infof("Updating loadbalancer %v/%v with IP %v", ing.Namespace, ing.Name, lbc.lbInfo.Address) - currIng.Status.LoadBalancer.Ingress = append(currIng.Status.LoadBalancer.Ingress, api.LoadBalancerIngress{ - IP: lbc.lbInfo.Address, - }) - if _, err := ingClient.UpdateStatus(currIng); err != nil { - lbc.recorder.Eventf(currIng, api.EventTypeWarning, "UPDATE", "error: %v", err) + obj, ingExists, err := lbc.ingLister.Store.GetByKey(key) + if err != nil { + lbc.ingQueue.requeue(key, err) + return + } + + if ingExists { + ing := obj.(*extensions.Ingress) + + ingClient := lbc.client.Extensions().Ingress(ing.Namespace) + + currIng, err := ingClient.Get(ing.Name) + if err != nil { + glog.Errorf("unexpected error searching Ingress %v/%v: %v", ing.Namespace, ing.Name, err) return } - lbc.recorder.Eventf(currIng, api.EventTypeNormal, "CREATE", "ip: %v", lbc.lbInfo.Address) + lbIPs := ing.Status.LoadBalancer.Ingress + if len(lbIPs) > 0 && !lbc.isStatusIPDefined(lbIPs) { + glog.Infof("Updating loadbalancer %v/%v with IP %v", ing.Namespace, ing.Name, lbc.lbInfo.Address) + currIng.Status.LoadBalancer.Ingress = append(currIng.Status.LoadBalancer.Ingress, api.LoadBalancerIngress{ + IP: lbc.lbInfo.Address, + }) + if _, err := ingClient.UpdateStatus(currIng); err != nil { + lbc.recorder.Eventf(currIng, api.EventTypeWarning, "UPDATE", "error: %v", err) + return + } + + lbc.recorder.Eventf(currIng, api.EventTypeNormal, "CREATE", "ip: %v", lbc.lbInfo.Address) + } } } @@ -701,6 +719,7 @@ func (lbc *loadBalancerController) Run() { go lbc.svcController.Run(lbc.stopCh) go lbc.syncQueue.run(time.Second, lbc.stopCh) + go lbc.ingQueue.run(time.Second, lbc.stopCh) <-lbc.stopCh glog.Infof("shutting down NGINX loadbalancer controller") diff --git a/controllers/nginx/examples/custom-configuration/rc-custom-configuration.yaml b/controllers/nginx/examples/custom-configuration/rc-custom-configuration.yaml index 8e5f92655..aef3d16f3 100644 --- a/controllers/nginx/examples/custom-configuration/rc-custom-configuration.yaml +++ b/controllers/nginx/examples/custom-configuration/rc-custom-configuration.yaml @@ -15,7 +15,7 @@ spec: name: nginx-ingress-lb spec: containers: - - image: gcr.io/google_containers/nginx-ingress-controller:0.4 + - image: gcr.io/google_containers/nginx-ingress-controller:0.5 name: nginx-ingress-lb imagePullPolicy: Always livenessProbe: diff --git a/controllers/nginx/examples/daemonset/as-daemonset.yaml b/controllers/nginx/examples/daemonset/as-daemonset.yaml index e029c53bb..dc3b37f6b 100644 --- a/controllers/nginx/examples/daemonset/as-daemonset.yaml +++ b/controllers/nginx/examples/daemonset/as-daemonset.yaml @@ -9,7 +9,7 @@ spec: name: nginx-ingress-lb spec: containers: - - image: gcr.io/google_containers/nginx-ingress-controller:0.4 + - image: gcr.io/google_containers/nginx-ingress-controller:0.5 name: nginx-ingress-lb imagePullPolicy: Always livenessProbe: diff --git a/controllers/nginx/examples/default/rc-default.yaml b/controllers/nginx/examples/default/rc-default.yaml index 73f377742..459865753 100644 --- a/controllers/nginx/examples/default/rc-default.yaml +++ b/controllers/nginx/examples/default/rc-default.yaml @@ -15,7 +15,7 @@ spec: name: nginx-ingress-lb spec: containers: - - image: gcr.io/google_containers/nginx-ingress-controller:0.4 + - image: gcr.io/google_containers/nginx-ingress-controller:0.5 name: nginx-ingress-lb imagePullPolicy: Always livenessProbe: diff --git a/controllers/nginx/examples/full/rc-full.yaml b/controllers/nginx/examples/full/rc-full.yaml index 2e406f7f4..f6d6e9580 100644 --- a/controllers/nginx/examples/full/rc-full.yaml +++ b/controllers/nginx/examples/full/rc-full.yaml @@ -20,7 +20,7 @@ spec: secret: secretName: dhparam-example containers: - - image: gcr.io/google_containers/nginx-ingress-controller:0.4 + - image: gcr.io/google_containers/nginx-ingress-controller:0.5 name: nginx-ingress-lb imagePullPolicy: Always livenessProbe: diff --git a/controllers/nginx/examples/tcp/rc-tcp.yaml b/controllers/nginx/examples/tcp/rc-tcp.yaml index 61e6b7a37..a38bf7145 100644 --- a/controllers/nginx/examples/tcp/rc-tcp.yaml +++ b/controllers/nginx/examples/tcp/rc-tcp.yaml @@ -15,7 +15,7 @@ spec: name: nginx-ingress-lb spec: containers: - - image: gcr.io/google_containers/nginx-ingress-controller:0.4 + - image: gcr.io/google_containers/nginx-ingress-controller:0.5 name: nginx-ingress-lb imagePullPolicy: Always livenessProbe: diff --git a/controllers/nginx/examples/tls/rc-ssl.yaml b/controllers/nginx/examples/tls/rc-ssl.yaml index 9ef3b864d..798539860 100644 --- a/controllers/nginx/examples/tls/rc-ssl.yaml +++ b/controllers/nginx/examples/tls/rc-ssl.yaml @@ -15,7 +15,7 @@ spec: name: nginx-ingress-lb spec: containers: - - image: gcr.io/google_containers/nginx-ingress-controller:0.4 + - image: gcr.io/google_containers/nginx-ingress-controller:0.5 name: nginx-ingress-lb imagePullPolicy: Always livenessProbe: diff --git a/controllers/nginx/examples/udp/rc-udp.yaml b/controllers/nginx/examples/udp/rc-udp.yaml index 4a057fc5c..9e0920f07 100644 --- a/controllers/nginx/examples/udp/rc-udp.yaml +++ b/controllers/nginx/examples/udp/rc-udp.yaml @@ -15,7 +15,7 @@ spec: name: nginx-ingress-lb spec: containers: - - image: aledbf/nginx-third-party:0.9 + - image: gcr.io/google_containers/nginx-ingress-controller:0.5 name: nginx-ingress-lb imagePullPolicy: Always livenessProbe: