[Feature]: Share readiness, reserved-label filtering and OS-tag logic between the ClusterPolicy and NVIDIADriver/GPUCluster stacks
Motivation Several recent defects are the same fix applied to one stack but not the other:
- #2968 added an
observedGenerationguard tointernal/state/state_skel.go:isDaemonSetReady; the ClusterPolicy copy incontrollers/object_controls.go:4030still 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:605andinternal/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
Could you provide more details about the problem you encountered and your proposed solution?
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 whenDesiredNumberScheduled == 0, without checkingobservedGeneration. For RollingUpdate it then usesisDaemonSetRollingUpdateComplete(generation-aware), and for OnDelete a per-pod revision check. - NVIDIADriver/GPUCluster:
stateSkel.isDaemonSetReady(internal/state/state_skel.go:511) is status-only and requiresobservedGeneration >= generationin 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:
DaemonSetStatusReady(ds *appsv1.DaemonSet) bool: the generation-aware status check fromstate_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.OSTag(id, versionID string) string, plus moving the OS path maps and NFD label keys to one place (internal/constsor the new package).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
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 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.