Skip to content

fix(upgrade): drain pods holding AMD GPUs through DRA ResourceClaims - #687

Open
beengineer-moreh wants to merge 1 commit into
ROCm:mainfrom
beengineer-moreh:fix/upgrade-drain-dra-claims
Open

beengineer-moreh wants to merge 1 commit into
ROCm:mainfrom
beengineer-moreh:fix/upgrade-drain-dra-claims

Conversation

@beengineer-moreh

Copy link
Copy Markdown

Problem

The DRA driver has been supported since v1.5.0 (release notes, guide). When the operator manages the driver and upgrades it under spec.driver.upgradePolicy, workload pods that get their GPU from a ResourceClaim are not drained. They stay on the node while the old module is unloaded.

This covers claims set in spec.resourceClaims (by name or from a template) and the claim the scheduler creates for the implicit extended resource deviceclass.resource.kubernetes.io/gpu.amd.com. The AutoPartition path creates the gpu.amd.com class without extendedResourceName, so that request is not an amd.com/ name. Pods that request amd.com/gpu through the class mapping are already drained.

A pod left behind can keep amdgpu in use. If the unload never finishes and rebootRequired is true, handleNodeReboot waits up to an hour for the new image and then reboots anyway, so the pod is killed by the reboot instead of going through the drain or delete policy.

Root cause

getPodsToDrainOrDelete looks for the GPU in the container spec: an amd.com/ request or a /dev/dri mount. The DRA driver injects devices through CDI, so a claim-based pod often has neither. Which driver owns the device is only recorded in the claim's status.allocation.devices.results[].driver.

What changed

After the existing checks, a pod is also selected when one of its claims has a device allocated by gpu.amd.com. The class selector is device.driver == 'gpu.amd.com', so this reuses deviceClassName. Claims come from spec.resourceClaims, status.resourceClaimStatuses and status.extendedResourceClaimStatus. A template claim that has not been generated yet is skipped.

The check is per pod. If a claim is shared and a container only uses its NIC request, the pod is still selected.

Claims are read with the highest resource.k8s.io version from draAPIVersionPriority whose discovery list has resourceclaims. Discovery only runs when a pod has a claim, at most once per call. A claim that is already gone is skipped, since a terminating pod's claim can be deleted first. Any other error is returned, so the node ends in Drain-Failed rather than rebooting with the pod running.

The manager role gets get on resource.k8s.io/resourceclaims. config/rbac/role.yaml is regenerated with controller-gen v0.17.0. The same rule is added by hand to the Helm manager-rbac.yaml and the bundle CSV, because make manifests would also rewrite image tags and versions.

Out of scope & compatibility

No change to the device plugin, the DRA driver, DeviceConfig, CRDs, validators or Helm values, so older images are not affected. Nodes without claim-based pods make no new API calls.

Nodes with claim-based pods, including pods of other DRA drivers, now need the new RBAC rule. Helm and OLM ship it. If RBAC is managed some other way, the operator must already have get on resourceclaims before the image is switched. Otherwise the node goes to Drain-Failed, counts against maxUnavailableNodes, and stays there until it is relabeled with operator.amd.com/gpu-driver-upgrade-state=upgrade-required (recovery).

Left for later: handleNodeReboot still reboots without an error state when the new image never shows up, and the version probe is not shared with discoverDRAAPIVersion, which builds its own in-cluster client and only checks the group version.

Testing

go vet ./internal/controllers/, go test -count=1 ./internal/... and golangci-lint run ./internal/controllers/... (v2.15.0) pass.

New specs in upgrademgr_test.go use a fake clientset with discovery resource lists. They cover direct, template and extended-resource claims allocated by gpu.amd.com, a claim from another driver, a template claim not generated yet, falling back to v1beta2 when v1 has no resourceclaims, a v1beta1-only cluster, a deleted claim, and Forbidden from both the claim read and discovery. The DRA positive specs fail on main. The fixtures do not set containers[].resources.claims.

Not run against a live driver upgrade or an OpenShift cluster serving only v1beta2. On a Kubernetes v1.37 cluster I found a pod of this shape: a gpu.amd.com claim, no amd.com/ request, no /dev/dri mount.

#606 drains the operator's own DRA driver pod; this is about workload pods. The amd.com/ check from #663 is kept as is.

getPodsToDrainOrDelete only finds GPU pods by an amd.com/ request or a
/dev/dri mount. The DRA driver injects devices through CDI, so a pod
that gets its GPU from a ResourceClaim usually has neither and is left
on the node during a driver upgrade, where it can keep amdgpu busy.

Also select a pod when one of its claims has a device allocated by
gpu.amd.com. Claims come from spec.resourceClaims, the generated
template claims, and the claim the scheduler creates for a DRA extended
resource request. They are read with the highest resource.k8s.io
version that serves resourceclaims. A claim that is already deleted is
skipped; any other error fails the drain.

Grant the manager role get on resource.k8s.io resourceclaims.

Signed-off-by: been-son <been.son@moreh.io>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant