Skip to content

Commit 26349eb

Browse files
committed
BUG/MEDIUM: Update only status of assigned Ingress resources
1 parent b18b6c2 commit 26349eb

File tree

3 files changed

+22
-9
lines changed

3 files changed

+22
-9
lines changed

controller/controller.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,8 +163,8 @@ func (c *HAProxyController) updateHAProxy() {
163163
if ingResource.Status == DELETED {
164164
continue
165165
}
166-
i := ingress.New(ingResource, c.OSArgs.IngressClass, c.OSArgs.EmptyIngressClass)
167-
if !i.Supported(c.Store) {
166+
i := ingress.New(c.Store, ingResource, c.OSArgs.IngressClass, c.OSArgs.EmptyIngressClass)
167+
if i == nil {
168168
logger.Debugf("ingress '%s/%s' ignored: no matching IngressClass", ingResource.Namespace, ingResource.Name)
169169
continue
170170
}

controller/ingress/ingress.go

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,17 +35,24 @@ type Ingress struct {
3535
sslPassthrough bool
3636
}
3737

38-
func New(i *store.Ingress, class string, emptyClass bool) *Ingress {
39-
return &Ingress{resource: i, class: class, emptyClass: emptyClass}
38+
// New returns an Ingress instance to handle the k8s ingress resource given in params.
39+
// If the k8s ingress resource is not assigned to the controller (no matching IngressClass)
40+
// then New will return nil
41+
func New(k store.K8s, resource *store.Ingress, class string, emptyClass bool) *Ingress {
42+
i := &Ingress{resource: resource, class: class, emptyClass: emptyClass}
43+
if i.resource == nil || !i.supported(k) {
44+
return nil
45+
}
46+
return i
4047
}
4148

42-
// Supported verifies if the IngressClass matches the ControllerClass
49+
// supported verifies if the IngressClass matches the ControllerClass
4350
// and in such case returns true otherwise false
4451
//
4552
// According to https://github.com/kubernetes/api/blob/master/networking/v1/types.go#L257
4653
// ingress.class annotation should have precedence over the IngressClass mechanism implemented
4754
// in "networking.k8s.io".
48-
func (i Ingress) Supported(k8s store.K8s) bool {
55+
func (i Ingress) supported(k8s store.K8s) bool {
4956
var igClass *store.IngressClass
5057
igClassAnn := annotations.String("ingress.class", i.resource.Annotations)
5158

controller/ingress/status.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,25 @@ import (
1717
)
1818

1919
func UpdateStatus(client *kubernetes.Clientset, k store.K8s, class string, emptyClass bool, channel chan Sync) {
20+
var i *Ingress
2021
addresses := []string{}
2122
for sync := range channel {
2223
// Published Service updated: Update all Ingresses
2324
if sync.Service != nil && getServiceAddresses(sync.Service, &addresses) {
2425
logger.Debug("Addresses of Ingress Controller service changed, status of all ingress resources are going to be updated")
2526
for _, ns := range k.Namespaces {
27+
if !ns.Relevant {
28+
continue
29+
}
2630
for _, ingress := range k.Namespaces[ns.Name].Ingresses {
27-
logger.Error(New(ingress, class, emptyClass).updateStatus(client, addresses))
31+
if i = New(k, ingress, class, emptyClass); i != nil {
32+
logger.Error(i.updateStatus(client, addresses))
33+
}
2834
}
2935
}
30-
} else if sync.Ingress != nil {
36+
} else if i = New(k, sync.Ingress, class, emptyClass); i != nil {
3137
// Update single Ingress
32-
logger.Error(New(sync.Ingress, class, emptyClass).updateStatus(client, addresses))
38+
logger.Error(i.updateStatus(client, addresses))
3339
}
3440
}
3541
}

0 commit comments

Comments
 (0)