Commit 82d7945
improve: generic cache-aware secondary resource lookup for dependent resources
Introduces a cache-aware O(1) secondary resource lookup path at the
AbstractEventSourceHolderDependentResource level, generalising the
optimisation that was previously only available in a Kubernetes-specific
branch (optimize-kube-dependent).
## Problem
AbstractDependentResource.getSecondaryResource() calls
Context.getSecondaryResources(resourceType()), which loads all secondary
resources into a Set<R> and then delegates to selectTargetSecondaryResource()
to filter down to the single expected resource. For KubernetesDependentResource
this additionally calls getOrComputeDesired() inside
selectTargetSecondaryResource() just to derive the target name/namespace —
even though InformerEventSource already provides an O(1) cache.get(ResourceID)
API. For AbstractExternalDependentResource, selectTargetSecondaryResource()
calls desired(primary, context) equally wastefully for a mere lookup.
## Solution
AbstractEventSourceHolderDependentResource: overrides getSecondaryResource()
to check whether the event source implements Cache<R>. When it does, and when
targetSecondaryResourceID() returns a non-null ResourceID, the framework
calls cache.get(resourceID) directly — a single O(1) hash-map lookup.
Adds targetSecondaryResourceID() returning null by default (fully backward
compatible: existing subclasses see no change).
KubernetesDependentResource: the existing targetSecondaryResourceID() override
naturally wires into the new generic parent mechanism. selectTargetSecondaryResource()
is retained as a fallback for shared/non-informer event source scenarios.
Both methods re-documented to clarify the preferred fast path.
AbstractExternalDependentResource: overrides getSecondaryResource() to call
ExternalResourceCachingEventSource.getSecondaryResource(primaryID) directly,
bypassing desired() computation in selectTargetSecondaryResource().
All changes are strictly additive/override-with-fallback — no API removed,
no existing subclass needs to change.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>1 parent 04a694e commit 82d7945
3 files changed
Lines changed: 107 additions & 5 deletions
File tree
- operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent
- kubernetes
Lines changed: 55 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
27 | 27 | | |
28 | 28 | | |
29 | 29 | | |
| 30 | + | |
30 | 31 | | |
31 | 32 | | |
32 | 33 | | |
| |||
123 | 124 | | |
124 | 125 | | |
125 | 126 | | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
126 | 181 | | |
127 | 182 | | |
128 | 183 | | |
| |||
Lines changed: 28 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
26 | 26 | | |
27 | 27 | | |
28 | 28 | | |
| 29 | + | |
29 | 30 | | |
30 | 31 | | |
31 | 32 | | |
| |||
103 | 104 | | |
104 | 105 | | |
105 | 106 | | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
106 | 134 | | |
107 | 135 | | |
108 | 136 | | |
| |||
Lines changed: 24 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 | + | |
250 | 262 | | |
251 | 263 | | |
252 | 264 | | |
| |||
262 | 274 | | |
263 | 275 | | |
264 | 276 | | |
265 | | - | |
266 | | - | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
267 | 280 | | |
268 | | - | |
269 | | - | |
270 | | - | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
271 | 289 | | |
| 290 | + | |
272 | 291 | | |
273 | 292 | | |
274 | 293 | | |
| |||
0 commit comments