mirror of
https://github.com/intel/intel-device-plugins-for-kubernetes.git
synced 2025-06-03 03:59:37 +00:00
vpu: move to using klog
Move to using klog for logging and debug for vpu plugin. Signed-off-by: Graham Whaley <graham.whaley@intel.com>
This commit is contained in:
parent
15d4b10715
commit
82713d0cf9
@ -18,12 +18,13 @@ import (
|
|||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
|
"strconv"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/google/gousb"
|
"github.com/google/gousb"
|
||||||
|
|
||||||
"github.com/intel/intel-device-plugins-for-kubernetes/pkg/debug"
|
|
||||||
dpapi "github.com/intel/intel-device-plugins-for-kubernetes/pkg/deviceplugin"
|
dpapi "github.com/intel/intel-device-plugins-for-kubernetes/pkg/deviceplugin"
|
||||||
|
"k8s.io/klog"
|
||||||
pluginapi "k8s.io/kubelet/pkg/apis/deviceplugin/v1beta1"
|
pluginapi "k8s.io/kubelet/pkg/apis/deviceplugin/v1beta1"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -41,7 +42,6 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
isdebug = flag.Int("debug", 0, "debug level (0..1)")
|
|
||||||
// Movidius MyriadX Product IDs
|
// Movidius MyriadX Product IDs
|
||||||
productIDs = []int{0x2485, 0xf63b}
|
productIDs = []int{0x2485, 0xf63b}
|
||||||
)
|
)
|
||||||
@ -101,7 +101,7 @@ func (dp *devicePlugin) scan() (dpapi.DeviceTree, error) {
|
|||||||
thisVendor := desc.Vendor
|
thisVendor := desc.Vendor
|
||||||
thisProduct := desc.Product
|
thisProduct := desc.Product
|
||||||
for _, v := range dp.productIDs {
|
for _, v := range dp.productIDs {
|
||||||
debug.Printf("checking %04x,%04x vs %s,%s", dp.vendorID, v, thisVendor.String(), thisProduct.String())
|
klog.V(4).Infof("checking %04x,%04x vs %s,%s", dp.vendorID, v, thisVendor.String(), thisProduct.String())
|
||||||
if (gousb.ID(dp.vendorID) == thisVendor) && (gousb.ID(v) == thisProduct) {
|
if (gousb.ID(dp.vendorID) == thisVendor) && (gousb.ID(v) == thisProduct) {
|
||||||
nUsb++
|
nUsb++
|
||||||
}
|
}
|
||||||
@ -115,7 +115,7 @@ func (dp *devicePlugin) scan() (dpapi.DeviceTree, error) {
|
|||||||
}()
|
}()
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
debug.Printf("list usb device %s", err)
|
klog.V(4).Infof("list usb device %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if nUsb > 0 {
|
if nUsb > 0 {
|
||||||
@ -159,22 +159,24 @@ func main() {
|
|||||||
|
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
if *isdebug > 0 {
|
klog.V(4).Info("debug is on")
|
||||||
debug.Activate()
|
|
||||||
debug.Printf("isdebug is on")
|
|
||||||
}
|
|
||||||
|
|
||||||
if sharedDevNum < 1 {
|
if sharedDevNum < 1 {
|
||||||
fmt.Println("The number of containers sharing the same VPU must greater than zero")
|
klog.Fatal("The number of containers sharing the same VPU must greater than zero")
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Println("VPU device plugin started")
|
klog.V(1).Info("VPU device plugin started")
|
||||||
|
|
||||||
// add lsusb here
|
// add lsusb here
|
||||||
ctx := gousb.NewContext()
|
ctx := gousb.NewContext()
|
||||||
defer ctx.Close()
|
defer ctx.Close()
|
||||||
ctx.Debug(*isdebug)
|
|
||||||
|
verbosityLevel, err := strconv.Atoi(flag.CommandLine.Lookup("v").Value.String())
|
||||||
|
if err == nil {
|
||||||
|
// gousb (libusb) Debug levels are a 1:1 match to klog levels, just pass through.
|
||||||
|
ctx.Debug(verbosityLevel)
|
||||||
|
}
|
||||||
|
|
||||||
plugin := newDevicePlugin(ctx, vendorID, productIDs, sharedDevNum)
|
plugin := newDevicePlugin(ctx, vendorID, productIDs, sharedDevNum)
|
||||||
manager := dpapi.NewManager(namespace, plugin)
|
manager := dpapi.NewManager(namespace, plugin)
|
||||||
|
@ -15,14 +15,16 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/google/gousb"
|
"flag"
|
||||||
"github.com/intel/intel-device-plugins-for-kubernetes/pkg/debug"
|
|
||||||
"os"
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/google/gousb"
|
||||||
|
"k8s.io/klog"
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
debug.Activate()
|
flag.Set("v", "4")
|
||||||
}
|
}
|
||||||
|
|
||||||
type testCase struct {
|
type testCase struct {
|
||||||
@ -69,6 +71,6 @@ func TestScan(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error("vpu plugin test failed")
|
t.Error("vpu plugin test failed")
|
||||||
} else {
|
} else {
|
||||||
debug.Printf("tree len is %d", len(tree[deviceType]))
|
klog.V(4).Infof("tree len is %d", len(tree[deviceType]))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user