From ae2ec82376c4efa073db15db05d377b68b59752e Mon Sep 17 00:00:00 2001 From: Joel Speed Date: Mon, 9 Dec 2024 15:50:19 +0000 Subject: [PATCH] Prevent panic when informer receives cache.DeletedFinalStateUnknown --- pkg/provider/azure_local_services.go | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/pkg/provider/azure_local_services.go b/pkg/provider/azure_local_services.go index 0febc94edb..cf83433cb8 100644 --- a/pkg/provider/azure_local_services.go +++ b/pkg/provider/azure_local_services.go @@ -356,7 +356,23 @@ func (az *Cloud) setUpEndpointSlicesInformer(informerFactory informers.SharedInf } }, DeleteFunc: func(obj interface{}) { - es := obj.(*discovery_v1.EndpointSlice) + var es *discovery_v1.EndpointSlice + switch v := obj.(type) { + case *discovery_v1.EndpointSlice: + es = v + case cache.DeletedFinalStateUnknown: + // We may miss the deletion event if the watch stream is diconnected and the object is deleted. + var ok bool + es, ok = v.Obj.(*discovery_v1.EndpointSlice) + if !ok { + klog.Errorf("Cannot convert to *discovery_v1.EndpointSlice: %T", v.Obj) + return + } + default: + klog.Errorf("Cannot convert to *discovery_v1.EndpointSlice: %T", v) + return + } + az.endpointSlicesCache.Delete(strings.ToLower(fmt.Sprintf("%s/%s", es.Namespace, es.Name))) }, })