squat / generic-device-plugin

A Kubernetes device plugin to schedule generic Linux devices
Apache License 2.0
210 stars 23 forks source link

Support for finding USB devices #2

Closed duckfullstop closed 1 year ago

duckfullstop commented 1 year ago

This PR adds support for exposing USB devices on /dev/bus/usb based on their vendor / product ID.

This is currently implemented by using a device string like the following:

'{"name": "ch340", "groups": [{"usb": [{"vendor": "1a86", "product": "7523"}]}]}'

This took a fair bit of work to avoid using google/gousb - doing so would have required linking libusb - which inside a container would be an absolute nightmare and probably require moving away from scratch. Instead, I enumerate /sys/bus/usb/devices directly - meaning this is all 100% native go. I have had to bump go to 1.19 in the process just to make life a little easier - this seems to have broken linting, guidance on that would be helpful.

Currently a draft, ~as I'm thinking about adding threading to the enumeration routine~ - otherwise feedback is greatly appreciated!

squat commented 1 year ago

nice! there's only one tiny linting error now because of the golang upgrade, which expects build flags to be different

duckfullstop commented 1 year ago

nice! there's only one tiny linting error now because of the golang upgrade, which expects build flags to be different

Whoops, thought I'd committed that lint change: 3acf0e5

duckfullstop commented 1 year ago

Have you been able to test this on a cluster?

I haven't tested full functionality, but it does at least find a dongle - this was just running a binary inside an Alpine container so I haven't tested it end-to-end.

I don't think we realistically have a way to add tests for this USB functionality in CI.

Could we spin a mock environment to discover mocked devices? I was struggling to figure out how to do integration tests, but I can add a few unit tests (though maybe a "test all the things" PR / epic makes more sense)

squat commented 1 year ago

Yeah, I'd support a new PR to add a e2e test suite to the project! I have some ideas for testing full e2e use of a mounted fuse device, for example.