From 4bb5f703282d5402dd32594e8453ff24eb84fdc8 Mon Sep 17 00:00:00 2001 From: Nick Young Date: Thu, 26 Mar 2020 14:34:25 +1100 Subject: [PATCH] Update status updater name to IngressStatusUpdater, fix RBAC Updates #403. Change StatusLoadBalancer name to IngressStatusUpdater, makes the purpose clearer. Minor fix to RBAC - "ingress/status" resource requires "update" for updating status. Signed-off-by: Nick Young --- cmd/contour/ingressstatus.go | 11 ++++++----- examples/contour/02-rbac.yaml | 1 + internal/contour/handler.go | 2 +- internal/k8s/ingressstatus.go | 8 ++++---- 4 files changed, 12 insertions(+), 10 deletions(-) diff --git a/cmd/contour/ingressstatus.go b/cmd/contour/ingressstatus.go index 07f9cce1bec..4774293dd8b 100644 --- a/cmd/contour/ingressstatus.go +++ b/cmd/contour/ingressstatus.go @@ -21,15 +21,16 @@ import ( v1 "k8s.io/api/core/v1" ) -// ingressStatusWriter manages the lifetime of StatusLoadBalancerUpdaters. +// ingressStatusWriter manages the lifetime of IngressStatusUpdaters. // // The theory of operation of the ingressStatusWriter is as follows: // 1. On startup the ingressStatusWriter waits to be elected leader. // 2. Once elected leader, the ingressStatusWriter waits to receive a // v1.LoadBalancerStatus value. // 3. Once a v1.LoadBalancerStatus value has been received, any existing informer -// is stopped and a new informer started in its place. -// 4. Each informer is connected to a k8s.StatusLoadBalancerUpdater which reacts to +// is stopped and a new informer started in its place. This ensures that all existing +// Ingress objects will have OnAdd events fired to the new event handler. +// 4. Each informer is connected to a k8s.IngressStatusUpdater which reacts to // OnAdd events for networking.k8s.io/ingress.v1beta1 objects. For each OnAdd // the object is patched with the v1.LoadBalancerStatus value obtained on creation. // OnUpdate and OnDelete events are ignored.If a new v1.LoadBalancerStatus value @@ -75,8 +76,8 @@ func (isw *ingressStatusWriter) Start(stop <-chan struct{}) error { // create informer for the new LoadBalancerStatus factory := isw.clients.NewInformerFactory() inf := factory.Networking().V1beta1().Ingresses().Informer() - log := isw.log.WithField("context", "IngressStatusLoadBalancerUpdater") - inf.AddEventHandler(&k8s.StatusLoadBalancerUpdater{ + log := isw.log.WithField("context", "IngressStatusUpdater") + inf.AddEventHandler(&k8s.IngressStatusUpdater{ Client: isw.clients.ClientSet(), Logger: log, Status: lbs, diff --git a/examples/contour/02-rbac.yaml b/examples/contour/02-rbac.yaml index 1904a6fcbe9..bfcb123346c 100644 --- a/examples/contour/02-rbac.yaml +++ b/examples/contour/02-rbac.yaml @@ -60,6 +60,7 @@ rules: - watch - patch - post + - update - apiGroups: ["contour.heptio.com"] resources: ["ingressroutes", "tlscertificatedelegations"] verbs: diff --git a/internal/contour/handler.go b/internal/contour/handler.go index 92484c219c4..e351f2f83d8 100644 --- a/internal/contour/handler.go +++ b/internal/contour/handler.go @@ -223,7 +223,7 @@ func (e *EventHandler) updateDAG() { e.Metrics.SetIngressRouteMetric(metrics) e.Metrics.SetHTTPProxyMetric(proxymetrics) default: - e.Debug("skipping status update: not the leader") + e.Debug("skipping metrics and CRD status update, not leader") } } diff --git a/internal/k8s/ingressstatus.go b/internal/k8s/ingressstatus.go index fb94f779a5d..4108cf69e4c 100644 --- a/internal/k8s/ingressstatus.go +++ b/internal/k8s/ingressstatus.go @@ -23,13 +23,13 @@ import ( // StatusLoadbalancerUpdater observes informer OnAdd events and // updates the ingress.status.loadBalancer field on all Ingress // objects that match the ingress class (if used). -type StatusLoadBalancerUpdater struct { +type IngressStatusUpdater struct { Client clientset.Interface Logger logrus.FieldLogger Status v1.LoadBalancerStatus } -func (s *StatusLoadBalancerUpdater) OnAdd(obj interface{}) { +func (s *IngressStatusUpdater) OnAdd(obj interface{}) { ing := obj.(*v1beta1.Ingress).DeepCopy() // TODO(dfc) check ingress class @@ -44,7 +44,7 @@ func (s *StatusLoadBalancerUpdater) OnAdd(obj interface{}) { } } -func (s *StatusLoadBalancerUpdater) OnUpdate(oldObj, newObj interface{}) { +func (s *IngressStatusUpdater) OnUpdate(oldObj, newObj interface{}) { // Ignoring OnUpdate allows us to avoid the message generated // from the status update. @@ -55,7 +55,7 @@ func (s *StatusLoadBalancerUpdater) OnUpdate(oldObj, newObj interface{}) { // of scope. } -func (s *StatusLoadBalancerUpdater) OnDelete(obj interface{}) { +func (s *IngressStatusUpdater) OnDelete(obj interface{}) { // we don't need to update the status on resources that // have been deleted. }