-
Notifications
You must be signed in to change notification settings - Fork 235
feat: provide de-duplicated secondary resources stream on Context #3141
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?
Conversation
Signed-off-by: Attila Mészáros <a_meszaros@apple.com>
…tor/api/reconciler/ReconcileUtils.java Co-authored-by: Martin Stefanko <xstefank122@gmail.com>
Signed-off-by: Chris Laprun <metacosm@gmail.com>
Alternative without requiring collecting to a Map Signed-off-by: Chris Laprun <metacosm@gmail.com>
...-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/DefaultContext.java
Show resolved
Hide resolved
...-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/DefaultContext.java
Show resolved
Hide resolved
| * @param <T> the type of HasMetadata objects | ||
| * @return a collector that produces a collection of deduplicated Kubernetes objects | ||
| */ | ||
| public static <T extends HasMetadata> Collector<T, ?, Collection<T>> latestDistinct() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wasn't this moved to ReconcileUtilsInternal
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we were to keep this implementation, this actually would be removed
csviri
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Made some minor comments, pls add unit tests! Otherwise looks great, thank you!!
|
|
||
| default <R> Stream<R> getSecondaryResourcesAsStream(Class<R> expectedType) { | ||
| return getSecondaryResources(expectedType).stream(); | ||
| return getSecondaryResourcesAsStream(expectedType, false); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here we could use the former implementation and call this in case in the new method the deduplication is false.
| } | ||
|
|
||
| final var idToLatest = deduplicate ? new HashMap<ResourceID, String>() : null; | ||
| final var stream = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As mentioned above for sake of simplicity/readbaility can if deduplicate is false could we just use the former implementation?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could but this implementation avoids creating intermediary Streams, though I agree that it's slightly less readable. Let me see what I can do about that.
| return controller.getEventSourceManager().getEventSourcesFor(expectedType).stream() | ||
| .map(es -> es.getSecondaryResources(primaryResource)) | ||
| .flatMap(Set::stream); | ||
| public <R> Stream<R> getSecondaryResourcesAsStream(Class<R> expectedType, boolean deduplicate) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add comprehensive javadoc
Alternative to #3130, to discuss