Commit c39b349
improve: cache-aware secondary resource lookup for KubernetesDependentResource
Introduces a direct O(1) cache lookup path in KubernetesDependentResource
to retrieve the secondary resource from the InformerEventSource cache,
bypassing the costlier Context.getSecondaryResources() path.
## Problem
AbstractDependentResource.getSecondaryResource() calls
Context.getSecondaryResources(resourceType()), which iterates the
InformerEventSource index to build a Set<R> of all secondary resources
for the primary, then delegates to selectTargetSecondaryResource() to
filter down to the single expected resource. That implementation calls
getOrComputeDesired() to derive the target name/namespace, and then
streams and filters the full Set — even though InformerEventSource
already provides an O(1) cache.get(ResourceID) lookup.
## Solution
KubernetesDependentResource now overrides getSecondaryResource() to
call InformerEventSource.get(targetSecondaryResourceID) directly — a
single hash-map lookup — when the event source is present. Falls back
to the standard AbstractDependentResource path (via
selectTargetSecondaryResource) when the event source is not directly
available (e.g. shared event source scenario).
The existing targetSecondaryResourceID() method drives both the new
fast path and the existing selectTargetSecondaryResource() fallback.
Override it to return a cheap, statically-derivable ResourceID (e.g.
from the primary name/namespace) to avoid the getOrComputeDesired()
call during secondary resource lookup entirely.
The optimisation is intentionally scoped to KubernetesDependentResource
where R extends HasMetadata and ResourceID is a valid secondary resource
identifier. The base class AbstractEventSourceHolderDependentResource
is left unchanged because R is not bounded to HasMetadata there and
ResourceID is not a universally applicable secondary resource key.
## Backward compatibility
All changes are additive or override-with-fallback:
- getSecondaryResource() falls back to super when eventSource() is empty.
- selectTargetSecondaryResource() is retained as the fallback for the
shared event source scenario.
- targetSecondaryResourceID() behaviour is unchanged.
Signed-off-by: Mohit Gupta <mohitg@zeta.tech>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Signed-off-by: Mohit Gupta <mohitg@zeta.tech>1 parent 04a694e commit c39b349
1 file changed
Lines changed: 54 additions & 5 deletions
File tree
- operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes
Lines changed: 54 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
247 | 247 | | |
248 | 248 | | |
249 | 249 | | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
250 | 292 | | |
251 | 293 | | |
252 | 294 | | |
| |||
262 | 304 | | |
263 | 305 | | |
264 | 306 | | |
265 | | - | |
266 | | - | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
267 | 316 | | |
268 | | - | |
269 | | - | |
270 | | - | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
271 | 320 | | |
272 | 321 | | |
273 | 322 | | |
| |||
0 commit comments