Skip to content

Commit

Permalink
Update status updater name to IngressStatusUpdater, fix RBAC
Browse files Browse the repository at this point in the history
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 <ynick@vmware.com>
  • Loading branch information
youngnick committed Mar 26, 2020
1 parent 0405cf8 commit 4bb5f70
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 10 deletions.
11 changes: 6 additions & 5 deletions cmd/contour/ingressstatus.go
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions examples/contour/02-rbac.yaml
Expand Up @@ -60,6 +60,7 @@ rules:
- watch
- patch
- post
- update
- apiGroups: ["contour.heptio.com"]
resources: ["ingressroutes", "tlscertificatedelegations"]
verbs:
Expand Down
2 changes: 1 addition & 1 deletion internal/contour/handler.go
Expand Up @@ -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")
}
}

Expand Down
8 changes: 4 additions & 4 deletions internal/k8s/ingressstatus.go
Expand Up @@ -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
Expand All @@ -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.

Expand All @@ -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.
}
Expand Down

0 comments on commit 4bb5f70

Please sign in to comment.