Skip to content

Commit

Permalink
fix: skip resource doesn't match the node
Browse files Browse the repository at this point in the history
Signed-off-by: Jack Yu <jack.yu@suse.com>
  • Loading branch information
Yu-Jack committed Jul 3, 2024
1 parent 45bfbb0 commit bd8f370
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
10 changes: 10 additions & 0 deletions pkg/controller/usbdevice/usbdevice_claim_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down Expand Up @@ -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()

Expand Down
3 changes: 2 additions & 1 deletion pkg/controller/usbdevice/usbdevice_claim_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ var (
{
APIVersion: "devices.harvesterhci.io/v1beta1",
Kind: "USBDevice",
Name: "test-node-0951-1666-001002",
Name: "test-node",
UID: "test-uid",
},
},
Expand All @@ -72,6 +72,7 @@ var (
)

func Test_OnUSBDeviceClaimChanged(t *testing.T) {
cl.nodeName = "test-node"
testcases := []struct {
fun func(t *testing.T)
description string
Expand Down

0 comments on commit bd8f370

Please sign in to comment.