Skip to content

Commit 0a24262

Browse files
committed
MEDIUM: Don't skip any Ingress event
When an ingress resource is received from k8s, IC controller used to verify if the resource is different from the one in the cache (if there is any) before starting the sync method. This verification process is complex and not easy to maintain and also seemed to result in some missed information in the cache (like missing ingress rules in the cached Ingress resource). In this commit the verification has been removed which means an ingress update from k8s will always trigger the sync method. This will guarantee that we don't miss any update but also increases the risk of triggering the sync method for no reason in case the k8s update is irrelevant.
1 parent 60f0218 commit 0a24262

File tree

10 files changed

+37
-420
lines changed

10 files changed

+37
-420
lines changed

controller/annotations/ingress/httpsRedirect.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,8 @@ func tlsEnabled(ingress *store.Ingress) bool {
9090
if ingress == nil {
9191
return false
9292
}
93-
for _, tls := range ingress.TLS {
94-
if tls.Status != store.DELETED {
95-
return true
96-
}
93+
if len(ingress.TLS) == 0 {
94+
return false
9795
}
98-
return false
96+
return true
9997
}

controller/controller.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -160,9 +160,6 @@ func (c *HAProxyController) updateHAProxy() {
160160
continue
161161
}
162162
for _, ingResource := range namespace.Ingresses {
163-
if ingResource.Status == DELETED {
164-
continue
165-
}
166163
i := ingress.New(c.Store, ingResource, c.OSArgs.IngressClass, c.OSArgs.EmptyIngressClass)
167164
if i == nil {
168165
logger.Debugf("ingress '%s/%s' ignored: no matching IngressClass", ingResource.Namespace, ingResource.Name)

controller/ingress/ingress.go

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ func New(k store.K8s, resource *store.Ingress, class string, emptyClass bool) *I
5656
func (i Ingress) supported(k8s store.K8s) (supported bool) {
5757
var igClassAnn, igClassSpec string
5858
igClassAnn = annotations.String("ingress.class", i.resource.Annotations)
59-
if igClassResource := k8s.IngressClasses[i.resource.Class]; igClassResource != nil && igClassResource.Status != store.DELETED {
59+
if igClassResource := k8s.IngressClasses[i.resource.Class]; igClassResource != nil {
6060
igClassSpec = igClassResource.Controller
6161
}
6262
if igClassAnn == "" && i.resource.Class == "" {
@@ -99,9 +99,6 @@ func (i *Ingress) handlePath(k store.K8s, cfg *configuration.ControllerCfg, api
9999
if err != nil {
100100
return
101101
}
102-
if path.Status == store.DELETED {
103-
return
104-
}
105102
// Backend
106103
backendReload, err := svc.HandleBackend(api, k)
107104
if err != nil {
@@ -210,9 +207,6 @@ func (i *Ingress) Update(k store.K8s, cfg *configuration.ControllerCfg, api api.
210207
// Ingress secrets
211208
logger.Tracef("Ingress '%s/%s': processing secrets...", i.resource.Namespace, i.resource.Name)
212209
for _, tls := range i.resource.TLS {
213-
if tls.Status == store.DELETED {
214-
continue
215-
}
216210
secret, secErr := k.GetSecret(i.resource.Namespace, tls.SecretName)
217211
if secErr != nil {
218212
logger.Warningf("Ingress '%s/%s': %s", i.resource.Namespace, i.resource.Name, secErr)

controller/kubernetes.go

Lines changed: 8 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -385,25 +385,15 @@ func (k *K8s) EventsIngressClass(channel chan SyncDataEvent, stop chan struct{},
385385
channel <- SyncDataEvent{SyncType: INGRESS_CLASS, Data: item}
386386
},
387387
UpdateFunc: func(oldObj, newObj interface{}) {
388-
item1, err := store.ConvertToIngressClass(oldObj)
389-
if err != nil {
390-
k.Logger.Errorf("%s: Invalid data from k8s api, %s", INGRESS_CLASS, oldObj)
391-
return
392-
}
393-
item1.Status = MODIFIED
394-
395-
item2, err := store.ConvertToIngressClass(newObj)
388+
item, err := store.ConvertToIngressClass(newObj)
396389
if err != nil {
397390
k.Logger.Errorf("%s: Invalid data from k8s api, %s", INGRESS, oldObj)
398391
return
399392
}
400-
item1.Status = MODIFIED
393+
item.Status = MODIFIED
401394

402-
if item2.Equal(item1) {
403-
return
404-
}
405-
k.Logger.Tracef("%s %s: %s", INGRESS_CLASS, item2.Status, item2.Name)
406-
channel <- SyncDataEvent{SyncType: INGRESS_CLASS, Data: item2}
395+
k.Logger.Tracef("%s %s: %s", INGRESS_CLASS, item.Status, item.Name)
396+
channel <- SyncDataEvent{SyncType: INGRESS_CLASS, Data: item}
407397
},
408398
},
409399
)
@@ -433,25 +423,14 @@ func (k *K8s) EventsIngresses(channel chan SyncDataEvent, stop chan struct{}, in
433423
channel <- SyncDataEvent{SyncType: INGRESS, Namespace: item.Namespace, Data: item}
434424
},
435425
UpdateFunc: func(oldObj, newObj interface{}) {
436-
item1, err := store.ConvertToIngress(oldObj)
437-
if err != nil {
438-
k.Logger.Errorf("%s: Invalid data from k8s api, %s", INGRESS, oldObj)
439-
return
440-
}
441-
item1.Status = MODIFIED
442-
443-
item2, err := store.ConvertToIngress(newObj)
426+
item, err := store.ConvertToIngress(newObj)
444427
if err != nil {
445428
k.Logger.Errorf("%s: Invalid data from k8s api, %s", INGRESS, oldObj)
446429
return
447430
}
448-
item1.Status = MODIFIED
449-
450-
if item2.Equal(item1) {
451-
return
452-
}
453-
k.Logger.Tracef("%s %s: %s", INGRESS, item2.Status, item2.Name)
454-
channel <- SyncDataEvent{SyncType: INGRESS, Namespace: item2.Namespace, Data: item2}
431+
item.Status = MODIFIED
432+
k.Logger.Tracef("%s %s: %s", INGRESS, item.Status, item.Name)
433+
channel <- SyncDataEvent{SyncType: INGRESS, Namespace: item.Namespace, Data: item}
455434
},
456435
},
457436
)

controller/monitor.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ func (c *HAProxyController) SyncData() {
113113
case NAMESPACE:
114114
change = c.Store.EventNamespace(ns, job.Data.(*store.Namespace))
115115
case INGRESS:
116-
change = c.Store.EventIngress(ns, job.Data.(*store.Ingress), c.OSArgs.IngressClass)
116+
change = c.Store.EventIngress(ns, job.Data.(*store.Ingress))
117117
case INGRESS_CLASS:
118118
change = c.Store.EventIngressClass(job.Data.(*store.IngressClass))
119119
case ENDPOINTS:

controller/store/convert.go

Lines changed: 6 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,6 @@ func (n ingressNetworkingV1Beta1Strategy) ConvertIngress() *Ingress {
110110
SvcName: k8sPath.Backend.ServiceName,
111111
SvcPortInt: int64(k8sPath.Backend.ServicePort.IntValue()),
112112
SvcPortString: k8sPath.Backend.ServicePort.StrVal,
113-
Status: "",
114113
}
115114
}
116115
if rule, ok := rules[k8sRule.Host]; ok {
@@ -119,9 +118,8 @@ func (n ingressNetworkingV1Beta1Strategy) ConvertIngress() *Ingress {
119118
}
120119
} else {
121120
rules[k8sRule.Host] = &IngressRule{
122-
Host: k8sRule.Host,
123-
Paths: paths,
124-
Status: "",
121+
Host: k8sRule.Host,
122+
Paths: paths,
125123
}
126124
}
127125
}
@@ -137,7 +135,6 @@ func (n ingressNetworkingV1Beta1Strategy) ConvertIngress() *Ingress {
137135
SvcPortInt: int64(ingressBackend.ServicePort.IntValue()),
138136
SvcPortString: ingressBackend.ServicePort.StrVal,
139137
IsDefaultBackend: true,
140-
Status: "",
141138
}
142139
}(n.ig.Spec.Backend),
143140
TLS: func(ingressTLS []networkingv1beta1.IngressTLS) map[string]*IngressTLS {
@@ -147,18 +144,11 @@ func (n ingressNetworkingV1Beta1Strategy) ConvertIngress() *Ingress {
147144
tls[host] = &IngressTLS{
148145
Host: host,
149146
SecretName: k8sTLS.SecretName,
150-
Status: EMPTY,
151147
}
152148
}
153149
}
154150
return tls
155151
}(n.ig.Spec.TLS),
156-
Status: func() Status {
157-
if n.ig.ObjectMeta.GetDeletionTimestamp() != nil {
158-
return DELETED
159-
}
160-
return ADDED
161-
}(),
162152
}
163153
}
164154

@@ -172,12 +162,6 @@ func (n ingressNetworkingV1Beta1Strategy) ConvertClass() *IngressClass {
172162
Name: n.class.GetName(),
173163
Controller: n.class.Spec.Controller,
174164
Annotations: annotations,
175-
Status: func() Status {
176-
if n.class.ObjectMeta.GetDeletionTimestamp() != nil {
177-
return DELETED
178-
}
179-
return ADDED
180-
}(),
181165
}
182166
}
183167

@@ -213,7 +197,6 @@ func (e ingressExtensionsStrategy) ConvertIngress() *Ingress {
213197
SvcName: k8sPath.Backend.ServiceName,
214198
SvcPortInt: int64(k8sPath.Backend.ServicePort.IntValue()),
215199
SvcPortString: k8sPath.Backend.ServicePort.StrVal,
216-
Status: "",
217200
}
218201
}
219202
if rule, ok := rules[k8sRule.Host]; ok {
@@ -222,9 +205,8 @@ func (e ingressExtensionsStrategy) ConvertIngress() *Ingress {
222205
}
223206
} else {
224207
rules[k8sRule.Host] = &IngressRule{
225-
Host: k8sRule.Host,
226-
Paths: paths,
227-
Status: "",
208+
Host: k8sRule.Host,
209+
Paths: paths,
228210
}
229211
}
230212
}
@@ -240,7 +222,6 @@ func (e ingressExtensionsStrategy) ConvertIngress() *Ingress {
240222
SvcPortInt: int64(ingressBackend.ServicePort.IntValue()),
241223
SvcPortString: ingressBackend.ServicePort.StrVal,
242224
IsDefaultBackend: true,
243-
Status: "",
244225
}
245226
}(e.ig.Spec.Backend),
246227
TLS: func(ingressTLS []extensionsv1beta1.IngressTLS) map[string]*IngressTLS {
@@ -250,18 +231,11 @@ func (e ingressExtensionsStrategy) ConvertIngress() *Ingress {
250231
tls[host] = &IngressTLS{
251232
Host: host,
252233
SecretName: k8sTLS.SecretName,
253-
Status: EMPTY,
254234
}
255235
}
256236
}
257237
return tls
258238
}(e.ig.Spec.TLS),
259-
Status: func() Status {
260-
if e.ig.ObjectMeta.GetDeletionTimestamp() != nil {
261-
return DELETED
262-
}
263-
return ADDED
264-
}(),
265239
}
266240
}
267241

