diff --git a/pkg/controller/usbdevice/usbdevice_claim_controller.go b/pkg/controller/usbdevice/usbdevice_claim_controller.go index 061f563..dc55e4c 100644 --- a/pkg/controller/usbdevice/usbdevice_claim_controller.go +++ b/pkg/controller/usbdevice/usbdevice_claim_controller.go @@ -77,6 +77,11 @@ func (h *DevClaimHandler) OnUSBDeviceClaimChanged(_ string, usbDeviceClaim *v1be return usbDeviceClaim, err } + if usbDevice.Status.NodeName != cl.nodeName { + logrus.Infof("usbdevice %s is not in the node %s", usbDevice.Name, cl.nodeName) + return usbDeviceClaim, nil + } + h.lock.Lock() defer h.lock.Unlock() @@ -195,6 +200,11 @@ func (h *DevClaimHandler) OnRemove(_ string, claim *v1beta1.USBDeviceClaim) (*v1 return claim, err } + if usbDevice.Status.NodeName != cl.nodeName { + logrus.Infof("usbdevice %s is not in the node %s", usbDevice.Name, cl.nodeName) + return claim, nil + } + h.lock.Lock() defer h.lock.Unlock() diff --git a/pkg/controller/usbdevice/usbdevice_claim_controller_test.go b/pkg/controller/usbdevice/usbdevice_claim_controller_test.go index bc8ffe7..2dd840b 100644 --- a/pkg/controller/usbdevice/usbdevice_claim_controller_test.go +++ b/pkg/controller/usbdevice/usbdevice_claim_controller_test.go @@ -57,7 +57,7 @@ var ( { APIVersion: "devices.harvesterhci.io/v1beta1", Kind: "USBDevice", - Name: "test-node-0951-1666-001002", + Name: "test-node", UID: "test-uid", }, }, @@ -72,6 +72,7 @@ var ( ) func Test_OnUSBDeviceClaimChanged(t *testing.T) { + cl.nodeName = "test-node" testcases := []struct { fun func(t *testing.T) description string