feat(core): add by-name secondary resource lookup on Context#3373
Conversation
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Adds new Context APIs for retrieving secondary resources by ResourceID and streaming secondary resources from a specific named event source, with cache-backed fast paths and tests to validate behavior.
Changes:
- Added
Context#getSecondaryResource(..., ResourceID)and a convenience overload that infers namespace from the primary resource. - Added
Context#getSecondaryResourcesAsStream(..., eventSourceName)with aResourceCachefast path for read-cache-after-write consistency. - Expanded
DefaultContextTestto cover cache hit/miss, fallback behavior, cluster-scoped vs namespaced primaries, and workflow-managed missing event sources.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/Context.java | Introduces new public API methods and Javadoc for ResourceID lookups and named event-source streaming. |
| operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/DefaultContext.java | Implements the new APIs, adds cache/resource-cache fast paths, and refactors missing-event-source handling into a helper. |
| operator-framework-core/src/test/java/io/javaoperatorsdk/operator/api/reconciler/DefaultContextTest.java | Adds unit tests validating the new APIs and fast-path/fallback behaviors. |
| * @throws io.javaoperatorsdk.operator.processing.event.NoEventSourceForClassException if no event | ||
| * source is registered for the given type and name (and no workflow activation condition | ||
| * accounts for it) | ||
| * @since 5.3.5 |
There was a problem hiding this comment.
Since this would be a new feature, I'm not sure whether this is something it will be released as part of a patch release or as a minor one.
So depending on it, this might change.
495d579 to
c8b2feb
Compare
Signed-off-by: Antonio Fernandez Alhambra <antonio.alhambra@hivemq.com>
c8b2feb to
1012314
Compare
csviri
left a comment
There was a problem hiding this comment.
Thank you for the PR @afalhambra-hivemq !
Could you pls target 'next' branch so this ends up in next minor release rather than in next patch release.
I was also thinking if we should use ResourceID in the method or simply name and namespace directly it might be less user boilerplate code at the end,or? What do you think?
Adds three typed by-name secondary-resource accessors to
Context<P>:<R> Optional<R> getSecondaryResource(Class<R>, String eventSourceName, ResourceID)(abstract)<R> Optional<R> getSecondaryResource(Class<R>, String eventSourceName, String name)(default; uses the primary's namespace)<R> Stream<R> getSecondaryResourcesAsStream(Class<R>, String eventSourceName)(abstract)Closes #3372