| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
…sResourceFetcher
`fetchResource` selected between a namespaced and a cluster-scoped lookup
with `Optional.orElse`:
return resourceId.getNamespace()
.map(ns -> client.resources(rClass).inNamespace(ns).withName(name).get())
.orElse(client.resources(rClass).withName(name).get());
`orElse` evaluates its argument unconditionally, so every namespaced
lookup also performed the cluster-scoped GET. For a namespaced resource
type that second request either queries whichever namespace the client
happens to default to or fails outright, and its result is then thrown
away.
This runs on the `BoundedItemStore` cache-miss path
(`refreshMissingStateFromServer`), so it doubles the API server requests
for every bounded-cache refresh of a namespaced resource.
Switches to `orElseGet` so the fallback is only evaluated for
cluster-scoped resource ids.
There was a problem hiding this comment.
This PR updates KubernetesResourceFetcher in operator-framework-core to avoid eagerly executing a cluster-scoped fallback lookup when fetching resources, reducing unnecessary Kubernetes API calls on the bounded-cache refresh path.
Changes:
operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/cache/KubernetesResourceFetcher.java:48
return resourceId
.getNamespace()
.map(ns -> client.resources(rClass).inNamespace(ns).withName(resourceId.getName()).get())
.orElseGet(() -> client.resources(rClass).withName(resourceId.getName()).get());
Sorry, something went wrong.
| public R fetchResource(String key) { | ||
| var resourceId = resourceIDFunction.apply(key); | ||
| return resourceId | ||
| .getNamespace() | ||
| .map(ns -> client.resources(rClass).inNamespace(ns).withName(resourceId.getName()).get()) | ||
| .orElse(client.resources(rClass).withName(resourceId.getName()).get()); | ||
| .orElseGet(() -> client.resources(rClass).withName(resourceId.getName()).get()); |
There was a problem hiding this comment.
LGTM
Sorry, something went wrong.
…sResourceFetcher (operator-framework#3527) `fetchResource` selected between a namespaced and a cluster-scoped lookup with `Optional.orElse`: return resourceId.getNamespace() .map(ns -> client.resources(rClass).inNamespace(ns).withName(name).get()) .orElse(client.resources(rClass).withName(name).get()); `orElse` evaluates its argument unconditionally, so every namespaced lookup also performed the cluster-scoped GET. For a namespaced resource type that second request either queries whichever namespace the client happens to default to or fails outright, and its result is then thrown away. This runs on the `BoundedItemStore` cache-miss path (`refreshMissingStateFromServer`), so it doubles the API server requests for every bounded-cache refresh of a namespaced resource. Switches to `orElseGet` so the fallback is only evaluated for cluster-scoped resource ids.
| Back | FazBrowse Home | New Git URL |
fetchResource selected between a namespaced and a cluster-scoped lookup
with Optional.orElse:
return resourceId.getNamespace() .map(ns -> client.resources(rClass).inNamespace(ns).withName(name).get()) .orElse(client.resources(rClass).withName(name).get());orElse evaluates its argument unconditionally, so every namespaced
lookup also performed the cluster-scoped GET. For a namespaced resource
type that second request either queries whichever namespace the client
happens to default to or fails outright, and its result is then thrown
away.
This runs on the BoundedItemStore cache-miss path
(refreshMissingStateFromServer), so it doubles the API server requests
for every bounded-cache refresh of a namespaced resource.
Switches to orElseGet so the fallback is only evaluated for
cluster-scoped resource ids.
Part of #3517