Skip to content

Commit

Permalink
fix cache when error occurs
Browse files Browse the repository at this point in the history
  • Loading branch information
zreigz committed Sep 11, 2024
1 parent 982ad78 commit f693ebd
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions pkg/controller/service/reconciler_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down

0 comments on commit f693ebd

Please sign in to comment.