Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 23 additions & 13 deletions src/KubeOps.Operator/Watcher/ResourceWatcher{TEntity}.cs
Original file line number Diff line number Diff line change
Expand Up @@ -143,20 +143,30 @@ protected virtual async Task OnEventAsync(WatchEventType type, TEntity entity, C
switch (type)
{
case WatchEventType.Added:
cachedGeneration = await _entityCache.TryGetAsync<long?>(entity.Uid(), token: cancellationToken);

if (!cachedGeneration.HasValue)
{
// Only perform reconciliation if the entity was not already in the cache.
await _entityCache.SetAsync(entity.Uid(), entity.Generation() ?? 0, token: cancellationToken);
await ReconcileModificationAsync(entity, cancellationToken);
}
else
switch (entity)
{
logger.LogDebug(
"""Received ADDED event for entity "{Kind}/{Name}" which was already in the cache. Skip event.""",
entity.Kind,
entity.Name());
case { Metadata.DeletionTimestamp: null }:
cachedGeneration = await _entityCache.TryGetAsync<long?>(entity.Uid(), token: cancellationToken);

if (!cachedGeneration.HasValue)
{
// Only perform reconciliation if the entity was not already in the cache.
await _entityCache.SetAsync(entity.Uid(), entity.Generation() ?? 0, token: cancellationToken);
await ReconcileModificationAsync(entity, cancellationToken);
}
else
{
logger.LogDebug(
"""Received ADDED event for entity "{Kind}/{Name}" which was already in the cache. Skip event.""",
entity.Kind,
entity.Name());
}

break;

case { Metadata: { DeletionTimestamp: not null, Finalizers.Count: > 0 } }:
await ReconcileFinalizersSequentialAsync(entity, cancellationToken);
break;
}

break;
Expand Down