@@ -297,7 +271,6 @@ func (n ingressNetworkingV1Strategy) ConvertIngress() *Ingress {
297271
Path: k8sPath.Path,
298272
PathTypeMatch: pathType,
299273
SvcNamespace: n.ig.GetNamespace(),
300-
Status: "",
301274
}
302275
if k8sPath.Backend.Service != nil {
303276
paths[pathKey].SvcName = k8sPath.Backend.Service.Name
@@ -311,9 +284,8 @@ func (n ingressNetworkingV1Strategy) ConvertIngress() *Ingress {
311284
}
312285
} else {
313286
rules[k8sRule.Host] = &IngressRule{
314-
Host: k8sRule.Host,
315-
Paths: paths,
316-
Status: "",
287+
Host: k8sRule.Host,
288+
Paths: paths,
317289
}
318290
}
319291
}
@@ -326,7 +298,6 @@ func (n ingressNetworkingV1Strategy) ConvertIngress() *Ingress {
326298
ingPath := &IngressPath{
327299
SvcNamespace: n.ig.GetNamespace(),
328300
IsDefaultBackend: true,
329-
Status: "",
330301
}
331302
if ingressBackend.Service != nil {
332303
ingPath.SvcName = ingressBackend.Service.Name
@@ -342,18 +313,11 @@ func (n ingressNetworkingV1Strategy) ConvertIngress() *Ingress {
342313
tls[host] = &IngressTLS{
343314
Host: host,
344315
SecretName: k8sTLS.SecretName,
345-
Status: EMPTY,
346316
}
347317
}
348318
}
349319
return tls
350320
}(n.ig.Spec.TLS),
351-
Status: func() Status {
352-
if n.ig.ObjectMeta.GetDeletionTimestamp() != nil {
353-
return DELETED
354-
}
355-
return ADDED
356-
}(),
357321
}
358322
}
359323

@@ -367,12 +331,6 @@ func (n ingressNetworkingV1Strategy) ConvertClass() *IngressClass {
367331
Name: n.class.GetName(),
368332
Controller: n.class.Spec.Controller,
369333
Annotations: annotations,
370-
Status: func() Status {
371-
if n.class.ObjectMeta.GetDeletionTimestamp() != nil {
372-
return DELETED
373-
}
374-
return ADDED
375-
}(),
376334
}
377335
}
378336

0 commit comments

Comments
 (0)