Skip to content

Commit 07e10cd

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 cb71dd2 commit 07e10cd

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

@@ -87,9 +87,6 @@ func (i *Ingress) handlePath(k store.K8s, cfg *configuration.ControllerCfg, api
8787
if err != nil {
8888
return
8989
}
90-
if path.Status == store.DELETED {
91-
return
92-
}
9390
// Backend
9491
backendReload, err := svc.HandleBackend(api, k)
9592
if err != nil {
@@ -198,9 +195,6 @@ func (i *Ingress) Update(k store.K8s, cfg *configuration.ControllerCfg, api api.
198195
// Ingress secrets
199196
logger.Tracef("Ingress '%s/%s': processing secrets...", i.resource.Namespace, i.resource.Name)
200197
for _, tls := range i.resource.TLS {
201-
if tls.Status == store.DELETED {
202-
continue
203-
}
204198
secret, secErr := k.GetSecret(i.resource.Namespace, tls.SecretName)
205199
if secErr != nil {
206200
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

@@ -167,12 +157,6 @@ func (n ingressNetworkingV1Beta1Strategy) ConvertClass() *IngressClass {
167157
APIVersion: NETWORKINGV1BETA1,
168158
Name: n.class.GetName(),
169159
Controller: n.class.Spec.Controller,
170-
Status: func() Status {
171-
if n.class.ObjectMeta.GetDeletionTimestamp() != nil {
172-
return DELETED
173-
}
174-
return ADDED
175-
}(),
176160
}
177161
}
178162

@@ -208,7 +192,6 @@ func (e ingressExtensionsStrategy) ConvertIngress() *Ingress {
208192
SvcName: k8sPath.Backend.ServiceName,
209193
SvcPortInt: int64(k8sPath.Backend.ServicePort.IntValue()),
210194
SvcPortString: k8sPath.Backend.ServicePort.StrVal,
211-
Status: "",
212195
}
213196
}
214197
if rule, ok := rules[k8sRule.Host]; ok {
@@ -217,9 +200,8 @@ func (e ingressExtensionsStrategy) ConvertIngress() *Ingress {
217200
}
218201
} else {
219202
rules[k8sRule.Host] = &IngressRule{
220-
Host: k8sRule.Host,
221-
Paths: paths,
222-
Status: "",
203+
Host: k8sRule.Host,
204+
Paths: paths,
223205
}
224206
}
225207
}
@@ -235,7 +217,6 @@ func (e ingressExtensionsStrategy) ConvertIngress() *Ingress {
235217
SvcPortInt: int64(ingressBackend.ServicePort.IntValue()),
236218
SvcPortString: ingressBackend.ServicePort.StrVal,
237219
IsDefaultBackend: true,
238-
Status: "",
239220
}
240221
}(e.ig.Spec.Backend),
241222
TLS: func(ingressTLS []extensionsv1beta1.IngressTLS) map[string]*IngressTLS {
@@ -245,18 +226,11 @@ func (e ingressExtensionsStrategy) ConvertIngress() *Ingress {
245226
tls[host] = &IngressTLS{
246227
Host: host,
247228
SecretName: k8sTLS.SecretName,
248-
Status: EMPTY,
249229
}
250230
}
251231
}
252232
return tls
253233
}(e.ig.Spec.TLS),
254-
Status: func() Status {
255-
if e.ig.ObjectMeta.GetDeletionTimestamp() != nil {
256-
return DELETED
257-
}
258-
return ADDED
259-
}(),
260234
}
261235
}
262236

@@ -292,7 +266,6 @@ func (n ingressNetworkingV1Strategy) ConvertIngress() *Ingress {
292266
Path: k8sPath.Path,
293267
PathTypeMatch: pathType,
294268
SvcNamespace: n.ig.GetNamespace(),
295-
Status: "",
296269
}
297270
if k8sPath.Backend.Service != nil {
298271
paths[pathKey].SvcName = k8sPath.Backend.Service.Name
@@ -306,9 +279,8 @@ func (n ingressNetworkingV1Strategy) ConvertIngress() *Ingress {
306279
}
307280
} else {
308281
rules[k8sRule.Host] = &IngressRule{
309-
Host: k8sRule.Host,
310-
Paths: paths,
311-
Status: "",
282+
Host: k8sRule.Host,
283+
Paths: paths,
312284
}
313285
}
314286
}
@@ -321,7 +293,6 @@ func (n ingressNetworkingV1Strategy) ConvertIngress() *Ingress {
321293
ingPath := &IngressPath{
322294
SvcNamespace: n.ig.GetNamespace(),
323295
IsDefaultBackend: true,
324-
Status: "",
325296
}
326297
if ingressBackend.Service != nil {
327298
ingPath.SvcName = ingressBackend.Service.Name
@@ -337,18 +308,11 @@ func (n ingressNetworkingV1Strategy) ConvertIngress() *Ingress {
337308
tls[host] = &IngressTLS{
338309
Host: host,
339310
SecretName: k8sTLS.SecretName,
340-
Status: EMPTY,
341311
}
342312
}
343313
}
344314
return tls
345315
}(n.ig.Spec.TLS),
346-
Status: func() Status {
347-
if n.ig.ObjectMeta.GetDeletionTimestamp() != nil {
348-
return DELETED
349-
}
350-
return ADDED
351-
}(),
352316
}
353317
}
354318

@@ -357,12 +321,6 @@ func (n ingressNetworkingV1Strategy) ConvertClass() *IngressClass {
357321
APIVersion: NETWORKINGV1,
358322
Name: n.class.GetName(),
359323
Controller: n.class.Spec.Controller,
360-
Status: func() Status {
361-
if n.class.ObjectMeta.GetDeletionTimestamp() != nil {
362-
return DELETED
363-
}
364-
return ADDED
365-
}(),
366324
}
367325
}
368326

0 commit comments

Comments
 (0)