gpu-operator icon indicating copy to clipboard operation
gpu-operator copied to clipboard

[Feature]: Reduce the operator's Pod cache: scope or metadata-only watches

Open CloneOfAlex opened this issue 1 month ago • 4 comments

Motivation The node-labeling controller watches corev1.Pod cluster-wide (controllers/nodelabeling_controller.go:784) to catch driver pods turning Running and to find DRA claim pods per node, so the manager caches every Pod in the cluster with full specs and status. On large clusters this dominates the operator's memory, even though only driver pods (by label) and pods on GPU nodes are relevant.

Proposal

  • Cache driver pods via a label-selected informer (app.kubernetes.io/component=nvidia-driver in the operator namespace) using controller-runtime cache.Options.ByObject.
  • For per-node DRA claim checks, either use a metadata-only watch (PartialObjectMetadata) plus targeted reads, or list by spec.nodeName field selector through the API reader when needed.

This complements #2886 (reducing what is stored in the cache).

CloneOfAlex avatar Oct 13 '26 18:10 CloneOfAlex

@CloneOfAlex

Could you provide more details about the problem you encountered and your proposed solution?

francisguillier avatar Oct 19 '26 23:10 francisguillier

Thanks @francisguillier. Working through the details showed that the premise of this issue is wrong for current main, and that the real question is the one raised in #2886. Corrected picture below.

Correction: the Pod cache is not cluster-wide today

I wrote that the Pod watch (nodelabeling_controller.go:784) makes the manager cache every Pod in the cluster. It doesn't. The manager's cache is namespace-scoped (cmd/gpu-operator/main.go:131):

cacheOptions := cache.Options{
	DefaultNamespaces: map[string]cache.Config{
		operatorNamespace:  {},
		openshiftNamespace: {}, // "openshift"
	},
}

There's no ByObject override, so the Pod informer only holds pods in the operator namespace and openshift. All-namespace List calls go through multiNamespaceCache.List, which only aggregates those namespaces (controller-runtime pkg/cache/multi_namespace_cache.go:289). The cached set is essentially the operand pods: roughly one per operand DaemonSet per GPU node. That's not small on a big cluster, but it's not "every Pod". I don't have memory measurements, and on main I wouldn't claim Pods are the dominant cost.

The actual problem: DRA teardown needs cluster-wide pod visibility

nodeHasDRAClaimPods (nodelabeling_controller.go:461) is meant to find any pod on a node still holding an NVIDIA DRA claim before the kubelet-plugin label is removed. With the namespace-scoped cache it only sees operator/openshift pods, so user workloads holding NVIDIA claims are invisible to it. I've described that in more detail on #3073.

#2886 fixes the visibility by caching Pods and ResourceClaims in all namespaces. As noted in review there, that's exactly the trade-off this issue was worried about: every Pod and ResourceClaim in the cluster would be held in operator memory. So I'd reframe this issue as: give the DRA teardown check cluster-wide visibility without a cluster-wide Pod informer.

Options

  1. Targeted live reads when the check runs (my recommendation). The check only runs when a node's workload-config change would remove the kubelet-plugin deploy label (nodelabeling_controller.go:357-365), which is a rare event. While removal is deferred, the controller re-checks on a 30s backstop requeue (:252-255). At that point, mgr.GetAPIReader().List(ctx, pods, client.MatchingFields{"spec.nodeName": nodeName}) is served by the API server's spec.nodeName field selector (supported for Pods), followed by live Gets on that node's claims. Cost: one list per affected node every 30s, only during a mode flip, and zero steady-state memory. The existing pod-by-node cache index stays as-is for operator-namespace pods.

    Side note: the comment at :253 says pod deletion events retrigger reconciliation, but the Pod predicate's DeleteFunc returns false (:777), and its UpdateFunc only fires for driver pods turning Running. In practice the 30s requeue is the only thing that drives the re-check, so option 1 doesn't lose any event-driven behavior.

  2. Cluster-wide informer with a stripping transform. Use ByObject for Pods (and ResourceClaims) in all namespaces, with a Transform that keeps only what the check reads: spec.nodeName, spec.resourceClaims, status.resourceClaimStatuses, status.phase, deletionTimestamp. This makes memory much smaller than full objects, but it's still O(cluster pods). And because the transformed objects are shared, any future cached Pod reader silently gets stripped objects.

  3. Metadata-only watch (PartialObjectMetadata). I suggested this originally, but it doesn't work for this check. Metadata objects carry no spec.nodeName or spec.resourceClaims, so they can't be indexed by node or used to find claims.

I'd also withdraw the other half of my original proposal: label-scoping the Pod cache to driver pods only. The same cache serves nodeHasDRAClaimPods, which needs non-driver operator-namespace pods holding admin-access claims, and the operand pod lists in object_controls.go.

Suggested resolution

I'd fold this into the #2886 discussion and the node-labeling visibility bug, preferring option 1. If you agree, I can close this issue in favor of those, or keep it open as the tracking issue for option 1. Happy to send a PR for option 1 with tests.

CloneOfAlex avatar Oct 20 '26 16:10 CloneOfAlex

@CloneOfAlex

I’m not sure I understand the deployment problem you’re trying to solve. Could you please provide:

  • Issue summary: What is happening, and what behavior do you expect?
  • Steps to reproduce: Include the relevant environment details and configuration.
  • Proposed fix: Explain how the fix addresses the problem. Without these details, we won’t be able to assess the issue and will close it. Thanks

francisguillier avatar Nov 05 '26 22:11 francisguillier

@francisguillier the short answer is that there isn't a deployment problem. As I wrote above, the premise was wrong: the manager cache is already namespace-scoped (cmd/gpu-operator/main.go:131), so the operator doesn't cache every Pod in the cluster. Closing this. The DRA claim-visibility gap that came out of the analysis is better tracked separately.

CloneOfAlex avatar Nov 05 '26 23:11 CloneOfAlex