Skip to content

Commit

Permalink
BUG/MEDIUM: Update only status of assigned Ingress resources
Browse files Browse the repository at this point in the history
The Ingress code base has diverged between IC 1.6 and newer versions.
Thus instead of backporting this Fix, a different solution was applied
here by moving handling of ingress status into "controller" package where
"igClassIsSupported" can be used to update only status of assigned
Ingresses.
  • Loading branch information
Mo3m3n committed Dec 1, 2021
1 parent bcebb14 commit 99b6ac3
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 31 deletions.
9 changes: 4 additions & 5 deletions controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import (
"github.com/haproxytech/kubernetes-ingress/controller/haproxy"
"github.com/haproxytech/kubernetes-ingress/controller/haproxy/api"
"github.com/haproxytech/kubernetes-ingress/controller/route"
"github.com/haproxytech/kubernetes-ingress/controller/status"
"github.com/haproxytech/kubernetes-ingress/controller/store"
"github.com/haproxytech/kubernetes-ingress/controller/utils"
)
Expand All @@ -39,7 +38,7 @@ type HAProxyController struct {
PublishService *utils.NamespaceValue
AuxCfgModTime int64
eventChan chan SyncDataEvent
statusChan chan status.SyncIngress
statusChan chan SyncIngress
k8s *K8s
ready bool
reload bool
Expand Down Expand Up @@ -118,8 +117,8 @@ func (c *HAProxyController) Start() {
go c.monitorChanges()
if c.PublishService != nil {
// Update Ingress status
c.statusChan = make(chan status.SyncIngress, watch.DefaultChanSize*6)
go status.UpdateIngress(c.k8s.API, c.Store, c.statusChan)
c.statusChan = make(chan SyncIngress, watch.DefaultChanSize*6)
go c.UpdateIngress()
}
}

Expand Down Expand Up @@ -166,7 +165,7 @@ func (c *HAProxyController) updateHAProxy() {
}
if c.PublishService != nil && ingress.Status == ADDED {
select {
case c.statusChan <- status.SyncIngress{Ingress: ingress}:
case c.statusChan <- SyncIngress{Ingress: ingress}:
default:
logger.Errorf("Ingress %s/%s: unable to sync status: sync channel full", ingress.Namespace, ingress.Name)
}
Expand Down
17 changes: 10 additions & 7 deletions controller/status/ingress.go → controller/ingress-status.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package status
package controller

import (
"context"
Expand All @@ -16,20 +16,23 @@ import (
"github.com/haproxytech/kubernetes-ingress/controller/store"
)

func UpdateIngress(client *kubernetes.Clientset, k store.K8s, channel chan SyncIngress) {
func (c *HAProxyController) UpdateIngress() {
addresses := []string{}
for status := range channel {
for status := range c.statusChan {
// Published Service updated: Update all Ingresses
if status.Service != nil && getServiceAddresses(status.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 {
for _, ingress := range k.Namespaces[ns.Name].Ingresses {
logger.Error(updateIngressStatus(client, ingress, addresses))
for _, ns := range c.Store.Namespaces {
for _, ingress := range c.Store.Namespaces[ns.Name].Ingresses {
if !c.igClassIsSupported(ingress) {
continue
}
logger.Error(updateIngressStatus(c.k8s.API, ingress, addresses))
}
}
}
if status.Ingress != nil {
logger.Error(updateIngressStatus(client, status.Ingress, addresses))
logger.Error(updateIngressStatus(c.k8s.API, status.Ingress, addresses))
}
}
}
Expand Down
9 changes: 4 additions & 5 deletions controller/kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import (
"k8s.io/client-go/tools/cache"
"k8s.io/client-go/tools/clientcmd"

ingstatus "github.com/haproxytech/kubernetes-ingress/controller/status"
"github.com/haproxytech/kubernetes-ingress/controller/store"
"github.com/haproxytech/kubernetes-ingress/controller/utils"
)
Expand Down Expand Up @@ -336,7 +335,7 @@ func (k *K8s) EventsIngresses(channel chan SyncDataEvent, stop chan struct{}, in
go informer.Run(stop)
}

func (k *K8s) EventsServices(channel chan SyncDataEvent, ingChan chan ingstatus.SyncIngress, stop chan struct{}, informer cache.SharedIndexInformer, publishSvc *utils.NamespaceValue) {
func (k *K8s) EventsServices(channel chan SyncDataEvent, ingChan chan SyncIngress, stop chan struct{}, informer cache.SharedIndexInformer, publishSvc *utils.NamespaceValue) {
informer.AddEventHandler(cache.ResourceEventHandlerFuncs{
AddFunc: func(obj interface{}) {
data, ok := obj.(*corev1.Service)
Expand Down Expand Up @@ -374,7 +373,7 @@ func (k *K8s) EventsServices(channel chan SyncDataEvent, ingChan chan ingstatus.
k.Logger.Tracef("%s %s: %s", SERVICE, item.Status, item.Name)
channel <- SyncDataEvent{SyncType: SERVICE, Namespace: item.Namespace, Data: item}
if publishSvc != nil && publishSvc.Namespace == data.Namespace && publishSvc.Name == data.Name {
ingChan <- ingstatus.SyncIngress{Service: data}
ingChan <- SyncIngress{Service: data}
}
},
DeleteFunc: func(obj interface{}) {
Expand All @@ -400,7 +399,7 @@ func (k *K8s) EventsServices(channel chan SyncDataEvent, ingChan chan ingstatus.
k.Logger.Tracef("%s %s: %s", SERVICE, item.Status, item.Name)
channel <- SyncDataEvent{SyncType: SERVICE, Namespace: item.Namespace, Data: item}
if publishSvc != nil && publishSvc.Namespace == data.Namespace && publishSvc.Name == data.Name {
ingChan <- ingstatus.SyncIngress{Service: data}
ingChan <- SyncIngress{Service: data}
}
},
UpdateFunc: func(oldObj, newObj interface{}) {
Expand All @@ -423,7 +422,7 @@ func (k *K8s) EventsServices(channel chan SyncDataEvent, ingChan chan ingstatus.
return
}
if publishSvc != nil && publishSvc.Namespace == data2.Namespace && publishSvc.Name == data2.Name {
ingChan <- ingstatus.SyncIngress{Service: data2}
ingChan <- SyncIngress{Service: data2}
}
status := MODIFIED
item1 := &store.Service{
Expand Down
14 changes: 0 additions & 14 deletions controller/status/status.go

This file was deleted.

7 changes: 7 additions & 0 deletions controller/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
package controller

import (
corev1 "k8s.io/api/core/v1"

"github.com/haproxytech/kubernetes-ingress/controller/store"
"github.com/haproxytech/kubernetes-ingress/controller/utils"
)
Expand All @@ -30,6 +32,11 @@ type SyncDataEvent struct {
Data interface{}
}

type SyncIngress struct {
Service *corev1.Service
Ingress *store.Ingress
}

type Mode string

//nolint:golint,stylecheck
Expand Down

0 comments on commit 99b6ac3

Please sign in to comment.