Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pci device plugin fix orphan goroutine and remove unused channel #67

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading