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

[Feature]: Share readiness, reserved-label filtering and OS-tag logic between the ClusterPolicy and NVIDIADriver/GPUCluster stacks

Open CloneOfAlex opened this issue 1 month ago • 4 comments

Motivation Several recent defects are the same fix applied to one stack but not the other:

  • #2968 added an observedGeneration guard to internal/state/state_skel.go:isDaemonSetReady; the ClusterPolicy copy in controllers/object_controls.go:4030 still lacks it (#3060).
  • Reserved operand labels are protected on the ClusterPolicy path (applyCommonDaemonsetLabel, object_controls.go:809) but not for NVIDIADriver (#3059) or GPUCluster (#2955, draft #2973).
  • OS-tag derivation is duplicated in controllers/state_manager.go:605 and internal/state/nodepool.go:162.

Proposal An internal package (e.g. internal/operand) exporting IsDaemonSetReady, FilterReservedLabels and OSTag, called by both stacks, with one table-driven test suite. Future fixes then land once.

Related: #3059, #3060, #2955, #2973. Found during a code review of main @ f806d6b.

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. To make this concrete, I ran the duplicated logic side by side on current main to see where the copies have actually drifted versus where they're just duplicated. Short version: readiness has diverged in exactly the way #3060 describes, OS-tag hasn't (yet), and reserved-label handling is too operand-specific for a single fixed filter, which changes the shape of the proposed package.

1. DaemonSet readiness: diverged

The two implementations:

  • ClusterPolicy: isDaemonSetReady (controllers/object_controls.go:4030) fetches the DaemonSet and returns Ready immediately when DesiredNumberScheduled == 0, without checking observedGeneration. For RollingUpdate it then uses isDaemonSetRollingUpdateComplete (generation-aware), and for OnDelete a per-pod revision check.
  • NVIDIADriver/GPUCluster: stateSkel.isDaemonSetReady (internal/state/state_skel.go:511) is status-only and requires observedGeneration >= generation in both branches (the #2968 fix).

I fed the same RollingUpdate DaemonSet states through both (fake client for the ClusterPolicy one):

Case ClusterPolicy NVIDIADriver / GPUCluster
A: just created, status not yet written (gen 1, observed 0, all zero) ready notReady
B: zero desired, observed ready ready
C: steady state, 3/3 available and updated ready ready
D: spec changed, not yet observed notReady notReady
E: rollout in progress (1/3 updated) notReady notReady
F: one pod unavailable notReady notReady
G: zero desired but stale status (e.g. nodeSelector just changed) ready notReady

A and G are the #3060 bug: on the ClusterPolicy path, a DaemonSet the controller hasn't processed yet reports Ready, so the state machine can advance past an operand that hasn't been scheduled. Everything else agrees.

2. OS-tag derivation: duplicated, not diverged

ClusterPolicyController.getGPUNodeOSInfo (controllers/state_manager.go:578-610) and getOSTag (internal/state/nodepool.go:162) produce identical tags for ubuntu 22.04, rhel 9.4, rocky 9.3, ol 8.10, sles 15.5, rhcos 4.16, centos 7, sl-micro 6.0 and debian 12. There's no bug here today; it's drift waiting to happen.

While checking this I found more verbatim copies that drift the same way: RepoConfigPathMap, CertConfigPathMap and SubscriptionPathMap exist in both controllers/object_controls.go:226+ and internal/state/driver_volumes.go:33+ (identical today), and the NFD label key constants (nfdOSReleaseIDLabelKey, nfdOSVersionIDLabelKey, …) are declared in both controllers/state_manager.go and internal/state/driver.go.

3. Reserved labels: needs a different shape than "FilterReservedLabels"

As I detailed on #3067, which keys are operator-owned differs per operand (app.kubernetes.io/name only on DRA workloads, part-of nowhere on these paths), and the ClusterPolicy path deliberately lets app/part-of through to DaemonSet metadata. A single FilterReservedLabels with a fixed list would either over-filter or under-filter. What generalizes is "operator-owned keys win": a merge that takes the operand's own labels and drops colliding user keys, reporting what it dropped.

On the template stacks this has to be reachable from the templates, since labels are rendered in YAML (internal/render), e.g. a template func such as {{ userLabels .Driver.Spec.Labels "app" "app.kubernetes.io/component" }}, or a pre-filter of the spec copy in Go before render.

Revised proposal

An internal/operand (or similar) package with:

  1. DaemonSetStatusReady(ds *appsv1.DaemonSet) bool: the generation-aware status check from state_skel.go, used by both stacks. The ClusterPolicy path keeps its OnDelete per-pod revision check on top for now; replacing that is a separate decision. This fixes #3060 as a side effect. The table above becomes the shared test.
  2. OSTag(id, versionID string) string, plus moving the OS path maps and NFD label keys to one place (internal/consts or the new package).
  3. MergeUserLabels(owned, user map[string]string) (merged map[string]string, dropped []string), plus a template func wrapping it, so each operand passes its own owned keys. ClusterPolicy can adopt it later if maintainers want to align its metadata behavior; it doesn't have to change now.

Suggested order: (1) first since it's an actual bug, then (2) as a no-behavior-change refactor, and (3) together with the #3059/#3067 template fixes. To be transparent: this is from code review plus the side-by-side runs above, not a production incident. I'm happy to open the PR for (1) with the shared table test.

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 fair question. Re-checking this against current main, I don't think there's a deployment problem left to justify this issue:

  • Readiness: the only user-visible divergence was #3060, now fixed by #3079.
  • Reserved labels: #3059 turned out to be invalid (NVIDIADriver labels are already sanitized in getDriverSpec()), and the GPUCluster case is tracked in #2955 / #2973.
  • OS-tag and path maps: duplicated but identical today, so this is a refactor with no behavior change.

What's left is code-health only, so I'm closing this. Thanks for pushing for a concrete problem statement.

CloneOfAlex avatar Nov 05 '26 23:11 CloneOfAlex