mirror of
https://github.com/intel/intel-device-plugins-for-kubernetes.git
synced 2025-06-03 03:59:37 +00:00
replace glog with simpler home-grown debug logging
This commit is contained in:
parent
2ff6c5929a
commit
eccd70c600
@ -33,10 +33,6 @@ ignored = ["k8s.io/code-generator"]
|
||||
non-go = false
|
||||
unused-packages = false
|
||||
|
||||
[[constraint]]
|
||||
branch = "master"
|
||||
name = "github.com/golang/glog"
|
||||
|
||||
[[constraint]]
|
||||
name = "google.golang.org/grpc"
|
||||
version = "1.11.0"
|
||||
|
2
Makefile
2
Makefile
@ -21,7 +21,7 @@ ifndef WHAT
|
||||
@$(GO) test -race -coverprofile=coverage.txt -covermode=atomic $(pkgs)
|
||||
else
|
||||
@cd $(WHAT) && \
|
||||
$(GO) test -v -cover -coverprofile cover.out -args -logtostderr -v 2 || rc=1; \
|
||||
$(GO) test -v -cover -coverprofile cover.out || rc=1; \
|
||||
$(GO) tool cover -html=cover.out -o coverage.html; \
|
||||
rm cover.out; \
|
||||
echo "Coverage report: file://$$(realpath coverage.html)"; \
|
||||
|
@ -7,4 +7,4 @@ RUN chmod a+x /go/bin/fpga_plugin
|
||||
|
||||
FROM alpine
|
||||
COPY --from=builder /go/bin/fpga_plugin /usr/bin/intel_fpga_device_plugin
|
||||
CMD ["/usr/bin/intel_fpga_device_plugin", "-logtostderr"]
|
||||
CMD ["/usr/bin/intel_fpga_device_plugin"]
|
||||
|
@ -18,7 +18,6 @@ import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/golang/glog"
|
||||
"github.com/pkg/errors"
|
||||
|
||||
k8serrors "k8s.io/apimachinery/pkg/api/errors"
|
||||
@ -31,6 +30,7 @@ import (
|
||||
clientset "github.com/intel/intel-device-plugins-for-kubernetes/pkg/client/clientset/versioned"
|
||||
informers "github.com/intel/intel-device-plugins-for-kubernetes/pkg/client/informers/externalversions"
|
||||
listers "github.com/intel/intel-device-plugins-for-kubernetes/pkg/client/listers/fpga.intel.com/v1"
|
||||
"github.com/intel/intel-device-plugins-for-kubernetes/pkg/debug"
|
||||
)
|
||||
|
||||
const (
|
||||
@ -89,7 +89,7 @@ func (c *controller) run(threadiness int) error {
|
||||
defer runtime.HandleCrash()
|
||||
defer c.queue.ShutDown()
|
||||
|
||||
glog.Info("Starting controller")
|
||||
fmt.Println("Starting controller")
|
||||
|
||||
go c.informerFactory.Start(c.stopCh)
|
||||
|
||||
@ -153,7 +153,7 @@ func (c *controller) processNextWorkItem() bool {
|
||||
// Finally, if no error occurs we Forget this item so it does not
|
||||
// get queued again until another change happens.
|
||||
c.queue.Forget(obj)
|
||||
glog.V(2).Infof("Successfully synced '%s'", key)
|
||||
debug.Printf("Successfully synced '%s'", key)
|
||||
return nil
|
||||
}(obj)
|
||||
|
||||
@ -180,7 +180,7 @@ func (c *controller) syncAfHandler(key string) error {
|
||||
// processing.
|
||||
if k8serrors.IsNotFound(err) {
|
||||
runtime.HandleError(errors.Errorf("accelerated function '%s' in work queue no longer exists", key))
|
||||
glog.V(2).Infof("AF '%s' no longer exists", key)
|
||||
debug.Printf("AF '%s' no longer exists", key)
|
||||
c.patcher.removeAf(name)
|
||||
return nil
|
||||
}
|
||||
@ -188,7 +188,7 @@ func (c *controller) syncAfHandler(key string) error {
|
||||
return err
|
||||
}
|
||||
|
||||
glog.V(2).Info("Received ", af)
|
||||
debug.Print("Received", af)
|
||||
c.patcher.addAf(af)
|
||||
return nil
|
||||
}
|
||||
@ -208,7 +208,7 @@ func (c *controller) syncRegionHandler(key string) error {
|
||||
// processing.
|
||||
if k8serrors.IsNotFound(err) {
|
||||
runtime.HandleError(errors.Errorf("FPGA region '%s' in work queue no longer exists", key))
|
||||
glog.V(2).Infof("Region '%s' no longer exists", key)
|
||||
debug.Printf("Region '%s' no longer exists", key)
|
||||
c.patcher.removeRegion(name)
|
||||
return nil
|
||||
}
|
||||
@ -216,7 +216,7 @@ func (c *controller) syncRegionHandler(key string) error {
|
||||
return err
|
||||
}
|
||||
|
||||
glog.V(2).Info("Received ", region)
|
||||
debug.Print("Received", region)
|
||||
c.patcher.addRegion(region)
|
||||
return nil
|
||||
}
|
||||
|
@ -25,6 +25,7 @@ import (
|
||||
|
||||
v1 "github.com/intel/intel-device-plugins-for-kubernetes/pkg/apis/fpga.intel.com/v1"
|
||||
listers "github.com/intel/intel-device-plugins-for-kubernetes/pkg/client/listers/fpga.intel.com/v1"
|
||||
"github.com/intel/intel-device-plugins-for-kubernetes/pkg/debug"
|
||||
)
|
||||
|
||||
type fakeAfNamespaceLister struct {
|
||||
@ -32,6 +33,10 @@ type fakeAfNamespaceLister struct {
|
||||
err error
|
||||
}
|
||||
|
||||
func init() {
|
||||
debug.Activate()
|
||||
}
|
||||
|
||||
func (nl *fakeAfNamespaceLister) Get(name string) (*v1.AcceleratorFunction, error) {
|
||||
return nl.af, nl.err
|
||||
}
|
||||
|
@ -24,7 +24,6 @@ import (
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/golang/glog"
|
||||
"github.com/pkg/errors"
|
||||
|
||||
"k8s.io/api/admission/v1beta1"
|
||||
@ -36,6 +35,8 @@ import (
|
||||
"k8s.io/apimachinery/pkg/types"
|
||||
"k8s.io/client-go/rest"
|
||||
"k8s.io/client-go/tools/clientcmd"
|
||||
|
||||
"github.com/intel/intel-device-plugins-for-kubernetes/pkg/debug"
|
||||
)
|
||||
|
||||
const (
|
||||
@ -71,11 +72,11 @@ func getTLSConfig(certFile string, keyFile string) *tls.Config {
|
||||
func mutatePods(ar v1beta1.AdmissionReview, p *patcher) *v1beta1.AdmissionResponse {
|
||||
var ops []string
|
||||
|
||||
glog.V(2).Info("mutating pods")
|
||||
debug.Print("mutating pods")
|
||||
|
||||
podResource := metav1.GroupVersionResource{Group: "", Version: "v1", Resource: "pods"}
|
||||
if ar.Request.Resource != podResource {
|
||||
glog.Errorf("expect resource to be %s", podResource)
|
||||
fmt.Printf("WARNING: Unexpected resource type %s\n", ar.Request.Resource)
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -128,7 +129,7 @@ func serve(w http.ResponseWriter, r *http.Request, admit admitFunc) {
|
||||
}
|
||||
|
||||
if len(body) == 0 {
|
||||
glog.Error("No body in request")
|
||||
debug.Print("No body in request")
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
@ -136,16 +137,16 @@ func serve(w http.ResponseWriter, r *http.Request, admit admitFunc) {
|
||||
// verify the content type is accurate
|
||||
contentType := r.Header.Get("Content-Type")
|
||||
if contentType != "application/json" {
|
||||
glog.Errorf("contentType=%s, expect application/json", contentType)
|
||||
debug.Printf("contentType=%s, expect application/json", contentType)
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
glog.V(2).Info(fmt.Sprintf("handling request: %s", string(body)))
|
||||
debug.Printf("handling request: %s", string(body))
|
||||
ar := v1beta1.AdmissionReview{}
|
||||
deserializer := codecs.UniversalDeserializer()
|
||||
if _, _, err := deserializer.Decode(body, nil, &ar); err != nil {
|
||||
glog.Error(err)
|
||||
fmt.Printf("ERROR: %+v\n", err)
|
||||
reviewResponse = toAdmissionResponse(err)
|
||||
} else {
|
||||
if ar.Request == nil {
|
||||
@ -156,7 +157,7 @@ func serve(w http.ResponseWriter, r *http.Request, admit admitFunc) {
|
||||
reviewResponse = admit(ar)
|
||||
}
|
||||
}
|
||||
glog.V(2).Info(fmt.Sprintf("sending response: %v", reviewResponse))
|
||||
debug.Print("sending response", reviewResponse)
|
||||
|
||||
response := v1beta1.AdmissionReview{}
|
||||
if reviewResponse != nil {
|
||||
@ -172,11 +173,11 @@ func serve(w http.ResponseWriter, r *http.Request, admit admitFunc) {
|
||||
|
||||
resp, err := json.Marshal(response)
|
||||
if err != nil {
|
||||
glog.Error(err)
|
||||
fmt.Println("ERROR:", err)
|
||||
return
|
||||
}
|
||||
if _, err := w.Write(resp); err != nil {
|
||||
glog.Error(err)
|
||||
fmt.Println("ERROR:", err)
|
||||
}
|
||||
}
|
||||
|
||||
@ -201,6 +202,7 @@ func main() {
|
||||
var mode string
|
||||
var config *rest.Config
|
||||
var err error
|
||||
var debugEnabled bool
|
||||
|
||||
flag.StringVar(&kubeconfig, "kubeconfig", "", "absolute path to the kubeconfig file")
|
||||
flag.StringVar(&master, "master", "", "master url")
|
||||
@ -208,25 +210,30 @@ func main() {
|
||||
"File containing the x509 Certificate for HTTPS. (CA cert, if any, concatenated after server cert).")
|
||||
flag.StringVar(&keyFile, "tls-private-key-file", keyFile, "File containing the x509 private key matching --tls-cert-file.")
|
||||
flag.StringVar(&mode, "mode", preprogrammed, fmt.Sprintf("webhook mode: '%s' (default) or '%s'", preprogrammed, orchestrated))
|
||||
flag.BoolVar(&debugEnabled, "debug", false, "enable debug output")
|
||||
flag.Parse()
|
||||
|
||||
if debugEnabled {
|
||||
debug.Activate()
|
||||
}
|
||||
|
||||
if certFile == "" {
|
||||
glog.Error("TLS certificate file is not set")
|
||||
fmt.Println("TLS certificate file is not set")
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
if keyFile == "" {
|
||||
glog.Error("TLS private key is not set")
|
||||
fmt.Println("TLS private key is not set")
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
if _, err = os.Stat(certFile); err != nil {
|
||||
glog.Error("TLS certificate not found")
|
||||
fmt.Println("TLS certificate not found")
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
if _, err = os.Stat(keyFile); err != nil {
|
||||
glog.Error("TLS private key not found")
|
||||
fmt.Println("TLS private key not found")
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
@ -236,7 +243,7 @@ func main() {
|
||||
config, err = clientcmd.BuildConfigFromFlags(master, kubeconfig)
|
||||
}
|
||||
if err != nil {
|
||||
glog.Error("Failed to get cluster config ", err)
|
||||
fmt.Println("Failed to get cluster config ", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
@ -253,7 +260,7 @@ func main() {
|
||||
|
||||
http.HandleFunc("/pods", makePodsHandler(patcher))
|
||||
|
||||
glog.V(2).Info("Webhook started")
|
||||
debug.Print("Webhook started")
|
||||
|
||||
server := &http.Server{
|
||||
Addr: ":443",
|
||||
|
@ -28,8 +28,14 @@ import (
|
||||
"k8s.io/apimachinery/pkg/api/resource"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/runtime"
|
||||
|
||||
"github.com/intel/intel-device-plugins-for-kubernetes/pkg/debug"
|
||||
)
|
||||
|
||||
func init() {
|
||||
debug.Activate()
|
||||
}
|
||||
|
||||
func fakeMutatePods(ar v1beta1.AdmissionReview) *v1beta1.AdmissionResponse {
|
||||
reviewResponse := v1beta1.AdmissionResponse{}
|
||||
return &reviewResponse
|
||||
|
@ -22,8 +22,13 @@ import (
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
|
||||
fpgav1 "github.com/intel/intel-device-plugins-for-kubernetes/pkg/apis/fpga.intel.com/v1"
|
||||
"github.com/intel/intel-device-plugins-for-kubernetes/pkg/debug"
|
||||
)
|
||||
|
||||
func init() {
|
||||
debug.Activate()
|
||||
}
|
||||
|
||||
func TestPatcherStorageFunctions(t *testing.T) {
|
||||
af := &fpgav1.AcceleratorFunction{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
|
@ -22,8 +22,14 @@ import (
|
||||
|
||||
"k8s.io/utils/exec"
|
||||
fakeexec "k8s.io/utils/exec/testing"
|
||||
|
||||
"github.com/intel/intel-device-plugins-for-kubernetes/pkg/debug"
|
||||
)
|
||||
|
||||
func init() {
|
||||
debug.Activate()
|
||||
}
|
||||
|
||||
func TestGetFPGAParams(t *testing.T) {
|
||||
tcases := []struct {
|
||||
stdinJSON string
|
||||
|
@ -24,7 +24,6 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/golang/glog"
|
||||
"github.com/pkg/errors"
|
||||
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
@ -35,6 +34,7 @@ import (
|
||||
utilnode "k8s.io/kubernetes/pkg/util/node"
|
||||
|
||||
dpapi "github.com/intel/intel-device-plugins-for-kubernetes/internal/deviceplugin"
|
||||
"github.com/intel/intel-device-plugins-for-kubernetes/pkg/debug"
|
||||
)
|
||||
|
||||
const (
|
||||
@ -237,7 +237,7 @@ func (dp *devicePlugin) getDevNode(devName string) (string, error) {
|
||||
func (dp *devicePlugin) scanFPGAs() (dpapi.DeviceTree, error) {
|
||||
var devices []device
|
||||
|
||||
glog.V(2).Info("Start new FPGA scan")
|
||||
debug.Print("Start new FPGA scan")
|
||||
|
||||
fpgaFiles, err := ioutil.ReadDir(dp.sysfsDir)
|
||||
if err != nil {
|
||||
@ -340,13 +340,19 @@ func main() {
|
||||
var master string
|
||||
var config *rest.Config
|
||||
var err error
|
||||
var debugEnabled bool
|
||||
|
||||
flag.StringVar(&kubeconfig, "kubeconfig", "", "absolute path to the kubeconfig file")
|
||||
flag.StringVar(&master, "master", "", "master url")
|
||||
flag.StringVar(&mode, "mode", string(afMode),
|
||||
fmt.Sprintf("device plugin mode: '%s' (default), '%s' or '%s'", afMode, regionMode, regionDevelMode))
|
||||
flag.BoolVar(&debugEnabled, "debug", false, "enable debug output")
|
||||
flag.Parse()
|
||||
|
||||
if debugEnabled {
|
||||
debug.Activate()
|
||||
}
|
||||
|
||||
if kubeconfig == "" {
|
||||
config, err = rest.InClusterConfig()
|
||||
} else {
|
||||
@ -370,7 +376,7 @@ func main() {
|
||||
}
|
||||
|
||||
if nodeMode, ok := node.ObjectMeta.Annotations["fpga.intel.com/device-plugin-mode"]; ok {
|
||||
glog.Info("Overriding mode to ", nodeMode)
|
||||
fmt.Println("Overriding mode to ", nodeMode)
|
||||
mode = nodeMode
|
||||
}
|
||||
|
||||
@ -379,7 +385,7 @@ func main() {
|
||||
fatal(err)
|
||||
}
|
||||
|
||||
glog.Info("FPGA device plugin started in ", mode, " mode")
|
||||
fmt.Println("FPGA device plugin started in ", mode, " mode")
|
||||
|
||||
manager := dpapi.NewManager(namespace, plugin)
|
||||
manager.Run()
|
||||
|
@ -29,8 +29,13 @@ import (
|
||||
pluginapi "k8s.io/kubernetes/pkg/kubelet/apis/deviceplugin/v1beta1"
|
||||
|
||||
dpapi "github.com/intel/intel-device-plugins-for-kubernetes/internal/deviceplugin"
|
||||
"github.com/intel/intel-device-plugins-for-kubernetes/pkg/debug"
|
||||
)
|
||||
|
||||
func init() {
|
||||
debug.Activate()
|
||||
}
|
||||
|
||||
func createTestDirs(devfs, sysfs string, devfsDirs, sysfsDirs []string, sysfsFiles map[string][]byte) error {
|
||||
var err error
|
||||
|
||||
|
@ -24,12 +24,12 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/golang/glog"
|
||||
"github.com/pkg/errors"
|
||||
|
||||
pluginapi "k8s.io/kubernetes/pkg/kubelet/apis/deviceplugin/v1beta1"
|
||||
|
||||
dpapi "github.com/intel/intel-device-plugins-for-kubernetes/internal/deviceplugin"
|
||||
"github.com/intel/intel-device-plugins-for-kubernetes/pkg/debug"
|
||||
)
|
||||
|
||||
const (
|
||||
@ -88,7 +88,7 @@ func (dp *devicePlugin) scan() (dpapi.DeviceTree, error) {
|
||||
if dp.gpuDeviceReg.MatchString(f.Name()) {
|
||||
dat, err := ioutil.ReadFile(path.Join(dp.sysfsDir, f.Name(), "device/vendor"))
|
||||
if err != nil {
|
||||
glog.Warning("Skipping. Can't read vendor file: ", err)
|
||||
fmt.Println("WARNING: Skipping. Can't read vendor file: ", err)
|
||||
continue
|
||||
}
|
||||
|
||||
@ -110,7 +110,7 @@ func (dp *devicePlugin) scan() (dpapi.DeviceTree, error) {
|
||||
continue
|
||||
}
|
||||
|
||||
glog.V(2).Info("Adding ", devPath, " to GPU ", f.Name())
|
||||
debug.Printf("Adding %s to GPU %s", devPath, f.Name())
|
||||
nodes = append(nodes, devPath)
|
||||
}
|
||||
|
||||
@ -134,16 +134,22 @@ func (dp *devicePlugin) scan() (dpapi.DeviceTree, error) {
|
||||
|
||||
func main() {
|
||||
var sharedDevNum int
|
||||
var debugEnabled bool
|
||||
|
||||
flag.IntVar(&sharedDevNum, "shared-dev-num", 1, "number of containers sharing the same GPU device")
|
||||
flag.BoolVar(&debugEnabled, "debug", false, "enable debug output")
|
||||
flag.Parse()
|
||||
|
||||
if debugEnabled {
|
||||
debug.Activate()
|
||||
}
|
||||
|
||||
if sharedDevNum < 1 {
|
||||
glog.Error("The number of containers sharing the same GPU must greater than zero")
|
||||
fmt.Println("The number of containers sharing the same GPU must greater than zero")
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
glog.Info("GPU device plugin started")
|
||||
fmt.Println("GPU device plugin started")
|
||||
|
||||
plugin := newDevicePlugin(sysfsDrmDirectory, devfsDriDirectory, sharedDevNum)
|
||||
manager := dpapi.NewManager(namespace, plugin)
|
||||
|
@ -21,8 +21,14 @@ import (
|
||||
"path"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/intel/intel-device-plugins-for-kubernetes/pkg/debug"
|
||||
)
|
||||
|
||||
func init() {
|
||||
debug.Activate()
|
||||
}
|
||||
|
||||
func TestScan(t *testing.T) {
|
||||
tmpdir := fmt.Sprintf("/tmp/gpuplugin-test-%d", time.Now().Unix())
|
||||
sysfs := path.Join(tmpdir, "sysfs")
|
||||
|
@ -35,7 +35,7 @@ $ ls /var/lib/kubelet/device-plugins/kubelet.sock
|
||||
### Deploy QAT device plugin directly on the host:
|
||||
```
|
||||
$ sudo $GOPATH/src/github.com/intel/intel-device-plugins-for-kubernetes/cmd/qat_plugin/qat_plugin \
|
||||
-dpdk-driver igb_uio -kernel-vf-drivers dh895xccvf -max-num-devices 10 -v 10 logtostderr
|
||||
-dpdk-driver igb_uio -kernel-vf-drivers dh895xccvf -max-num-devices 10 -debug
|
||||
QAT device plugin started
|
||||
Discovered Devices below:
|
||||
03:01.0 device: corresponding DPDK device detected is uio0
|
||||
|
@ -25,12 +25,12 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/golang/glog"
|
||||
"github.com/pkg/errors"
|
||||
|
||||
pluginapi "k8s.io/kubernetes/pkg/kubelet/apis/deviceplugin/v1beta1"
|
||||
|
||||
"github.com/intel/intel-device-plugins-for-kubernetes/internal/deviceplugin"
|
||||
"github.com/intel/intel-device-plugins-for-kubernetes/pkg/debug"
|
||||
)
|
||||
|
||||
const (
|
||||
@ -263,9 +263,14 @@ func main() {
|
||||
dpdkDriver := flag.String("dpdk-driver", "igb_uio", "DPDK Device driver for configuring the QAT device")
|
||||
kernelVfDrivers := flag.String("kernel-vf-drivers", "dh895xccvf,c6xxvf,c3xxxvf,d15xxvf", "Comma separated VF Device Driver of the QuickAssist Devices in the system. Devices supported: DH895xCC,C62x,C3xxx and D15xx")
|
||||
maxNumDevices := flag.Int("max-num-devices", 32, "maximum number of QAT devices to be provided to the QuickAssist device plugin")
|
||||
debugEnabled := flag.Bool("debug", false, "enable debug output")
|
||||
flag.Parse()
|
||||
fmt.Println("QAT device plugin started")
|
||||
|
||||
if *debugEnabled {
|
||||
debug.Activate()
|
||||
}
|
||||
|
||||
if !isValidDpdkDeviceDriver(*dpdkDriver) {
|
||||
fmt.Println("Wrong DPDK device driver:", *dpdkDriver)
|
||||
os.Exit(1)
|
||||
|
@ -23,8 +23,14 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
|
||||
"github.com/intel/intel-device-plugins-for-kubernetes/pkg/debug"
|
||||
)
|
||||
|
||||
func init() {
|
||||
debug.Activate()
|
||||
}
|
||||
|
||||
func createTestFiles(prefix string, dirs []string, files map[string][]byte) error {
|
||||
for _, dir := range dirs {
|
||||
err := os.MkdirAll(path.Join(prefix, dir), 0755)
|
||||
|
@ -21,9 +21,7 @@ spec:
|
||||
- -tls-cert-file=/etc/webhook/certs/cert.pem
|
||||
- -tls-private-key-file=/etc/webhook/certs/key.pem
|
||||
- -mode={MODE}
|
||||
- -alsologtostderr
|
||||
- -v=2
|
||||
- 2>&1
|
||||
- -debug
|
||||
volumeMounts:
|
||||
- name: webhook-certs
|
||||
mountPath: /etc/webhook/certs
|
||||
|
@ -19,9 +19,9 @@ import (
|
||||
"os"
|
||||
"reflect"
|
||||
|
||||
"github.com/golang/glog"
|
||||
|
||||
pluginapi "k8s.io/kubernetes/pkg/kubelet/apis/deviceplugin/v1beta1"
|
||||
|
||||
"github.com/intel/intel-device-plugins-for-kubernetes/pkg/debug"
|
||||
)
|
||||
|
||||
// updateInfo contains info for added, updated and deleted devices.
|
||||
@ -107,7 +107,7 @@ func (m *Manager) Run() {
|
||||
}
|
||||
|
||||
func (m *Manager) handleUpdate(update updateInfo) {
|
||||
glog.V(2).Info("Received dev updates: ", update)
|
||||
debug.Print("Received dev updates:", update)
|
||||
for devType, devices := range update.Added {
|
||||
var postAllocate func(*pluginapi.AllocateResponse) error
|
||||
|
||||
|
@ -18,8 +18,14 @@ import (
|
||||
"testing"
|
||||
|
||||
pluginapi "k8s.io/kubernetes/pkg/kubelet/apis/deviceplugin/v1beta1"
|
||||
|
||||
"github.com/intel/intel-device-plugins-for-kubernetes/pkg/debug"
|
||||
)
|
||||
|
||||
func init() {
|
||||
debug.Activate()
|
||||
}
|
||||
|
||||
func TestNotify(t *testing.T) {
|
||||
tcases := []struct {
|
||||
name string
|
||||
|
@ -24,11 +24,12 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/fsnotify/fsnotify"
|
||||
"github.com/golang/glog"
|
||||
"github.com/pkg/errors"
|
||||
"google.golang.org/grpc"
|
||||
|
||||
pluginapi "k8s.io/kubernetes/pkg/kubelet/apis/deviceplugin/v1beta1"
|
||||
|
||||
"github.com/intel/intel-device-plugins-for-kubernetes/pkg/debug"
|
||||
)
|
||||
|
||||
// devicePluginServer maintains a gRPC server satisfying
|
||||
@ -69,7 +70,7 @@ func (srv *server) sendDevices(stream pluginapi.DevicePlugin_ListAndWatchServer)
|
||||
for id, device := range srv.devices {
|
||||
resp.Devices = append(resp.Devices, &pluginapi.Device{id, device.State})
|
||||
}
|
||||
glog.V(2).Info("Sending to kubelet ", resp.Devices)
|
||||
debug.Print("Sending to kubelet", resp.Devices)
|
||||
if err := stream.Send(resp); err != nil {
|
||||
srv.Stop()
|
||||
return errors.Wrapf(err, "Cannot update device list")
|
||||
@ -79,7 +80,7 @@ func (srv *server) sendDevices(stream pluginapi.DevicePlugin_ListAndWatchServer)
|
||||
}
|
||||
|
||||
func (srv *server) ListAndWatch(empty *pluginapi.Empty, stream pluginapi.DevicePlugin_ListAndWatchServer) error {
|
||||
glog.V(2).Info("Started ListAndWatch for ", srv.devType)
|
||||
debug.Print("Started ListAndWatch for", srv.devType)
|
||||
|
||||
if err := srv.sendDevices(stream); err != nil {
|
||||
return err
|
||||
@ -187,7 +188,7 @@ func (srv *server) setupAndServe(namespace string, devicePluginPath string, kube
|
||||
|
||||
// Starts device plugin service.
|
||||
go func() {
|
||||
fmt.Printf("device-plugin start server at: %s\n", pluginSocket)
|
||||
fmt.Printf("Start server for %s at: %s\n", srv.devType, pluginSocket)
|
||||
srv.grpcServer.Serve(lis)
|
||||
}()
|
||||
|
||||
@ -201,16 +202,14 @@ func (srv *server) setupAndServe(namespace string, devicePluginPath string, kube
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
fmt.Println("device-plugin registered")
|
||||
fmt.Printf("Device plugin for %s registered\n", srv.devType)
|
||||
|
||||
// Kubelet removes plugin socket when it (re)starts
|
||||
// plugin must restart in this case
|
||||
if err = watchFile(pluginSocket); err != nil {
|
||||
return err
|
||||
}
|
||||
fmt.Printf("socket %s removed, restarting", pluginSocket)
|
||||
|
||||
fmt.Println("stop GRPC server")
|
||||
fmt.Printf("Socket %s removed, restarting\n", pluginSocket)
|
||||
|
||||
srv.grpcServer.Stop()
|
||||
os.Remove(pluginSocket)
|
||||
|
@ -29,6 +29,7 @@ import (
|
||||
|
||||
pluginapi "k8s.io/kubernetes/pkg/kubelet/apis/deviceplugin/v1beta1"
|
||||
|
||||
"github.com/intel/intel-device-plugins-for-kubernetes/pkg/debug"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
@ -47,6 +48,10 @@ type kubeletStub struct {
|
||||
server *grpc.Server
|
||||
}
|
||||
|
||||
func init() {
|
||||
debug.Activate()
|
||||
}
|
||||
|
||||
// newKubeletStub returns an initialized kubeletStub for testing purpose.
|
||||
func newKubeletStub(socket string) *kubeletStub {
|
||||
return &kubeletStub{
|
||||
|
57
pkg/debug/debug.go
Normal file
57
pkg/debug/debug.go
Normal file
@ -0,0 +1,57 @@
|
||||
// Copyright 2018 Intel Corporation. All Rights Reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package debug
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"runtime"
|
||||
"strings"
|
||||
)
|
||||
|
||||
const (
|
||||
prefix = "DEBUG"
|
||||
)
|
||||
|
||||
var (
|
||||
isEnabled bool
|
||||
)
|
||||
|
||||
func getFileAndLine() string {
|
||||
_, file, line, ok := runtime.Caller(2)
|
||||
if !ok {
|
||||
return "???:0"
|
||||
}
|
||||
parts := strings.Split(file, "/")
|
||||
return fmt.Sprintf("%s:%d", parts[len(parts)-1], line)
|
||||
}
|
||||
|
||||
// Activate activates debugging output
|
||||
func Activate() {
|
||||
isEnabled = true
|
||||
}
|
||||
|
||||
// Print prints its arguments with fmt.Println() if debug output is activated
|
||||
func Print(obj ...interface{}) {
|
||||
if isEnabled {
|
||||
fmt.Println(append([]interface{}{prefix, getFileAndLine()}, obj...)...)
|
||||
}
|
||||
}
|
||||
|
||||
// Printf prints its arguments with fmt.Printf() if debug output is activated
|
||||
func Printf(pattern string, obj ...interface{}) {
|
||||
if isEnabled {
|
||||
fmt.Printf(strings.Join([]string{prefix, getFileAndLine(), pattern + "\n"}, " "), obj...)
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user