diff --git a/controller/controller.go b/controller/controller.go index e96bc963..d2407b5b 100644 --- a/controller/controller.go +++ b/controller/controller.go @@ -163,8 +163,8 @@ func (c *HAProxyController) updateHAProxy() { if ingResource.Status == DELETED { continue } - i := ingress.New(ingResource, c.OSArgs.IngressClass, c.OSArgs.EmptyIngressClass) - if !i.Supported(c.Store) { + i := ingress.New(c.Store, ingResource, c.OSArgs.IngressClass, c.OSArgs.EmptyIngressClass) + if i == nil { logger.Debugf("ingress '%s/%s' ignored: no matching IngressClass", ingResource.Namespace, ingResource.Name) continue } diff --git a/controller/ingress/ingress.go b/controller/ingress/ingress.go index 22f076a6..a4abe53d 100644 --- a/controller/ingress/ingress.go +++ b/controller/ingress/ingress.go @@ -35,17 +35,24 @@ type Ingress struct { sslPassthrough bool } -func New(i *store.Ingress, class string, emptyClass bool) *Ingress { - return &Ingress{resource: i, class: class, emptyClass: emptyClass} +// New returns an Ingress instance to handle the k8s ingress resource given in params. +// If the k8s ingress resource is not assigned to the controller (no matching IngressClass) +// then New will return nil +func New(k store.K8s, resource *store.Ingress, class string, emptyClass bool) *Ingress { + i := &Ingress{resource: resource, class: class, emptyClass: emptyClass} + if i.resource == nil || !i.supported(k) { + return nil + } + return i } -// Supported verifies if the IngressClass matches the ControllerClass +// supported verifies if the IngressClass matches the ControllerClass // and in such case returns true otherwise false // // According to https://github.com/kubernetes/api/blob/master/networking/v1/types.go#L257 // ingress.class annotation should have precedence over the IngressClass mechanism implemented // in "networking.k8s.io". -func (i Ingress) Supported(k8s store.K8s) bool { +func (i Ingress) supported(k8s store.K8s) bool { var igClass *store.IngressClass igClassAnn := annotations.String("ingress.class", i.resource.Annotations) diff --git a/controller/ingress/status.go b/controller/ingress/status.go index 609864eb..2252e11b 100644 --- a/controller/ingress/status.go +++ b/controller/ingress/status.go @@ -17,19 +17,25 @@ import ( ) func UpdateStatus(client *kubernetes.Clientset, k store.K8s, class string, emptyClass bool, channel chan Sync) { + var i *Ingress addresses := []string{} for sync := range channel { // Published Service updated: Update all Ingresses if sync.Service != nil && getServiceAddresses(sync.Service, &addresses) { logger.Debug("Addresses of Ingress Controller service changed, status of all ingress resources are going to be updated") for _, ns := range k.Namespaces { + if !ns.Relevant { + continue + } for _, ingress := range k.Namespaces[ns.Name].Ingresses { - logger.Error(New(ingress, class, emptyClass).updateStatus(client, addresses)) + if i = New(k, ingress, class, emptyClass); i != nil { + logger.Error(i.updateStatus(client, addresses)) + } } } - } else if sync.Ingress != nil { + } else if i = New(k, sync.Ingress, class, emptyClass); i != nil { // Update single Ingress - logger.Error(New(sync.Ingress, class, emptyClass).updateStatus(client, addresses)) + logger.Error(i.updateStatus(client, addresses)) } } }