-
Notifications
You must be signed in to change notification settings - Fork 238
improve: related resource reference change #3425
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: next
Are you sure you want to change the base?
Changes from all commits
58301d5
8c03c7e
5add551
a662e1a
8f80b29
04b809a
c289cc8
696769c
1228324
53ce6c6
5d80f99
bd8c204
200c964
9a8aeed
4ec2a75
e0fdd26
a9d6acf
a08970a
22e4a58
53eaf0b
0268865
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,6 +15,7 @@ | |
| */ | ||
| package io.javaoperatorsdk.operator.processing.event.source.informer; | ||
|
|
||
| import java.util.HashSet; | ||
| import java.util.Optional; | ||
| import java.util.Set; | ||
| import java.util.stream.Collectors; | ||
|
|
@@ -127,10 +128,10 @@ public synchronized void onDelete(R resource, boolean deletedFinalStateUnknown) | |
| if (resultEvent.isEmpty()) { | ||
| return; | ||
| } | ||
| primaryToSecondaryIndex.onDelete(resource); | ||
| var primaryIds = primaryToSecondaryIndex.onDelete(resource); | ||
| if (eventAcceptedByFilter( | ||
| ResourceAction.DELETED, resource, null, deletedFinalStateUnknown)) { | ||
| propagateEvent(resource); | ||
| propagateEvent(resource, null, primaryIds); | ||
| } | ||
| }); | ||
| } | ||
|
|
@@ -144,11 +145,12 @@ protected void handleEvent( | |
| // onAdd/onUpdate/onDelete watch paths. The index is updated for DELETED regardless of the | ||
| // filter outcome — the resource is really gone, so leaving a tombstone in the index would | ||
| // make getSecondaryResources keep returning a stale entry. | ||
| Set<ResourceID> primaryIds = null; | ||
| if (action == ResourceAction.DELETED) { | ||
| log.debug( | ||
| "handleEvent: removing from primaryToSecondaryIndex. id={}", | ||
| ResourceID.fromResource(resource)); | ||
| primaryToSecondaryIndex.onDelete(resource); | ||
| primaryIds = primaryToSecondaryIndex.onDelete(resource); | ||
| } | ||
| if (!eventAcceptedByFilter(action, resource, oldResource, deletedFinalStateUnknown)) { | ||
| if (log.isDebugEnabled()) { | ||
|
|
@@ -166,7 +168,7 @@ protected void handleEvent( | |
| action, | ||
| resource.getMetadata().getResourceVersion()); | ||
| } | ||
| propagateEvent(resource); | ||
| propagateEvent(resource, oldResource, primaryIds); | ||
| } | ||
|
|
||
| @Override | ||
|
|
@@ -177,12 +179,12 @@ public synchronized void start() { | |
| super.start(); | ||
| // this makes sure that on first reconciliation all resources are | ||
| // present on the index | ||
| manager().list().forEach(primaryToSecondaryIndex::onAddOrUpdate); | ||
| manager().list().forEach(r -> primaryToSecondaryIndex.onAddOrUpdate(r, null)); | ||
| } | ||
|
|
||
| @SuppressWarnings("unchecked") | ||
| private synchronized void onAddOrUpdate(ResourceAction action, R newObject, R oldObject) { | ||
| primaryToSecondaryIndex.onAddOrUpdate(newObject); | ||
| var primaryIds = primaryToSecondaryIndex.onAddOrUpdate(newObject, oldObject); | ||
| var resourceID = ResourceID.fromResource(newObject); | ||
|
|
||
| var resultEvent = temporaryResourceCache.onAddOrUpdateEvent(action, newObject, oldObject); | ||
|
csviri marked this conversation as resolved.
|
||
|
|
@@ -194,15 +196,22 @@ private synchronized void onAddOrUpdate(ResourceAction action, R newObject, R ol | |
| "Propagating event for {}, resource with same version not result of a our update.", | ||
| action); | ||
| var event = resultEvent.get(); | ||
| propagateEvent((R) event.getResource().orElseThrow()); | ||
| propagateEvent((R) event.getResource().orElseThrow(), oldObject, primaryIds); | ||
| } else { | ||
| log.debug("Event filtered out for operation: {}, resourceID: {}", action, resourceID); | ||
| } | ||
| } | ||
|
|
||
| protected void propagateEvent(R object) { | ||
| var primaryResourceIdSet = | ||
| configuration().getSecondaryToPrimaryMapper().toPrimaryResourceIDs(object); | ||
| protected void propagateEvent(R resource, R oldResource, Set<ResourceID> primaryResourceIdSet) { | ||
| if (primaryResourceIdSet == null) { | ||
| primaryResourceIdSet = new HashSet<>(); | ||
| primaryResourceIdSet.addAll( | ||
| configuration().getSecondaryToPrimaryMapper().toPrimaryResourceIDs(resource)); | ||
| if (oldResource != null) { | ||
|
Comment on lines
+206
to
+210
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is relevant will take a look |
||
| primaryResourceIdSet.addAll( | ||
| configuration().getSecondaryToPrimaryMapper().toPrimaryResourceIDs(oldResource)); | ||
| } | ||
| } | ||
| if (primaryResourceIdSet.isEmpty()) { | ||
| return; | ||
| } | ||
|
|
@@ -249,16 +258,16 @@ public Set<R> getSecondaryResources(P primary) { | |
| @Override | ||
| public void handleRecentResourceUpdate( | ||
| ResourceID resourceID, R resource, R previousVersionOfResource) { | ||
| handleRecentCreateOrUpdate(resource); | ||
| handleRecentCreateOrUpdate(resource, previousVersionOfResource); | ||
| } | ||
|
|
||
| @Override | ||
| public void handleRecentResourceCreate(ResourceID resourceID, R resource) { | ||
| handleRecentCreateOrUpdate(resource); | ||
| handleRecentCreateOrUpdate(resource, null); | ||
| } | ||
|
|
||
| private void handleRecentCreateOrUpdate(R newResource) { | ||
| primaryToSecondaryIndex.onAddOrUpdate(newResource); | ||
| private void handleRecentCreateOrUpdate(R newResource, R previousVersion) { | ||
| primaryToSecondaryIndex.onAddOrUpdate(newResource, previousVersion); | ||
| temporaryResourceCache.putResource(newResource); | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -33,13 +33,14 @@ public static <T extends HasMetadata> NOOPPrimaryToSecondaryIndex<T> getInstance | |
| private NOOPPrimaryToSecondaryIndex() {} | ||
|
|
||
| @Override | ||
| public void onAddOrUpdate(R resource) { | ||
| // empty method because of noop implementation | ||
| public Set<ResourceID> onAddOrUpdate(R resource, R oldResource) { | ||
| return null; | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is very ugly, might be better to remove the NOOP index |
||
| } | ||
|
|
||
| @Override | ||
| public void onDelete(R resource) { | ||
| public Set<ResourceID> onDelete(R resource) { | ||
| // empty method because of noop implementation | ||
| return null; | ||
| } | ||
|
Comment on lines
35
to
44
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. THis is relevant, but will need a refactoring to remove, will get rid of it in a subsequent PR |
||
|
|
||
| @Override | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.