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
|
non-go = false
|
||||||
unused-packages = false
|
unused-packages = false
|
||||||
|
|
||||||
[[constraint]]
|
|
||||||
branch = "master"
|
|
||||||
name = "github.com/golang/glog"
|
|
||||||
|
|
||||||
[[constraint]]
|
[[constraint]]
|
||||||
name = "google.golang.org/grpc"
|
name = "google.golang.org/grpc"
|
||||||
version = "1.11.0"
|
version = "1.11.0"
|
||||||
|
2
Makefile
2
Makefile
@ -21,7 +21,7 @@ ifndef WHAT
|
|||||||
@$(GO) test -race -coverprofile=coverage.txt -covermode=atomic $(pkgs)
|
@$(GO) test -race -coverprofile=coverage.txt -covermode=atomic $(pkgs)
|
||||||
else
|
else
|
||||||
@cd $(WHAT) && \
|
@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; \
|
$(GO) tool cover -html=cover.out -o coverage.html; \
|
||||||
rm cover.out; \
|
rm cover.out; \
|
||||||
echo "Coverage report: file://$$(realpath coverage.html)"; \
|
echo "Coverage report: file://$$(realpath coverage.html)"; \
|
||||||
|
@ -7,4 +7,4 @@ RUN chmod a+x /go/bin/fpga_plugin
|
|||||||
|
|
||||||
FROM alpine
|
FROM alpine
|
||||||
COPY --from=builder /go/bin/fpga_plugin /usr/bin/intel_fpga_device_plugin
|
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"
|
"fmt"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/golang/glog"
|
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
|
|
||||||
k8serrors "k8s.io/apimachinery/pkg/api/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"
|
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"
|
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"
|
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 (
|
const (
|
||||||
@ -89,7 +89,7 @@ func (c *controller) run(threadiness int) error {
|
|||||||
defer runtime.HandleCrash()
|
defer runtime.HandleCrash()
|
||||||
defer c.queue.ShutDown()
|
defer c.queue.ShutDown()
|
||||||
|
|
||||||
glog.Info("Starting controller")
|
fmt.Println("Starting controller")
|
||||||
|
|
||||||
go c.informerFactory.Start(c.stopCh)
|
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
|
// Finally, if no error occurs we Forget this item so it does not
|
||||||
// get queued again until another change happens.
|
// get queued again until another change happens.
|
||||||
c.queue.Forget(obj)
|
c.queue.Forget(obj)
|
||||||
glog.V(2).Infof("Successfully synced '%s'", key)
|
debug.Printf("Successfully synced '%s'", key)
|
||||||
return nil
|
return nil
|
||||||
}(obj)
|
}(obj)
|
||||||
|
|
||||||
@ -180,7 +180,7 @@ func (c *controller) syncAfHandler(key string) error {
|
|||||||
// processing.
|
// processing.
|
||||||
if k8serrors.IsNotFound(err) {
|
if k8serrors.IsNotFound(err) {
|
||||||
runtime.HandleError(errors.Errorf("accelerated function '%s' in work queue no longer exists", key))
|
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)
|
c.patcher.removeAf(name)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -188,7 +188,7 @@ func (c *controller) syncAfHandler(key string) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
glog.V(2).Info("Received ", af)
|
debug.Print("Received", af)
|
||||||
c.patcher.addAf(af)
|
c.patcher.addAf(af)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -208,7 +208,7 @@ func (c *controller) syncRegionHandler(key string) error {
|
|||||||
// processing.
|
// processing.
|
||||||
if k8serrors.IsNotFound(err) {
|
if k8serrors.IsNotFound(err) {
|
||||||
runtime.HandleError(errors.Errorf("FPGA region '%s' in work queue no longer exists", key))
|
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)
|
c.patcher.removeRegion(name)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -216,7 +216,7 @@ func (c *controller) syncRegionHandler(key string) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
glog.V(2).Info("Received ", region)
|
debug.Print("Received", region)
|
||||||
c.patcher.addRegion(region)
|
c.patcher.addRegion(region)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -25,6 +25,7 @@ import (
|
|||||||
|
|
||||||
v1 "github.com/intel/intel-device-plugins-for-kubernetes/pkg/apis/fpga.intel.com/v1"
|
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"
|
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 {
|
type fakeAfNamespaceLister struct {
|
||||||
@ -32,6 +33,10 @@ type fakeAfNamespaceLister struct {
|
|||||||
err error
|
err error
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
debug.Activate()
|
||||||
|
}
|
||||||
|
|
||||||
func (nl *fakeAfNamespaceLister) Get(name string) (*v1.AcceleratorFunction, error) {
|
func (nl *fakeAfNamespaceLister) Get(name string) (*v1.AcceleratorFunction, error) {
|
||||||
return nl.af, nl.err
|
return nl.af, nl.err
|
||||||
}
|
}
|
||||||
|
@ -24,7 +24,6 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/golang/glog"
|
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
|
|
||||||
"k8s.io/api/admission/v1beta1"
|
"k8s.io/api/admission/v1beta1"
|
||||||
@ -36,6 +35,8 @@ import (
|
|||||||
"k8s.io/apimachinery/pkg/types"
|
"k8s.io/apimachinery/pkg/types"
|
||||||
"k8s.io/client-go/rest"
|
"k8s.io/client-go/rest"
|
||||||
"k8s.io/client-go/tools/clientcmd"
|
"k8s.io/client-go/tools/clientcmd"
|
||||||
|
|
||||||
|
"github.com/intel/intel-device-plugins-for-kubernetes/pkg/debug"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@ -71,11 +72,11 @@ func getTLSConfig(certFile string, keyFile string) *tls.Config {
|
|||||||
func mutatePods(ar v1beta1.AdmissionReview, p *patcher) *v1beta1.AdmissionResponse {
|
func mutatePods(ar v1beta1.AdmissionReview, p *patcher) *v1beta1.AdmissionResponse {
|
||||||
var ops []string
|
var ops []string
|
||||||
|
|
||||||
glog.V(2).Info("mutating pods")
|
debug.Print("mutating pods")
|
||||||
|
|
||||||
podResource := metav1.GroupVersionResource{Group: "", Version: "v1", Resource: "pods"}
|
podResource := metav1.GroupVersionResource{Group: "", Version: "v1", Resource: "pods"}
|
||||||
if ar.Request.Resource != podResource {
|
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
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -128,7 +129,7 @@ func serve(w http.ResponseWriter, r *http.Request, admit admitFunc) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if len(body) == 0 {
|
if len(body) == 0 {
|
||||||
glog.Error("No body in request")
|
debug.Print("No body in request")
|
||||||
w.WriteHeader(http.StatusBadRequest)
|
w.WriteHeader(http.StatusBadRequest)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -136,16 +137,16 @@ func serve(w http.ResponseWriter, r *http.Request, admit admitFunc) {
|
|||||||
// verify the content type is accurate
|
// verify the content type is accurate
|
||||||
contentType := r.Header.Get("Content-Type")
|
contentType := r.Header.Get("Content-Type")
|
||||||
if contentType != "application/json" {
|
if contentType != "application/json" {
|
||||||
glog.Errorf("contentType=%s, expect application/json", contentType)
|
debug.Printf("contentType=%s, expect application/json", contentType)
|
||||||
w.WriteHeader(http.StatusBadRequest)
|
w.WriteHeader(http.StatusBadRequest)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
glog.V(2).Info(fmt.Sprintf("handling request: %s", string(body)))
|
debug.Printf("handling request: %s", string(body))
|
||||||
ar := v1beta1.AdmissionReview{}
|
ar := v1beta1.AdmissionReview{}
|
||||||
deserializer := codecs.UniversalDeserializer()
|
deserializer := codecs.UniversalDeserializer()
|
||||||
if _, _, err := deserializer.Decode(body, nil, &ar); err != nil {
|
if _, _, err := deserializer.Decode(body, nil, &ar); err != nil {
|
||||||
glog.Error(err)
|
fmt.Printf("ERROR: %+v\n", err)
|
||||||
reviewResponse = toAdmissionResponse(err)
|
reviewResponse = toAdmissionResponse(err)
|
||||||
} else {
|
} else {
|
||||||
if ar.Request == nil {
|
if ar.Request == nil {
|
||||||
@ -156,7 +157,7 @@ func serve(w http.ResponseWriter, r *http.Request, admit admitFunc) {
|
|||||||
reviewResponse = admit(ar)
|
reviewResponse = admit(ar)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
glog.V(2).Info(fmt.Sprintf("sending response: %v", reviewResponse))
|
debug.Print("sending response", reviewResponse)
|
||||||
|
|
||||||
response := v1beta1.AdmissionReview{}
|
response := v1beta1.AdmissionReview{}
|
||||||
if reviewResponse != nil {
|
if reviewResponse != nil {
|
||||||
@ -172,11 +173,11 @@ func serve(w http.ResponseWriter, r *http.Request, admit admitFunc) {
|
|||||||
|
|
||||||
resp, err := json.Marshal(response)
|
resp, err := json.Marshal(response)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
glog.Error(err)
|
fmt.Println("ERROR:", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if _, err := w.Write(resp); err != nil {
|
if _, err := w.Write(resp); err != nil {
|
||||||
glog.Error(err)
|
fmt.Println("ERROR:", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -201,6 +202,7 @@ func main() {
|
|||||||
var mode string
|
var mode string
|
||||||
var config *rest.Config
|
var config *rest.Config
|
||||||
var err error
|
var err error
|
||||||
|
var debugEnabled bool
|
||||||
|
|
||||||
flag.StringVar(&kubeconfig, "kubeconfig", "", "absolute path to the kubeconfig file")
|
flag.StringVar(&kubeconfig, "kubeconfig", "", "absolute path to the kubeconfig file")
|
||||||
flag.StringVar(&master, "master", "", "master url")
|
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).")
|
"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(&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.StringVar(&mode, "mode", preprogrammed, fmt.Sprintf("webhook mode: '%s' (default) or '%s'", preprogrammed, orchestrated))
|
||||||
|
flag.BoolVar(&debugEnabled, "debug", false, "enable debug output")
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
|
if debugEnabled {
|
||||||
|
debug.Activate()
|
||||||
|
}
|
||||||
|
|
||||||
if certFile == "" {
|
if certFile == "" {
|
||||||
glog.Error("TLS certificate file is not set")
|
fmt.Println("TLS certificate file is not set")
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
if keyFile == "" {
|
if keyFile == "" {
|
||||||
glog.Error("TLS private key is not set")
|
fmt.Println("TLS private key is not set")
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, err = os.Stat(certFile); err != nil {
|
if _, err = os.Stat(certFile); err != nil {
|
||||||
glog.Error("TLS certificate not found")
|
fmt.Println("TLS certificate not found")
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, err = os.Stat(keyFile); err != nil {
|
if _, err = os.Stat(keyFile); err != nil {
|
||||||
glog.Error("TLS private key not found")
|
fmt.Println("TLS private key not found")
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -236,7 +243,7 @@ func main() {
|
|||||||
config, err = clientcmd.BuildConfigFromFlags(master, kubeconfig)
|
config, err = clientcmd.BuildConfigFromFlags(master, kubeconfig)
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
glog.Error("Failed to get cluster config ", err)
|
fmt.Println("Failed to get cluster config ", err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -253,7 +260,7 @@ func main() {
|
|||||||
|
|
||||||
http.HandleFunc("/pods", makePodsHandler(patcher))
|
http.HandleFunc("/pods", makePodsHandler(patcher))
|
||||||
|
|
||||||
glog.V(2).Info("Webhook started")
|
debug.Print("Webhook started")
|
||||||
|
|
||||||
server := &http.Server{
|
server := &http.Server{
|
||||||
Addr: ":443",
|
Addr: ":443",
|
||||||
|
@ -28,8 +28,14 @@ import (
|
|||||||
"k8s.io/apimachinery/pkg/api/resource"
|
"k8s.io/apimachinery/pkg/api/resource"
|
||||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
"k8s.io/apimachinery/pkg/runtime"
|
"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 {
|
func fakeMutatePods(ar v1beta1.AdmissionReview) *v1beta1.AdmissionResponse {
|
||||||
reviewResponse := v1beta1.AdmissionResponse{}
|
reviewResponse := v1beta1.AdmissionResponse{}
|
||||||
return &reviewResponse
|
return &reviewResponse
|
||||||
|
@ -22,8 +22,13 @@ import (
|
|||||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
|
|
||||||
fpgav1 "github.com/intel/intel-device-plugins-for-kubernetes/pkg/apis/fpga.intel.com/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) {
|
func TestPatcherStorageFunctions(t *testing.T) {
|
||||||
af := &fpgav1.AcceleratorFunction{
|
af := &fpgav1.AcceleratorFunction{
|
||||||
ObjectMeta: metav1.ObjectMeta{
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
|
@ -22,8 +22,14 @@ import (
|
|||||||
|
|
||||||
"k8s.io/utils/exec"
|
"k8s.io/utils/exec"
|
||||||
fakeexec "k8s.io/utils/exec/testing"
|
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) {
|
func TestGetFPGAParams(t *testing.T) {
|
||||||
tcases := []struct {
|
tcases := []struct {
|
||||||
stdinJSON string
|
stdinJSON string
|
||||||
|
@ -24,7 +24,6 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/golang/glog"
|
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
|
|
||||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
@ -35,6 +34,7 @@ import (
|
|||||||
utilnode "k8s.io/kubernetes/pkg/util/node"
|
utilnode "k8s.io/kubernetes/pkg/util/node"
|
||||||
|
|
||||||
dpapi "github.com/intel/intel-device-plugins-for-kubernetes/internal/deviceplugin"
|
dpapi "github.com/intel/intel-device-plugins-for-kubernetes/internal/deviceplugin"
|
||||||
|
"github.com/intel/intel-device-plugins-for-kubernetes/pkg/debug"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@ -237,7 +237,7 @@ func (dp *devicePlugin) getDevNode(devName string) (string, error) {
|
|||||||
func (dp *devicePlugin) scanFPGAs() (dpapi.DeviceTree, error) {
|
func (dp *devicePlugin) scanFPGAs() (dpapi.DeviceTree, error) {
|
||||||
var devices []device
|
var devices []device
|
||||||
|
|
||||||
glog.V(2).Info("Start new FPGA scan")
|
debug.Print("Start new FPGA scan")
|
||||||
|
|
||||||
fpgaFiles, err := ioutil.ReadDir(dp.sysfsDir)
|
fpgaFiles, err := ioutil.ReadDir(dp.sysfsDir)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -340,13 +340,19 @@ func main() {
|
|||||||
var master string
|
var master string
|
||||||
var config *rest.Config
|
var config *rest.Config
|
||||||
var err error
|
var err error
|
||||||
|
var debugEnabled bool
|
||||||
|
|
||||||
flag.StringVar(&kubeconfig, "kubeconfig", "", "absolute path to the kubeconfig file")
|
flag.StringVar(&kubeconfig, "kubeconfig", "", "absolute path to the kubeconfig file")
|
||||||
flag.StringVar(&master, "master", "", "master url")
|
flag.StringVar(&master, "master", "", "master url")
|
||||||
flag.StringVar(&mode, "mode", string(afMode),
|
flag.StringVar(&mode, "mode", string(afMode),
|
||||||
fmt.Sprintf("device plugin mode: '%s' (default), '%s' or '%s'", afMode, regionMode, regionDevelMode))
|
fmt.Sprintf("device plugin mode: '%s' (default), '%s' or '%s'", afMode, regionMode, regionDevelMode))
|
||||||
|
flag.BoolVar(&debugEnabled, "debug", false, "enable debug output")
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
|
if debugEnabled {
|
||||||
|
debug.Activate()
|
||||||
|
}
|
||||||
|
|
||||||
if kubeconfig == "" {
|
if kubeconfig == "" {
|
||||||
config, err = rest.InClusterConfig()
|
config, err = rest.InClusterConfig()
|
||||||
} else {
|
} else {
|
||||||
@ -370,7 +376,7 @@ func main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if nodeMode, ok := node.ObjectMeta.Annotations["fpga.intel.com/device-plugin-mode"]; ok {
|
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
|
mode = nodeMode
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -379,7 +385,7 @@ func main() {
|
|||||||
fatal(err)
|
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 := dpapi.NewManager(namespace, plugin)
|
||||||
manager.Run()
|
manager.Run()
|
||||||
|
@ -29,8 +29,13 @@ import (
|
|||||||
pluginapi "k8s.io/kubernetes/pkg/kubelet/apis/deviceplugin/v1beta1"
|
pluginapi "k8s.io/kubernetes/pkg/kubelet/apis/deviceplugin/v1beta1"
|
||||||
|
|
||||||
dpapi "github.com/intel/intel-device-plugins-for-kubernetes/internal/deviceplugin"
|
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 {
|
func createTestDirs(devfs, sysfs string, devfsDirs, sysfsDirs []string, sysfsFiles map[string][]byte) error {
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
|
@ -24,12 +24,12 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/golang/glog"
|
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
|
|
||||||
pluginapi "k8s.io/kubernetes/pkg/kubelet/apis/deviceplugin/v1beta1"
|
pluginapi "k8s.io/kubernetes/pkg/kubelet/apis/deviceplugin/v1beta1"
|
||||||
|
|
||||||
dpapi "github.com/intel/intel-device-plugins-for-kubernetes/internal/deviceplugin"
|
dpapi "github.com/intel/intel-device-plugins-for-kubernetes/internal/deviceplugin"
|
||||||
|
"github.com/intel/intel-device-plugins-for-kubernetes/pkg/debug"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@ -88,7 +88,7 @@ func (dp *devicePlugin) scan() (dpapi.DeviceTree, error) {
|
|||||||
if dp.gpuDeviceReg.MatchString(f.Name()) {
|
if dp.gpuDeviceReg.MatchString(f.Name()) {
|
||||||
dat, err := ioutil.ReadFile(path.Join(dp.sysfsDir, f.Name(), "device/vendor"))
|
dat, err := ioutil.ReadFile(path.Join(dp.sysfsDir, f.Name(), "device/vendor"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
glog.Warning("Skipping. Can't read vendor file: ", err)
|
fmt.Println("WARNING: Skipping. Can't read vendor file: ", err)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -110,7 +110,7 @@ func (dp *devicePlugin) scan() (dpapi.DeviceTree, error) {
|
|||||||
continue
|
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)
|
nodes = append(nodes, devPath)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -134,16 +134,22 @@ func (dp *devicePlugin) scan() (dpapi.DeviceTree, error) {
|
|||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
var sharedDevNum int
|
var sharedDevNum int
|
||||||
|
var debugEnabled bool
|
||||||
|
|
||||||
flag.IntVar(&sharedDevNum, "shared-dev-num", 1, "number of containers sharing the same GPU device")
|
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()
|
flag.Parse()
|
||||||
|
|
||||||
|
if debugEnabled {
|
||||||
|
debug.Activate()
|
||||||
|
}
|
||||||
|
|
||||||
if sharedDevNum < 1 {
|
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)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
glog.Info("GPU device plugin started")
|
fmt.Println("GPU device plugin started")
|
||||||
|
|
||||||
plugin := newDevicePlugin(sysfsDrmDirectory, devfsDriDirectory, sharedDevNum)
|
plugin := newDevicePlugin(sysfsDrmDirectory, devfsDriDirectory, sharedDevNum)
|
||||||
manager := dpapi.NewManager(namespace, plugin)
|
manager := dpapi.NewManager(namespace, plugin)
|
||||||
|
@ -21,8 +21,14 @@ import (
|
|||||||
"path"
|
"path"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/intel/intel-device-plugins-for-kubernetes/pkg/debug"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
debug.Activate()
|
||||||
|
}
|
||||||
|
|
||||||
func TestScan(t *testing.T) {
|
func TestScan(t *testing.T) {
|
||||||
tmpdir := fmt.Sprintf("/tmp/gpuplugin-test-%d", time.Now().Unix())
|
tmpdir := fmt.Sprintf("/tmp/gpuplugin-test-%d", time.Now().Unix())
|
||||||
sysfs := path.Join(tmpdir, "sysfs")
|
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:
|
### Deploy QAT device plugin directly on the host:
|
||||||
```
|
```
|
||||||
$ sudo $GOPATH/src/github.com/intel/intel-device-plugins-for-kubernetes/cmd/qat_plugin/qat_plugin \
|
$ 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
|
QAT device plugin started
|
||||||
Discovered Devices below:
|
Discovered Devices below:
|
||||||
03:01.0 device: corresponding DPDK device detected is uio0
|
03:01.0 device: corresponding DPDK device detected is uio0
|
||||||
|
@ -25,12 +25,12 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/golang/glog"
|
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
|
|
||||||
pluginapi "k8s.io/kubernetes/pkg/kubelet/apis/deviceplugin/v1beta1"
|
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/internal/deviceplugin"
|
||||||
|
"github.com/intel/intel-device-plugins-for-kubernetes/pkg/debug"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@ -263,9 +263,14 @@ func main() {
|
|||||||
dpdkDriver := flag.String("dpdk-driver", "igb_uio", "DPDK Device driver for configuring the QAT device")
|
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")
|
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")
|
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()
|
flag.Parse()
|
||||||
fmt.Println("QAT device plugin started")
|
fmt.Println("QAT device plugin started")
|
||||||
|
|
||||||
|
if *debugEnabled {
|
||||||
|
debug.Activate()
|
||||||
|
}
|
||||||
|
|
||||||
if !isValidDpdkDeviceDriver(*dpdkDriver) {
|
if !isValidDpdkDeviceDriver(*dpdkDriver) {
|
||||||
fmt.Println("Wrong DPDK device driver:", *dpdkDriver)
|
fmt.Println("Wrong DPDK device driver:", *dpdkDriver)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
|
@ -23,8 +23,14 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/pkg/errors"
|
"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 {
|
func createTestFiles(prefix string, dirs []string, files map[string][]byte) error {
|
||||||
for _, dir := range dirs {
|
for _, dir := range dirs {
|
||||||
err := os.MkdirAll(path.Join(prefix, dir), 0755)
|
err := os.MkdirAll(path.Join(prefix, dir), 0755)
|
||||||
|
@ -21,9 +21,7 @@ spec:
|
|||||||
- -tls-cert-file=/etc/webhook/certs/cert.pem
|
- -tls-cert-file=/etc/webhook/certs/cert.pem
|
||||||
- -tls-private-key-file=/etc/webhook/certs/key.pem
|
- -tls-private-key-file=/etc/webhook/certs/key.pem
|
||||||
- -mode={MODE}
|
- -mode={MODE}
|
||||||
- -alsologtostderr
|
- -debug
|
||||||
- -v=2
|
|
||||||
- 2>&1
|
|
||||||
volumeMounts:
|
volumeMounts:
|
||||||
- name: webhook-certs
|
- name: webhook-certs
|
||||||
mountPath: /etc/webhook/certs
|
mountPath: /etc/webhook/certs
|
||||||
|
@ -19,9 +19,9 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"reflect"
|
"reflect"
|
||||||
|
|
||||||
"github.com/golang/glog"
|
|
||||||
|
|
||||||
pluginapi "k8s.io/kubernetes/pkg/kubelet/apis/deviceplugin/v1beta1"
|
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.
|
// updateInfo contains info for added, updated and deleted devices.
|
||||||
@ -107,7 +107,7 @@ func (m *Manager) Run() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (m *Manager) handleUpdate(update updateInfo) {
|
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 {
|
for devType, devices := range update.Added {
|
||||||
var postAllocate func(*pluginapi.AllocateResponse) error
|
var postAllocate func(*pluginapi.AllocateResponse) error
|
||||||
|
|
||||||
|
@ -18,8 +18,14 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
pluginapi "k8s.io/kubernetes/pkg/kubelet/apis/deviceplugin/v1beta1"
|
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) {
|
func TestNotify(t *testing.T) {
|
||||||
tcases := []struct {
|
tcases := []struct {
|
||||||
name string
|
name string
|
||||||
|
@ -24,11 +24,12 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/fsnotify/fsnotify"
|
"github.com/fsnotify/fsnotify"
|
||||||
"github.com/golang/glog"
|
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"google.golang.org/grpc"
|
"google.golang.org/grpc"
|
||||||
|
|
||||||
pluginapi "k8s.io/kubernetes/pkg/kubelet/apis/deviceplugin/v1beta1"
|
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
|
// devicePluginServer maintains a gRPC server satisfying
|
||||||
@ -69,7 +70,7 @@ func (srv *server) sendDevices(stream pluginapi.DevicePlugin_ListAndWatchServer)
|
|||||||
for id, device := range srv.devices {
|
for id, device := range srv.devices {
|
||||||
resp.Devices = append(resp.Devices, &pluginapi.Device{id, device.State})
|
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 {
|
if err := stream.Send(resp); err != nil {
|
||||||
srv.Stop()
|
srv.Stop()
|
||||||
return errors.Wrapf(err, "Cannot update device list")
|
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 {
|
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 {
|
if err := srv.sendDevices(stream); err != nil {
|
||||||
return err
|
return err
|
||||||
@ -187,7 +188,7 @@ func (srv *server) setupAndServe(namespace string, devicePluginPath string, kube
|
|||||||
|
|
||||||
// Starts device plugin service.
|
// Starts device plugin service.
|
||||||
go func() {
|
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)
|
srv.grpcServer.Serve(lis)
|
||||||
}()
|
}()
|
||||||
|
|
||||||
@ -201,16 +202,14 @@ func (srv *server) setupAndServe(namespace string, devicePluginPath string, kube
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
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
|
// Kubelet removes plugin socket when it (re)starts
|
||||||
// plugin must restart in this case
|
// plugin must restart in this case
|
||||||
if err = watchFile(pluginSocket); err != nil {
|
if err = watchFile(pluginSocket); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
fmt.Printf("socket %s removed, restarting", pluginSocket)
|
fmt.Printf("Socket %s removed, restarting\n", pluginSocket)
|
||||||
|
|
||||||
fmt.Println("stop GRPC server")
|
|
||||||
|
|
||||||
srv.grpcServer.Stop()
|
srv.grpcServer.Stop()
|
||||||
os.Remove(pluginSocket)
|
os.Remove(pluginSocket)
|
||||||
|
@ -29,6 +29,7 @@ import (
|
|||||||
|
|
||||||
pluginapi "k8s.io/kubernetes/pkg/kubelet/apis/deviceplugin/v1beta1"
|
pluginapi "k8s.io/kubernetes/pkg/kubelet/apis/deviceplugin/v1beta1"
|
||||||
|
|
||||||
|
"github.com/intel/intel-device-plugins-for-kubernetes/pkg/debug"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -47,6 +48,10 @@ type kubeletStub struct {
|
|||||||
server *grpc.Server
|
server *grpc.Server
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
debug.Activate()
|
||||||
|
}
|
||||||
|
|
||||||
// newKubeletStub returns an initialized kubeletStub for testing purpose.
|
// newKubeletStub returns an initialized kubeletStub for testing purpose.
|
||||||
func newKubeletStub(socket string) *kubeletStub {
|
func newKubeletStub(socket string) *kubeletStub {
|
||||||
return &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