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"
|
||||
"fmt"
|
||||
"os"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"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"
|
||||
"k8s.io/klog"
|
||||
pluginapi "k8s.io/kubelet/pkg/apis/deviceplugin/v1beta1"
|
||||
)
|
||||
|
||||
@ -41,7 +42,6 @@ const (
|
||||
)
|
||||
|
||||
var (
|
||||
isdebug = flag.Int("debug", 0, "debug level (0..1)")
|
||||
// Movidius MyriadX Product IDs
|
||||
productIDs = []int{0x2485, 0xf63b}
|
||||
)
|
||||
@ -101,7 +101,7 @@ func (dp *devicePlugin) scan() (dpapi.DeviceTree, error) {
|
||||
thisVendor := desc.Vendor
|
||||
thisProduct := desc.Product
|
||||
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) {
|
||||
nUsb++
|
||||
}
|
||||
@ -115,7 +115,7 @@ func (dp *devicePlugin) scan() (dpapi.DeviceTree, error) {
|
||||
}()
|
||||
|
||||
if err != nil {
|
||||
debug.Printf("list usb device %s", err)
|
||||
klog.V(4).Infof("list usb device %s", err)
|
||||
}
|
||||
|
||||
if nUsb > 0 {
|
||||
@ -159,22 +159,24 @@ func main() {
|
||||
|
||||
flag.Parse()
|
||||
|
||||
if *isdebug > 0 {
|
||||
debug.Activate()
|
||||
debug.Printf("isdebug is on")
|
||||
}
|
||||
klog.V(4).Info("debug is on")
|
||||
|
||||
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)
|
||||
}
|
||||
|
||||
fmt.Println("VPU device plugin started")
|
||||
klog.V(1).Info("VPU device plugin started")
|
||||
|
||||
// add lsusb here
|
||||
ctx := gousb.NewContext()
|
||||
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)
|
||||
manager := dpapi.NewManager(namespace, plugin)
|
||||
|
@ -15,14 +15,16 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/google/gousb"
|
||||
"github.com/intel/intel-device-plugins-for-kubernetes/pkg/debug"
|
||||
"flag"
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"github.com/google/gousb"
|
||||
"k8s.io/klog"
|
||||
)
|
||||
|
||||
func init() {
|
||||
debug.Activate()
|
||||
flag.Set("v", "4")
|
||||
}
|
||||
|
||||
type testCase struct {
|
||||
@ -69,6 +71,6 @@ func TestScan(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Error("vpu plugin test failed")
|
||||
} 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