From 9a7f73097e0dbf9ad6e21e3d045f0e0921f2e278 Mon Sep 17 00:00:00 2001 From: Joel Speed Date: Mon, 6 Jan 2025 18:02:17 +0700 Subject: [PATCH] Prevent panic when informer receives cache.DeletedFinalStateUnknown (#7776) --- 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 5abf546c26..137e7feb92 100644 --- a/pkg/provider/azure_local_services.go +++ b/pkg/provider/azure_local_services.go @@ -351,7 +351,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))) }, })