From 4c6ae695c83ad9d6ddedc3707573dc450d409fb6 Mon Sep 17 00:00:00 2001 From: k8s-infra-cherrypick-robot <90416843+k8s-infra-cherrypick-robot@users.noreply.github.com> Date: Thu, 9 Jan 2025 01:28:31 -0800 Subject: [PATCH] Prevent panic when informer receives cache.DeletedFinalStateUnknown (#7985) Co-authored-by: Joel Speed --- 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 a413b366da..42634284f1 100644 --- a/pkg/provider/azure_local_services.go +++ b/pkg/provider/azure_local_services.go @@ -357,7 +357,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 disconnected 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))) }, })