From 3c0e94dab36ecf53ce01fb2bbe834f6b848640be Mon Sep 17 00:00:00 2001 From: huiwq1990 Date: Fri, 8 Apr 2022 12:00:18 +0800 Subject: [PATCH] support configmap delete (#791) --- pkg/yurthub/cachemanager/cache_agent.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/pkg/yurthub/cachemanager/cache_agent.go b/pkg/yurthub/cachemanager/cache_agent.go index c3117079bf2..102293a0f7d 100644 --- a/pkg/yurthub/cachemanager/cache_agent.go +++ b/pkg/yurthub/cachemanager/cache_agent.go @@ -39,6 +39,7 @@ func (cm *cacheManager) initCacheAgents() error { configmapInformer.AddEventHandler(cache.ResourceEventHandlerFuncs{ AddFunc: cm.addConfigmap, UpdateFunc: cm.updateConfigmap, + DeleteFunc: cm.deleteConfigmap, }) klog.Infof("init cache agents to %v", cm.cacheAgents) @@ -74,6 +75,16 @@ func (cm *cacheManager) updateConfigmap(oldObj, newObj interface{}) { cm.deleteAgentCache(deletedAgents) } +func (cm *cacheManager) deleteConfigmap(obj interface{}) { + _, ok := obj.(*corev1.ConfigMap) + if !ok { + return + } + + deletedAgents := cm.updateCacheAgents("", "delete") + cm.deleteAgentCache(deletedAgents) +} + // updateCacheAgents update cache agents func (cm *cacheManager) updateCacheAgents(cacheAgents, action string) sets.String { newAgents := sets.NewString()