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
  • Loading branch information
Mo3m3n committed Nov 4, 2021
1 parent b18b6c2 commit 26349eb
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 9 deletions.
4 changes: 2 additions & 2 deletions controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
15 changes: 11 additions & 4 deletions controller/ingress/ingress.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
12 changes: 9 additions & 3 deletions controller/ingress/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
}
}
Expand Down

0 comments on commit 26349eb

Please sign in to comment.