@@ -114,6 +114,89 @@ default <R> Stream<R> getSecondaryResourcesAsStream(Class<R> expectedType) {
114114
115115 <R > Optional <R > getSecondaryResource (Class <R > expectedType , String eventSourceName );
116116
117+ /**
118+ * Retrieves a specific secondary resource by name and namespace from the event source identified
119+ * by the given name.
120+ *
121+ * <p>This is a typed convenience over manually retrieving the {@link
122+ * io.javaoperatorsdk.operator.processing.event.source.EventSource} and calling its cache. When
123+ * the underlying event source implements {@link
124+ * io.javaoperatorsdk.operator.processing.event.source.Cache}, the lookup is a direct cache lookup
125+ * and read-cache-after-write consistent.
126+ *
127+ * <p>{@code eventSourceName} may be {@code null}. When {@code null} and {@code expectedType} is
128+ * part of a managed workflow whose activation condition may not have registered the event source,
129+ * an empty {@link Optional} is returned instead of throwing {@link
130+ * io.javaoperatorsdk.operator.processing.event.NoEventSourceForClassException}.
131+ *
132+ * @param expectedType the class representing the type of secondary resource to retrieve
133+ * @param eventSourceName the name of the event source to look in (may be {@code null})
134+ * @param name the name of the secondary resource
135+ * @param namespace the namespace of the secondary resource (may be {@code null} for
136+ * cluster-scoped resources)
137+ * @param <R> the type of secondary resource to retrieve
138+ * @return an {@link Optional} containing the matching secondary resource, or {@link
139+ * Optional#empty()} if none matches
140+ * @throws io.javaoperatorsdk.operator.processing.event.NoEventSourceForClassException if no event
141+ * source is registered for the given type and name (and no workflow activation condition
142+ * accounts for it)
143+ * @since 5.4.0
144+ */
145+ <R extends HasMetadata > Optional <R > getSecondaryResource (
146+ Class <R > expectedType , String eventSourceName , String name , String namespace );
147+
148+ /**
149+ * Convenience overload of {@link #getSecondaryResource(Class, String, String, String)} that uses
150+ * the primary resource's namespace.
151+ *
152+ * <p>If the primary resource is cluster-scoped (no namespace), the lookup is performed against
153+ * the cluster scope. To target a specific namespace from a cluster-scoped primary, use {@link
154+ * #getSecondaryResource(Class, String, String, String)} directly.
155+ *
156+ * <p>{@code eventSourceName} may be {@code null} with the same semantics as in {@link
157+ * #getSecondaryResource(Class, String, String, String)}.
158+ *
159+ * @param expectedType the class representing the type of secondary resource to retrieve
160+ * @param eventSourceName the name of the event source to look in (may be {@code null})
161+ * @param name the name of the secondary resource (namespace inferred from the primary)
162+ * @param <R> the type of secondary resource to retrieve
163+ * @return an {@link Optional} containing the matching secondary resource, or {@link
164+ * Optional#empty()} if none matches
165+ * @since 5.4.0
166+ */
167+ default <R extends HasMetadata > Optional <R > getSecondaryResource (
168+ Class <R > expectedType , String eventSourceName , String name ) {
169+ return getSecondaryResource (
170+ expectedType , eventSourceName , name , getPrimaryResource ().getMetadata ().getNamespace ());
171+ }
172+
173+ /**
174+ * Retrieves a {@link Stream} of the secondary resources of the specified type from the event
175+ * source identified by the given name. Useful when several event sources are registered for the
176+ * same type and you need to scope retrieval to one of them, or when you want to apply a custom
177+ * filter at the call site.
178+ *
179+ * <p>When the underlying event source implements {@link ResourceCache}, the stream is
180+ * read-cache-after-write consistent.
181+ *
182+ * <p>{@code eventSourceName} may be {@code null} with the same semantics as in {@link
183+ * #getSecondaryResource(Class, String, String, String)}: when {@code null} and {@code
184+ * expectedType} is part of a managed workflow whose activation condition may not have registered
185+ * the event source, an empty {@link Stream} is returned instead of throwing {@link
186+ * io.javaoperatorsdk.operator.processing.event.NoEventSourceForClassException}.
187+ *
188+ * @param expectedType the class representing the type of secondary resources to retrieve
189+ * @param eventSourceName the name of the event source to look in (may be {@code null})
190+ * @param <R> the type of secondary resources to retrieve
191+ * @return a {@link Stream} of secondary resources of the specified type
192+ * @throws io.javaoperatorsdk.operator.processing.event.NoEventSourceForClassException if no event
193+ * source is registered for the given type and name (and no workflow activation condition
194+ * accounts for it)
195+ * @since 5.4.0
196+ */
197+ <R extends HasMetadata > Stream <R > getSecondaryResourcesAsStream (
198+ Class <R > expectedType , String eventSourceName );
199+
117200 ControllerConfiguration <P > getControllerConfiguration ();
118201
119202 /**
0 commit comments