From f693ebd2b0fa6a0ab7c0da8f306d7a59a51a3690 Mon Sep 17 00:00:00 2001 From: Lukasz Zajaczkowski Date: Wed, 11 Sep 2024 14:10:33 +0200 Subject: [PATCH] fix cache when error occurs --- pkg/controller/service/reconciler_status.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/pkg/controller/service/reconciler_status.go b/pkg/controller/service/reconciler_status.go index 4207fdee..b01516e0 100644 --- a/pkg/controller/service/reconciler_status.go +++ b/pkg/controller/service/reconciler_status.go @@ -91,11 +91,24 @@ func (s *ServiceReconciler) UpdateApplyStatus( statusCollector.updateApplyStatus(e.ApplyEvent.Identifier, e.ApplyEvent) gk := e.ApplyEvent.Identifier.GroupKind name := e.ApplyEvent.Identifier.Name + namespace := e.ApplyEvent.Identifier.Namespace if e.ApplyEvent.Status == event.ApplySuccessful { cache.SaveResourceSHA(e.ApplyEvent.Resource, cache.ApplySHA) } if e.ApplyEvent.Error != nil { + // e.ApplyEvent.Resource == nil, create the key to get cache entry + key := cache.ResourceKey{ + Namespace: namespace, + Name: name, + GroupKind: gk, + } + sha, exists := cache.GetResourceCache().GetCacheEntry(key.ObjectIdentifier()) + if exists { + // clear SHA when error occurs + sha.Expire() + cache.GetResourceCache().SetCacheEntry(key.ObjectIdentifier(), sha) + } if e.ApplyEvent.Status == event.ApplyFailed { err = fmt.Errorf("%s apply %s: %s\n", resourceIDToString(gk, name), strings.ToLower(e.ApplyEvent.Status.String()), e.ApplyEvent.Error.Error())