Skip to content

Commit 624441d

Browse files
committed
BUG: fix crash on UPDATE events when old item is nil
1 parent 62bdc50 commit 624441d

File tree

1 file changed

+28
-5
lines changed

1 file changed

+28
-5
lines changed

pkg/store/events.go

+28-5
Original file line numberDiff line numberDiff line change
@@ -152,8 +152,11 @@ func (k *K8s) EventService(ns *Namespace, data *Service) (updateRequired bool) {
152152
newService := data
153153
oldService, ok := ns.Services[data.Name]
154154
if !ok {
155-
// intentionally do not add it. TODO see if our idea of only watching is ok
155+
// It can happen (resync) that we receive an UPDATE on a item that is not yet registered
156+
// We should treat it as a CREATE.
156157
logger.Warningf("Service '%s' not registered with controller !", data.Name)
158+
data.Status = ADDED
159+
return k.EventService(ns, data)
157160
}
158161
if oldService.Equal(newService) {
159162
return updateRequired
@@ -235,9 +238,11 @@ func (k *K8s) EventSecret(ns *Namespace, data *Secret) (updateRequired bool) {
235238
newSecret := data
236239
oldSecret, ok := ns.Secret[data.Name]
237240
if !ok {
238-
// intentionally do not add it. TODO see if our idea of only watching is ok
241+
// It can happen (resync) that we receive an UPDATE on a item that is not yet registered
242+
// We should treat it as a CREATE.
239243
logger.Warningf("Secret '%s' not registered with controller !", data.Name)
240-
return updateRequired
244+
data.Status = ADDED
245+
return k.EventSecret(ns, data)
241246
}
242247
if oldSecret.Equal(data) {
243248
return updateRequired
@@ -325,8 +330,11 @@ func (k *K8s) EventPublishService(ns *Namespace, data *Service) (updateRequired
325330
newService := data
326331
oldService, ok := ns.Services[data.Name]
327332
if !ok {
328-
// intentionally do not add it. TODO see if our idea of only watching is ok
333+
// It can happen (resync) that we receive an UPDATE on a item that is not yet registered
334+
// We should treat it as a CREATE.
329335
logger.Warningf("Service '%s' not registered with controller !", data.Name)
336+
data.Status = ADDED
337+
return k.EventPublishService(ns, data)
330338
}
331339
if oldService.EqualWithAddresses(newService) {
332340
return
@@ -381,7 +389,11 @@ func (k *K8s) EventGatewayClass(data *GatewayClass) (updateRequired bool) {
381389
newGatewayClass := data
382390
oldGatewayClass, ok := k.GatewayClasses[data.Name]
383391
if !ok {
392+
// It can happen (resync) that we receive an UPDATE on a item that is not yet registered
393+
// We should treat it as a CREATE.
384394
logger.Warningf("Modification of unexisting gatewayclass %s", data.Name)
395+
data.Status = ADDED
396+
return k.EventGatewayClass(data)
385397
}
386398
if ok && oldGatewayClass.Generation == newGatewayClass.Generation ||
387399
newGatewayClass.Equal(oldGatewayClass) {
@@ -412,7 +424,11 @@ func (k *K8s) EventGateway(ns *Namespace, data *Gateway) (updateRequired bool) {
412424
newGateway := data
413425
oldGateway, ok := ns.Gateways[data.Name]
414426
if !ok {
427+
// It can happen (resync) that we receive an UPDATE on a item that is not yet registered
428+
// We should treat it as a CREATE.
415429
logger.Warningf("Modification of unexisting gateway %s", data.Name)
430+
data.Status = ADDED
431+
return k.EventGateway(ns, data)
416432
}
417433
if ok && newGateway.Generation == oldGateway.Generation ||
418434
newGateway.Equal(oldGateway) {
@@ -444,7 +460,11 @@ func (k *K8s) EventTCPRoute(ns *Namespace, data *TCPRoute) (updateRequired bool)
444460
newTCPRoute := data
445461
oldTCPRoute, ok := ns.TCPRoutes[data.Name]
446462
if !ok {
463+
// It can happen (resync) that we receive an UPDATE on a item that is not yet registered
464+
// We should treat it as a CREATE.
447465
logger.Warningf("Modification of unexisting tcproute %s", data.Name)
466+
data.Status = ADDED
467+
return k.EventTCPRoute(ns, data)
448468
}
449469
if ok && newTCPRoute.Generation == oldTCPRoute.Generation ||
450470
newTCPRoute.Equal(oldTCPRoute) {
@@ -475,8 +495,11 @@ func (k *K8s) EventReferenceGrant(ns *Namespace, data *ReferenceGrant) (updateRe
475495
newReferenceGrant := data
476496
oldReferenceGrant, ok := ns.ReferenceGrants[data.Name]
477497
if !ok {
498+
// It can happen (resync) that we receive an UPDATE on a item that is not yet registered
499+
// We should treat it as a CREATE.
478500
logger.Warningf("Modification of unexisting referencegrant %s", data.Name)
479-
return
501+
data.Status = ADDED
502+
return k.EventReferenceGrant(ns, data)
480503
}
481504
if ok && newReferenceGrant.Generation == oldReferenceGrant.Generation ||
482505
newReferenceGrant.Equal(oldReferenceGrant) {

0 commit comments

Comments
 (0)