Skip to content

fix(usb): autodelete nodeusbdevice#2220

Open
danilrwx wants to merge 3 commits intomainfrom
fix/usb/autodelete-nodeusbdevice
Open

fix(usb): autodelete nodeusbdevice#2220
danilrwx wants to merge 3 commits intomainfrom
fix/usb/autodelete-nodeusbdevice

Conversation

@danilrwx
Copy link
Copy Markdown
Contributor

@danilrwx danilrwx commented Apr 15, 2026

Description

Implement automatic cleanup of stale NodeUSBDevice objects when the USB device is no longer present on the host and the object is not assigned to any namespace.

The deletion flow was moved to the lifecycle handler logic:

  • add and persist FinalizerNodeUSBDeviceCleanup first;
  • only after that, mark orphaned NodeUSBDevice for deletion;
  • perform USBDevice cleanup only in the standard deletion path after deletionTimestamp is set.

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

A detached or disappeared USB device could leave behind an unassigned NodeUSBDevice with Ready=False and Reason=NotFound.
Such objects are stale and should be removed automatically, but the cleanup must still respect the Kubernetes finalizer flow to avoid deleting the parent object before owned USBDevice resources are cleaned up.

This change makes the behavior safe and deterministic:

  • stale unassigned NodeUSBDevice objects are removed automatically;
  • owned USBDevice objects are cleaned through the normal finalizer-based deletion lifecycle;
  • cleanup is not performed before the finalizer is persisted.

What is the expected result?

  1. A USB device disappears from the host.
  2. The corresponding unassigned NodeUSBDevice gets Ready=False with Reason=NotFound.
  3. The controller persists the cleanup finalizer if it is missing.
  4. On the next reconcile, the controller requests deletion of the NodeUSBDevice.
  5. After deletionTimestamp is set, the controller removes owned USBDevice resources and then removes the finalizer.
  6. The stale NodeUSBDevice is deleted automatically.

Checklist

  • The code is covered by unit tests.
  • e2e tests passed.
  • Documentation updated according to the changes.
  • Changes were tested in the Kubernetes cluster manually.

Changelog entries

section: core
type: fix
summary: "Automatically delete stale unassigned NodeUSBDevice objects after finalizer-based cleanup."

Signed-off-by: Daniil Antoshin <daniil.antoshin@flant.com>
Signed-off-by: Daniil Antoshin <daniil.antoshin@flant.com>
Signed-off-by: Daniil Antoshin <daniil.antoshin@flant.com>
@danilrwx danilrwx added this to the v1.8.0 milestone Apr 15, 2026
@danilrwx danilrwx marked this pull request as ready for review April 15, 2026 13:01
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