Class OrphanedVMCleanupPeriodicWork

All Implemented Interfaces:
ExtensionPoint, Runnable

@Extension public class OrphanedVMCleanupPeriodicWork extends AsyncPeriodicWork
Periodic background task that detects and cleans up orphaned VMs in Kubernetes.

A VM is considered orphaned if:

  • It exists in Kubernetes with our cloud label
  • No corresponding Jenkins agent is registered
  • It has existed for longer than the template's grace period (to avoid deleting VMs still provisioning)

This provides a safety net for scenarios where:

  • Agent registration failed after VM creation
  • Jenkins crashed/restarted during provisioning
  • Network issues prevented proper cleanup
  • The _terminate callback failed to delete the VM