Skip to content

Commit

Permalink
clear cache entry when status == ApplyFailed (#272)
Browse files Browse the repository at this point in the history
  • Loading branch information
zreigz authored Sep 20, 2024
1 parent 9075f68 commit 98627a9
Showing 1 changed file with 12 additions and 13 deletions.
25 changes: 12 additions & 13 deletions pkg/controller/service/reconciler_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,21 +100,20 @@ func (s *ServiceReconciler) UpdateApplyStatus(
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 {
// 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)
}
err = fmt.Errorf("%s apply %s: %s\n", resourceIDToString(gk, name),
strings.ToLower(e.ApplyEvent.Status.String()), e.ApplyEvent.Error.Error())
logger.Error(err, "apply error")
Expand Down

0 comments on commit 98627a9

Please sign in to comment.