From 82713d0cf932d70749d1702381313b83b8f566d3 Mon Sep 17 00:00:00 2001 From: Graham Whaley Date: Mon, 16 Mar 2020 16:07:15 +0000 Subject: [PATCH] vpu: move to using klog Move to using klog for logging and debug for vpu plugin. Signed-off-by: Graham Whaley --- cmd/vpu_plugin/vpu_plugin.go | 24 +++++++++++++----------- cmd/vpu_plugin/vpu_plugin_test.go | 10 ++++++---- 2 files changed, 19 insertions(+), 15 deletions(-) diff --git a/cmd/vpu_plugin/vpu_plugin.go b/cmd/vpu_plugin/vpu_plugin.go index 7feb05b3..14496372 100644 --- a/cmd/vpu_plugin/vpu_plugin.go +++ b/cmd/vpu_plugin/vpu_plugin.go @@ -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) diff --git a/cmd/vpu_plugin/vpu_plugin_test.go b/cmd/vpu_plugin/vpu_plugin_test.go index 9dd3e116..02321426 100644 --- a/cmd/vpu_plugin/vpu_plugin_test.go +++ b/cmd/vpu_plugin/vpu_plugin_test.go @@ -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])) } }