Skip to content

Commit

Permalink
Pci device plugin fix orphan goroutine and remove unused channel
Browse files Browse the repository at this point in the history
Signed-off-by: Webber Huang <[email protected]>
  • Loading branch information
WebberHuang1118 committed Feb 20, 2024
1 parent 82535bf commit 10da8fc
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 19 deletions.
6 changes: 2 additions & 4 deletions pkg/controller/gpudevice/vgpu_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,13 @@ import (
"reflect"
"sync"

"github.com/google/uuid"
"github.com/sirupsen/logrus"
apierrors "k8s.io/apimachinery/pkg/api/errors"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/labels"
kubevirtv1 "kubevirt.io/api/core/v1"

"github.com/google/uuid"
"github.com/sirupsen/logrus"

"github.com/harvester/pcidevices/pkg/apis/devices.harvesterhci.io/v1beta1"
"github.com/harvester/pcidevices/pkg/deviceplugins"
"github.com/harvester/pcidevices/pkg/util/gpuhelper"
Expand Down
9 changes: 3 additions & 6 deletions pkg/controller/pcideviceclaim/pcideviceclaim_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -424,17 +424,14 @@ func (h *Handler) startDevicePlugin(
if dp.Started() {
return nil
}
// Start the plugin
stop := make(chan struct{})

go func() {
err := dp.Start(stop)
err := dp.Start()
if err != nil {
logrus.Errorf("error starting %s device plugin: %s", dp.GetDeviceName(), err)
}
// TODO: test if deleting this stops the DevicePlugin
<-stop
}()
dp.SetStarted(stop)
dp.SetStarted()
return nil
}

Expand Down
11 changes: 2 additions & 9 deletions pkg/deviceplugins/device_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ type PCIDevicePlugin struct {
devs []*pluginapi.Device
server *grpc.Server
socketPath string
stop <-chan struct{}
health chan deviceHealth
devicePath string
resourceName string
Expand Down Expand Up @@ -150,9 +149,8 @@ func constructDPIdevices(pciDevices []*PCIDevice, iommuToPCIMap map[string]strin
var defaultBackoffTime = []time.Duration{1 * time.Second, 2 * time.Second, 5 * time.Second, 10 * time.Second}

// Set Started is used after a call to Start. It's purpose is to set the private starter properly
func (dp *PCIDevicePlugin) SetStarted(stop chan struct{}) {
func (dp *PCIDevicePlugin) SetStarted() {
c := dp.starter
c.stopChan = stop
c.started = true
logrus.Infof("Started DevicePlugin: %s", dp.resourceName)
}
Expand All @@ -166,9 +164,8 @@ func (dp *PCIDevicePlugin) Stop() error {
}

// Start starts the device plugin
func (dp *PCIDevicePlugin) Start(stop <-chan struct{}) (err error) {
func (dp *PCIDevicePlugin) Start() (err error) {
logger := log.DefaultLogger()
dp.stop = stop
dp.done = make(chan struct{})
dp.deregistered = make(chan struct{})

Expand Down Expand Up @@ -235,8 +232,6 @@ func (dp *PCIDevicePlugin) ListAndWatch(_ *pluginapi.Empty, s pluginapi.DevicePl
return err
}
logrus.Debugf("Sending ListAndWatchResponse for device with dpi.devs = %v", dp.devs)
case <-dp.stop:
done = true
case <-dp.done:
done = true
}
Expand Down Expand Up @@ -350,8 +345,6 @@ func (dp *PCIDevicePlugin) healthCheck() error {

for {
select {
case <-dp.stop:
return nil
case err := <-watcher.Errors:
logger.Reason(err).Errorf("error watching devices and device plugin directory")
case event := <-watcher.Events:
Expand Down

0 comments on commit 10da8fc

Please sign in to comment.