Skip to content

fix(vm): track USB ResourceClaimTemplate spec via hash annotation#2623

Open
danilrwx wants to merge 2 commits into
mainfrom
fix/vm/usb-rct-spec-hash
Open

fix(vm): track USB ResourceClaimTemplate spec via hash annotation#2623
danilrwx wants to merge 2 commits into
mainfrom
fix/vm/usb-rct-spec-hash

Conversation

@danilrwx

@danilrwx danilrwx commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

Description

The controller decides whether the DRA claim template of a USBDevice is still up to date by comparing its stored spec with a freshly rendered one. Anything that mutates the stored spec on write — a new defaulted field in a future Kubernetes release, or a mutating admission policy in the user's cluster — makes that comparison permanently false: the controller then deletes and recreates the template on every reconcile, forever, producing constant API churn and event spam that never converges.

Each template now carries a fingerprint of the spec it was rendered from, and the controller compares fingerprints instead of live objects (the same approach already used for tolerations). Templates created before this change keep the old direct comparison until they are legitimately recreated, so nothing is churned on upgrade.

Why do we need it, and what problem does it solve?

This is a latent-bug fix: today the comparison holds because the controller explicitly sets every field the API server currently defaults. The first Kubernetes release that defaults a new field in claim specs — or any cluster-side mutating policy touching claim templates — would silently put every USBDevice into an endless recreate loop.

What is the expected result?

  1. Create a USBDevice; its claim template is created with an internal spec-fingerprint annotation and stays untouched across reconciles.
  2. Mutate the stored template spec externally (or upgrade to a Kubernetes version that defaults a new claim-spec field) — the template is not endlessly recreated.
  3. Templates existing before the module upgrade are left as is until their device attributes actually change.

Checklist

  • The code is covered by unit tests.
  • e2e tests passed.
  • Documentation updated according to the changes. — Not applicable: no user-facing API or behavior change.
  • Changes were tested in the Kubernetes cluster manually.

Changelog entries

section: vm
type: fix
summary: "USB device claim templates are no longer endlessly recreated when the Kubernetes API server or an admission policy mutates their stored spec."

Comparing the stored spec with the rendered one via DeepEqual breaks as
soon as the API server defaults any field absent from the rendered spec:
the comparison never converges and the handler deletes and recreates the
template on every reconcile. The USB template spec is especially exposed
because it embeds ObjectMeta with annotations. Stamp the rendered spec
hash into an annotation and compare hashes instead, following the
tolerations-hash pattern. A template without the annotation counts as
outdated and is recreated once.

Signed-off-by: Daniil Antoshin <daniil.antoshin@flant.com>
… hash

Templates created before the hash annotation existed would otherwise be
recreated once on controller upgrade. Compare their stored spec directly
instead; they migrate to the hash on their next legitimate recreation.

Signed-off-by: Daniil Antoshin <daniil.antoshin@flant.com>
@danilrwx danilrwx marked this pull request as ready for review July 9, 2026 13:59
@danilrwx danilrwx added this to the v1.10.0 milestone Jul 9, 2026
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