-
Notifications
You must be signed in to change notification settings - Fork 219
feat: activation condition #2105
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
Merged
Merged
Changes from 14 commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
75dc2ea
rename condition to activationCondition
csviri 4bebcf3
feat: platform condition
csviri 6c5ff08
progress
csviri cb1f913
progress
csviri 488f6f3
impl proress
csviri ffe9627
informer restart
csviri a7a0d0a
fix
csviri b993ef5
Simple Integration Test passes
csviri 0b9879e
integration test
csviri a22808b
workflow cleanup tests
csviri 319b735
workflow tests
csviri 1271067
additional corner case test
csviri 41a8064
timeout increase
csviri 65bb301
concurrency IT
csviri e4d3c4c
docs
csviri 833d656
naming + docs on IT
csviri e6058ae
fix
csviri 8d9a778
IT changes
csviri 884a225
doc: improve wording
metacosm b3f3f4a
fix: warning
metacosm 689ec0f
doc: more improvements
metacosm ba6d31f
changes from review
csviri 81c2658
fixes from review
csviri 62d7224
javadoc for registration
csviri File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -62,15 +62,40 @@ private synchronized <R> void handleReconcile(DependentResourceNode<R, P> depend | |
return; | ||
} | ||
|
||
boolean reconcileConditionMet = isConditionMet(dependentResourceNode.getReconcilePrecondition(), | ||
boolean activationConditionMet = isConditionMet(dependentResourceNode.getActivationCondition(), | ||
dependentResourceNode.getDependentResource()); | ||
if (!reconcileConditionMet) { | ||
handleReconcileConditionNotMet(dependentResourceNode); | ||
registerOrDeregisterEventSourceBasedOnActivation(activationConditionMet, dependentResourceNode); | ||
|
||
boolean reconcileConditionMet = true; | ||
if (activationConditionMet) { | ||
reconcileConditionMet = isConditionMet(dependentResourceNode.getReconcilePrecondition(), | ||
dependentResourceNode.getDependentResource()); | ||
} | ||
if (!reconcileConditionMet || !activationConditionMet) { | ||
handleReconcileOrActivationConditionNotMet(dependentResourceNode, activationConditionMet); | ||
} else { | ||
submit(dependentResourceNode, new NodeReconcileExecutor<>(dependentResourceNode), RECONCILE); | ||
} | ||
} | ||
|
||
private <R> void registerOrDeregisterEventSourceBasedOnActivation(boolean activationConditionMet, | ||
DependentResourceNode<R, P> dependentResourceNode) { | ||
if (dependentResourceNode.getActivationCondition().isPresent()) { | ||
if (activationConditionMet) { | ||
var eventSource = | ||
dependentResourceNode.getDependentResource().eventSource(context.eventSourceRetriever() | ||
.eventSourceContexForDynamicRegistration()); | ||
var es = eventSource.orElseThrow(); | ||
context.eventSourceRetriever() | ||
.dynamicallyRegisterEventSource(dependentResourceNode.getName(), es); | ||
|
||
} else { | ||
context.eventSourceRetriever() | ||
.dynamicallyDeRegisterEventSource(dependentResourceNode.getName()); | ||
} | ||
} | ||
} | ||
|
||
private synchronized void handleDelete(DependentResourceNode dependentResourceNode) { | ||
log.debug("Submitting for delete: {}", dependentResourceNode); | ||
|
||
|
@@ -83,7 +108,8 @@ private synchronized void handleDelete(DependentResourceNode dependentResourceNo | |
return; | ||
} | ||
|
||
submit(dependentResourceNode, new NodeDeleteExecutor<>(dependentResourceNode), DELETE); | ||
submit(dependentResourceNode, | ||
new NodeDeleteExecutor<>(dependentResourceNode), DELETE); | ||
} | ||
|
||
private boolean allDependentsDeletedAlready(DependentResourceNode<?, P> dependentResourceNode) { | ||
|
@@ -141,13 +167,21 @@ protected void doRun(DependentResourceNode<R, P> dependentResourceNode, | |
DependentResource<R, P> dependentResource) { | ||
var deletePostCondition = dependentResourceNode.getDeletePostcondition(); | ||
|
||
// GarbageCollected status is irrelevant here, as this method is only called when a | ||
// precondition does not hold, | ||
// a deleter should be deleted even if it is otherwise garbage collected | ||
if (dependentResource instanceof Deleter) { | ||
((Deleter<P>) dependentResource).delete(primary, context); | ||
var activationConditionMet = dependentResourceNode.getActivationCondition() | ||
.map(c -> c.isMet(dependentResource, primary, context)) | ||
.orElse(true); | ||
|
||
boolean deletePostConditionMet = true; | ||
if (Boolean.TRUE.equals(activationConditionMet)) { | ||
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. Not sure what's going on here. Why not use isConditionMet? 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. Hmm, by bad, changed it. thx! |
||
// GarbageCollected status is irrelevant here, as this method is only called when a | ||
// precondition does not hold, | ||
// a deleter should be deleted even if it is otherwise garbage collected | ||
if (dependentResource instanceof Deleter) { | ||
((Deleter<P>) dependentResource).delete(primary, context); | ||
} | ||
deletePostConditionMet = isConditionMet(deletePostCondition, dependentResource); | ||
} | ||
boolean deletePostConditionMet = isConditionMet(deletePostCondition, dependentResource); | ||
|
||
if (deletePostConditionMet) { | ||
markAsVisited(dependentResourceNode); | ||
handleDependentDeleted(dependentResourceNode); | ||
|
@@ -180,20 +214,35 @@ private synchronized void handleDependentsReconcile( | |
} | ||
|
||
|
||
private void handleReconcileConditionNotMet(DependentResourceNode<?, P> dependentResourceNode) { | ||
private void handleReconcileOrActivationConditionNotMet( | ||
DependentResourceNode<?, P> dependentResourceNode, | ||
boolean activationConditionMet) { | ||
Set<DependentResourceNode> bottomNodes = new HashSet<>(); | ||
markDependentsForDelete(dependentResourceNode, bottomNodes); | ||
bottomNodes.forEach(this::handleDelete); | ||
markDependentsForDelete(dependentResourceNode, bottomNodes, activationConditionMet); | ||
bottomNodes.forEach( | ||
dependentResourceNode1 -> handleDelete(dependentResourceNode1)); | ||
} | ||
|
||
private void markDependentsForDelete(DependentResourceNode<?, P> dependentResourceNode, | ||
Set<DependentResourceNode> bottomNodes) { | ||
markedForDelete.add(dependentResourceNode); | ||
Set<DependentResourceNode> bottomNodes, boolean activationConditionMet) { | ||
// this is a check so the activation condition is not evaluated twice, | ||
// so if the activation condition was false, this node is not meant to be deleted. | ||
var dependents = dependentResourceNode.getParents(); | ||
if (dependents.isEmpty()) { | ||
bottomNodes.add(dependentResourceNode); | ||
if (activationConditionMet) { | ||
markedForDelete.add(dependentResourceNode); | ||
if (dependents.isEmpty()) { | ||
bottomNodes.add(dependentResourceNode); | ||
} else { | ||
dependents.forEach(d -> markDependentsForDelete(d, bottomNodes, true)); | ||
} | ||
} else { | ||
dependents.forEach(d -> markDependentsForDelete(d, bottomNodes)); | ||
// this is for an edge case when there is only one resource but that is not active | ||
markAsVisited(dependentResourceNode); | ||
if (dependents.isEmpty()) { | ||
handleNodeExecutionFinish(dependentResourceNode); | ||
} else { | ||
dependents.forEach(d -> markDependentsForDelete(d, bottomNodes, true)); | ||
} | ||
} | ||
} | ||
|
||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.