Skip to content

Commit 99b6ac3

Browse files
committed
BUG/MEDIUM: Update only status of assigned Ingress resources
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.
1 parent bcebb14 commit 99b6ac3

File tree

5 files changed

+25
-31
lines changed

5 files changed

+25
-31
lines changed

controller/controller.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ import (
2525
"github.com/haproxytech/kubernetes-ingress/controller/haproxy"
2626
"github.com/haproxytech/kubernetes-ingress/controller/haproxy/api"
2727
"github.com/haproxytech/kubernetes-ingress/controller/route"
28-
"github.com/haproxytech/kubernetes-ingress/controller/status"
2928
"github.com/haproxytech/kubernetes-ingress/controller/store"
3029
"github.com/haproxytech/kubernetes-ingress/controller/utils"
3130
)
@@ -39,7 +38,7 @@ type HAProxyController struct {
3938
PublishService *utils.NamespaceValue
4039
AuxCfgModTime int64
4140
eventChan chan SyncDataEvent
42-
statusChan chan status.SyncIngress
41+
statusChan chan SyncIngress
4342
k8s *K8s
4443
ready bool
4544
reload bool
@@ -118,8 +117,8 @@ func (c *HAProxyController) Start() {
118117
go c.monitorChanges()
119118
if c.PublishService != nil {
120119
// Update Ingress status
121-
c.statusChan = make(chan status.SyncIngress, watch.DefaultChanSize*6)
122-
go status.UpdateIngress(c.k8s.API, c.Store, c.statusChan)
120+
c.statusChan = make(chan SyncIngress, watch.DefaultChanSize*6)
121+
go c.UpdateIngress()
123122
}
124123
}
125124

@@ -166,7 +165,7 @@ func (c *HAProxyController) updateHAProxy() {
166165
}
167166
if c.PublishService != nil && ingress.Status == ADDED {
168167
select {
169-
case c.statusChan <- status.SyncIngress{Ingress: ingress}:
168+
case c.statusChan <- SyncIngress{Ingress: ingress}:
170169
default:
171170
logger.Errorf("Ingress %s/%s: unable to sync status: sync channel full", ingress.Namespace, ingress.Name)
172171
}

controller/status/ingress.go renamed to controller/ingress-status.go

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package status
1+
package controller
22

33
import (
44
"context"
@@ -16,20 +16,23 @@ import (
1616
"github.com/haproxytech/kubernetes-ingress/controller/store"
1717
)
1818

19-
func UpdateIngress(client *kubernetes.Clientset, k store.K8s, channel chan SyncIngress) {
19+
func (c *HAProxyController) UpdateIngress() {
2020
addresses := []string{}
21-
for status := range channel {
21+
for status := range c.statusChan {
2222
// Published Service updated: Update all Ingresses
2323
if status.Service != nil && getServiceAddresses(status.Service, &addresses) {
2424
logger.Debug("Addresses of Ingress Controller service changed, status of all ingress resources are going to be updated")
25-
for _, ns := range k.Namespaces {
26-
for _, ingress := range k.Namespaces[ns.Name].Ingresses {
27-
logger.Error(updateIngressStatus(client, ingress, addresses))
25+
for _, ns := range c.Store.Namespaces {
26+
for _, ingress := range c.Store.Namespaces[ns.Name].Ingresses {
27+
if !c.igClassIsSupported(ingress) {
28+
continue
29+
}
30+
logger.Error(updateIngressStatus(c.k8s.API, ingress, addresses))
2831
}
2932
}
3033
}
3134
if status.Ingress != nil {
32-
logger.Error(updateIngressStatus(client, status.Ingress, addresses))
35+
logger.Error(updateIngressStatus(c.k8s.API, status.Ingress, addresses))
3336
}
3437
}
3538
}

controller/kubernetes.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ import (
2323
"k8s.io/client-go/tools/cache"
2424
"k8s.io/client-go/tools/clientcmd"
2525

26-
ingstatus "github.com/haproxytech/kubernetes-ingress/controller/status"
2726
"github.com/haproxytech/kubernetes-ingress/controller/store"
2827
"github.com/haproxytech/kubernetes-ingress/controller/utils"
2928
)
@@ -336,7 +335,7 @@ func (k *K8s) EventsIngresses(channel chan SyncDataEvent, stop chan struct{}, in
336335
go informer.Run(stop)
337336
}
338337

339-
func (k *K8s) EventsServices(channel chan SyncDataEvent, ingChan chan ingstatus.SyncIngress, stop chan struct{}, informer cache.SharedIndexInformer, publishSvc *utils.NamespaceValue) {
338+
func (k *K8s) EventsServices(channel chan SyncDataEvent, ingChan chan SyncIngress, stop chan struct{}, informer cache.SharedIndexInformer, publishSvc *utils.NamespaceValue) {
340339
informer.AddEventHandler(cache.ResourceEventHandlerFuncs{
341340
AddFunc: func(obj interface{}) {
342341
data, ok := obj.(*corev1.Service)
@@ -374,7 +373,7 @@ func (k *K8s) EventsServices(channel chan SyncDataEvent, ingChan chan ingstatus.
374373
k.Logger.Tracef("%s %s: %s", SERVICE, item.Status, item.Name)
375374
channel <- SyncDataEvent{SyncType: SERVICE, Namespace: item.Namespace, Data: item}
376375
if publishSvc != nil && publishSvc.Namespace == data.Namespace && publishSvc.Name == data.Name {
377-
ingChan <- ingstatus.SyncIngress{Service: data}
376+
ingChan <- SyncIngress{Service: data}
378377
}
379378
},
380379
DeleteFunc: func(obj interface{}) {
@@ -400,7 +399,7 @@ func (k *K8s) EventsServices(channel chan SyncDataEvent, ingChan chan ingstatus.
400399
k.Logger.Tracef("%s %s: %s", SERVICE, item.Status, item.Name)
401400
channel <- SyncDataEvent{SyncType: SERVICE, Namespace: item.Namespace, Data: item}
402401
if publishSvc != nil && publishSvc.Namespace == data.Namespace && publishSvc.Name == data.Name {
403-
ingChan <- ingstatus.SyncIngress{Service: data}
402+
ingChan <- SyncIngress{Service: data}
404403
}
405404
},
406405
UpdateFunc: func(oldObj, newObj interface{}) {
@@ -423,7 +422,7 @@ func (k *K8s) EventsServices(channel chan SyncDataEvent, ingChan chan ingstatus.
423422
return
424423
}
425424
if publishSvc != nil && publishSvc.Namespace == data2.Namespace && publishSvc.Name == data2.Name {
426-
ingChan <- ingstatus.SyncIngress{Service: data2}
425+
ingChan <- SyncIngress{Service: data2}
427426
}
428427
status := MODIFIED
429428
item1 := &store.Service{

controller/status/status.go

Lines changed: 0 additions & 14 deletions
This file was deleted.

controller/types.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
package controller
1616

1717
import (
18+
corev1 "k8s.io/api/core/v1"
19+
1820
"github.com/haproxytech/kubernetes-ingress/controller/store"
1921
"github.com/haproxytech/kubernetes-ingress/controller/utils"
2022
)
@@ -30,6 +32,11 @@ type SyncDataEvent struct {
3032
Data interface{}
3133
}
3234

35+
type SyncIngress struct {
36+
Service *corev1.Service
37+
Ingress *store.Ingress
38+
}
39+
3340
type Mode string
3441

3542
//nolint:golint,stylecheck

0 commit comments

Comments
 (0)