diff --git a/Gopkg.lock b/Gopkg.lock index d7b300688..0ef615457 100644 --- a/Gopkg.lock +++ b/Gopkg.lock @@ -2,34 +2,35 @@ [[projects]] + digest = "1:94ffc0947c337d618b6ff5ed9abaddc1217b090c1b3a1ae4739b35b7b25851d5" name = "github.com/container-storage-interface/spec" packages = ["lib/go/csi"] + pruneopts = "NUT" revision = "ed0bb0e1557548aa028307f48728767cfe8f6345" version = "v1.0.0" [[projects]] + digest = "1:2e15dd2dcea234f9f10e96041a3862830d10feadf8fd9c3795ca71fcb4cf2a3d" name = "github.com/gogo/protobuf" packages = [ "gogoproto", "proto", - "protoc-gen-gogo/descriptor" + "protoc-gen-gogo/descriptor", ] + pruneopts = "NUT" revision = "1adfc126b41513cc696b209667c8656ea7aac67c" version = "v1.0.0" [[projects]] - branch = "master" - name = "github.com/golang/glog" - packages = ["."] - revision = "23def4e6c14b4da8ac2ed8007337bc5eb5007998" - -[[projects]] + digest = "1:bc38c7c481812e178d85160472e231c5e1c9a7f5845d67e23ee4e706933c10d8" name = "github.com/golang/mock" packages = ["gomock"] + pruneopts = "NUT" revision = "c34cdb4725f4c3844d095133c6e40e448b86589b" version = "v1.1.1" [[projects]] + digest = "1:3b583d3cd8cec5a31ca9f928ddedd17770987daafa8f326b678c54e8e9798430" name = "github.com/golang/protobuf" packages = [ "descriptor", @@ -39,28 +40,34 @@ "ptypes/any", "ptypes/duration", "ptypes/timestamp", - "ptypes/wrappers" + "ptypes/wrappers", ] + pruneopts = "NUT" revision = "b4deda0973fb4c70b50d226b1af49f3da59f5265" version = "v1.1.0" [[projects]] + digest = "1:610f50d23ee3e0fa37d77fc23bf2c3b6897d2dc1c934739f13cdf551e9fc57d9" name = "github.com/kubernetes-csi/csi-lib-utils" packages = ["protosanitizer"] + pruneopts = "NUT" revision = "1628ab5351eafa4fc89a96862a08a891e601e03a" version = "v0.1.0" [[projects]] + digest = "1:cab5d1fe86e273b35887f707dbec779d77d87613d9f2f14ea23002912197ce81" name = "github.com/kubernetes-csi/csi-test" packages = [ "driver", - "utils" + "utils", ] + pruneopts = "NUT" revision = "42947e04c4a0d2087448841a1dc3ccb20fb903b1" version = "v1.0.0-rc2" [[projects]] branch = "master" + digest = "1:0744fec18e9083ec13cb19d8df60841b66a5caa0226171dc83d113969daa2968" name = "golang.org/x/net" packages = [ "context", @@ -69,17 +76,21 @@ "idna", "internal/timeseries", "lex/httplex", - "trace" + "trace", ] + pruneopts = "NUT" revision = "22ae77b79946ea320088417e4d50825671d82d57" [[projects]] branch = "master" + digest = "1:22f84ef46c650297fb870cb2497667a7129af9819675790f5914aae538004e7e" name = "golang.org/x/sys" packages = ["unix"] + pruneopts = "NUT" revision = "dd2ff4accc098aceecb86b36eaa7829b2a17b1c9" [[projects]] + digest = "1:e7071ed636b5422cc51c0e3a6cebc229d6c9fffc528814b519a980641422d619" name = "golang.org/x/text" packages = [ "collate", @@ -95,18 +106,22 @@ "unicode/bidi", "unicode/cldr", "unicode/norm", - "unicode/rangetable" + "unicode/rangetable", ] + pruneopts = "NUT" revision = "f21a4dfb5e38f5895301dc265a8def02365cc3d0" version = "v0.3.0" [[projects]] branch = "master" + digest = "1:cd018653a358d4b743a9d3bee89e825521f2ab2f2ec0770164bf7632d8d73ab7" name = "google.golang.org/genproto" packages = ["googleapis/rpc/status"] + pruneopts = "NUT" revision = "2c5e7ac708aaa719366570dd82bda44541ca2a63" [[projects]] + digest = "1:d6978aa19fad4f8b3485d7a56e847542dc821d8dd2845bf2d2f8fdccf2d5e655" name = "google.golang.org/grpc" packages = [ ".", @@ -133,20 +148,43 @@ "stats", "status", "tap", - "transport" + "transport", ] + pruneopts = "NUT" revision = "8e4536a86ab602859c20df5ebfd0bd4228d08655" version = "v1.10.0" [[projects]] + digest = "1:9cc257b3c9ff6a0158c9c661ab6eebda1fe8a4a4453cd5c4044dc9a2ebfb992b" + name = "k8s.io/klog" + packages = ["."] + pruneopts = "NUT" + revision = "a5bc97fbc634d635061f3146511332c7e313a55a" + version = "v0.1.0" + +[[projects]] + digest = "1:6168eefeaccb4d9a6061ebe8ce658f1163e6f12f96e3289a493f9aa8a7848d95" name = "k8s.io/kubernetes" packages = ["pkg/kubelet/apis/pluginregistration/v1alpha1"] + pruneopts = "NUT" revision = "be2cfcf9e44b5162a294e977329d6c8194748c4e" version = "v1.11.0-beta.2" [solve-meta] analyzer-name = "dep" analyzer-version = 1 - inputs-digest = "907a75d1f9d8ee5884fd9f5bd03797435076f9f2683c08188b06f81a2cb07cff" + input-imports = [ + "github.com/container-storage-interface/spec/lib/go/csi", + "github.com/golang/mock/gomock", + "github.com/kubernetes-csi/csi-lib-utils/protosanitizer", + "github.com/kubernetes-csi/csi-test/driver", + "golang.org/x/sys/unix", + "google.golang.org/grpc", + "google.golang.org/grpc/codes", + "google.golang.org/grpc/connectivity", + "google.golang.org/grpc/status", + "k8s.io/klog", + "k8s.io/kubernetes/pkg/kubelet/apis/pluginregistration/v1alpha1", + ] solver-name = "gps-cdcl" solver-version = 1 diff --git a/Gopkg.toml b/Gopkg.toml index 993807a00..4ea67b5ac 100644 --- a/Gopkg.toml +++ b/Gopkg.toml @@ -31,9 +31,6 @@ name = "github.com/kubernetes-csi/csi-test" version = "v1.0.0-1" -[[constraint]] - branch = "master" - name = "github.com/golang/glog" [[override]] name = "github.com/json-iterator/go" diff --git a/cmd/csi-node-driver-registrar/main.go b/cmd/csi-node-driver-registrar/main.go index c3bce88ff..ca32c80f7 100644 --- a/cmd/csi-node-driver-registrar/main.go +++ b/cmd/csi-node-driver-registrar/main.go @@ -23,7 +23,7 @@ import ( "os" "time" - "github.com/golang/glog" + "k8s.io/klog" registerapi "k8s.io/kubernetes/pkg/kubelet/apis/pluginregistration/v1alpha1" "github.com/kubernetes-csi/node-driver-registrar/pkg/connection" @@ -73,7 +73,7 @@ func newRegistrationServer(driverName string, endpoint string, versions []string // GetInfo is the RPC invoked by plugin watcher func (e registrationServer) GetInfo(ctx context.Context, req *registerapi.InfoRequest) (*registerapi.PluginInfo, error) { - glog.Infof("Received GetInfo call: %+v", req) + klog.Infof("Received GetInfo call: %+v", req) return ®isterapi.PluginInfo{ Type: registerapi.CSIPlugin, Name: e.driverName, @@ -83,9 +83,9 @@ func (e registrationServer) GetInfo(ctx context.Context, req *registerapi.InfoRe } func (e registrationServer) NotifyRegistrationStatus(ctx context.Context, status *registerapi.RegistrationStatus) (*registerapi.RegistrationStatusResponse, error) { - glog.Infof("Received NotifyRegistrationStatus call: %+v", status) + klog.Infof("Received NotifyRegistrationStatus call: %+v", status) if !status.PluginRegistered { - glog.Errorf("Registration process failed with error: %+v, restarting registration container.", status.Error) + klog.Errorf("Registration process failed with error: %+v, restarting registration container.", status.Error) os.Exit(1) } @@ -93,11 +93,12 @@ func (e registrationServer) NotifyRegistrationStatus(ctx context.Context, status } func main() { + klog.InitFlags(nil) flag.Set("logtostderr", "true") flag.Parse() if *kubeletRegistrationPath == "" { - glog.Error("kubelet-registration-path is a required parameter") + klog.Error("kubelet-registration-path is a required parameter") os.Exit(1) } @@ -105,30 +106,30 @@ func main() { fmt.Println(os.Args[0], version) return } - glog.Infof("Version: %s", version) + klog.Infof("Version: %s", version) // Once https://github.com/container-storage-interface/spec/issues/159 is // resolved, if plugin does not support PUBLISH_UNPUBLISH_VOLUME, then we // can skip adding mapping to "csi.volume.kubernetes.io/nodeid" annotation. // Connect to CSI. - glog.V(1).Infof("Attempting to open a gRPC connection with: %q", *csiAddress) + klog.V(1).Infof("Attempting to open a gRPC connection with: %q", *csiAddress) csiConn, err := connection.NewConnection(*csiAddress, *connectionTimeout) if err != nil { - glog.Error(err.Error()) + klog.Error(err.Error()) os.Exit(1) } // Get CSI driver name. - glog.V(1).Infof("Calling CSI driver to discover driver name.") + klog.V(1).Infof("Calling CSI driver to discover driver name.") ctx, cancel := context.WithTimeout(context.Background(), csiTimeout) defer cancel() csiDriverName, err := csiConn.GetDriverName(ctx) if err != nil { - glog.Error(err.Error()) + klog.Error(err.Error()) os.Exit(1) } - glog.V(2).Infof("CSI driver name: %q", csiDriverName) + klog.V(2).Infof("CSI driver name: %q", csiDriverName) // Run forever nodeRegister(csiDriverName) diff --git a/cmd/csi-node-driver-registrar/node_register.go b/cmd/csi-node-driver-registrar/node_register.go index ac4c83f6e..0e96980b4 100644 --- a/cmd/csi-node-driver-registrar/node_register.go +++ b/cmd/csi-node-driver-registrar/node_register.go @@ -23,8 +23,8 @@ import ( "google.golang.org/grpc" - "github.com/golang/glog" "golang.org/x/sys/unix" + "k8s.io/klog" registerapi "k8s.io/kubernetes/pkg/kubelet/apis/pluginregistration/v1alpha1" ) @@ -40,32 +40,32 @@ func nodeRegister( if err == nil && (fi.Mode()&os.ModeSocket) != 0 { // Remove any socket, stale or not, but fall through for other files if err := os.Remove(socketPath); err != nil { - glog.Errorf("failed to remove stale socket %s with error: %+v", socketPath, err) + klog.Errorf("failed to remove stale socket %s with error: %+v", socketPath, err) os.Exit(1) } } if err != nil && !os.IsNotExist(err) { - glog.Errorf("failed to stat the socket %s with error: %+v", socketPath, err) + klog.Errorf("failed to stat the socket %s with error: %+v", socketPath, err) os.Exit(1) } // Default to only user accessible socket, caller can open up later if desired oldmask := unix.Umask(0077) - glog.Infof("Starting Registration Server at: %s\n", socketPath) + klog.Infof("Starting Registration Server at: %s\n", socketPath) lis, err := net.Listen("unix", socketPath) if err != nil { - glog.Errorf("failed to listen on socket: %s with error: %+v", socketPath, err) + klog.Errorf("failed to listen on socket: %s with error: %+v", socketPath, err) os.Exit(1) } unix.Umask(oldmask) - glog.Infof("Registration Server started at: %s\n", socketPath) + klog.Infof("Registration Server started at: %s\n", socketPath) grpcServer := grpc.NewServer() // Registers kubelet plugin watcher api. registerapi.RegisterRegistrationServer(grpcServer, registrar) // Starts service if err := grpcServer.Serve(lis); err != nil { - glog.Errorf("Registration Server stopped serving: %v", err) + klog.Errorf("Registration Server stopped serving: %v", err) os.Exit(1) } // If gRPC server is gracefully shutdown, exit diff --git a/pkg/connection/connection.go b/pkg/connection/connection.go index be6ea2e49..8a46e77a6 100644 --- a/pkg/connection/connection.go +++ b/pkg/connection/connection.go @@ -24,12 +24,12 @@ import ( "time" "github.com/container-storage-interface/spec/lib/go/csi" - "github.com/golang/glog" "github.com/kubernetes-csi/csi-lib-utils/protosanitizer" "google.golang.org/grpc" "google.golang.org/grpc/codes" "google.golang.org/grpc/connectivity" "google.golang.org/grpc/status" + "k8s.io/klog" ) // CSIConnection is gRPC connection to a remote CSI driver and abstracts all @@ -67,7 +67,7 @@ func NewConnection( } func connect(address string, timeout time.Duration) (*grpc.ClientConn, error) { - glog.V(2).Infof("Connecting to %s", address) + klog.V(2).Infof("Connecting to %s", address) dialOptions := []grpc.DialOption{ grpc.WithInsecure(), grpc.WithBackoffMaxDelay(time.Second), @@ -87,14 +87,14 @@ func connect(address string, timeout time.Duration) (*grpc.ClientConn, error) { defer cancel() for { if !conn.WaitForStateChange(ctx, conn.GetState()) { - glog.V(4).Infof("Connection timed out") + klog.V(4).Infof("Connection timed out") return conn, nil // return nil, subsequent GetPluginInfo will show the real connection error } if conn.GetState() == connectivity.Ready { - glog.V(3).Infof("Connected") + klog.V(3).Infof("Connected") return conn, nil } - glog.V(4).Infof("Still trying, connection is %s", conn.GetState()) + klog.V(4).Infof("Still trying, connection is %s", conn.GetState()) } } @@ -135,11 +135,11 @@ func (c *csiConnection) Close() error { } func logGRPC(ctx context.Context, method string, req, reply interface{}, cc *grpc.ClientConn, invoker grpc.UnaryInvoker, opts ...grpc.CallOption) error { - glog.V(5).Infof("GRPC call: %s", method) - glog.V(5).Infof("GRPC request: %s", protosanitizer.StripSecrets(req)) + klog.V(5).Infof("GRPC call: %s", method) + klog.V(5).Infof("GRPC request: %s", protosanitizer.StripSecrets(req)) err := invoker(ctx, method, req, reply, cc, opts...) - glog.V(5).Infof("GRPC response: %s", protosanitizer.StripSecrets(reply)) - glog.V(5).Infof("GRPC error: %v", err) + klog.V(5).Infof("GRPC response: %s", protosanitizer.StripSecrets(reply)) + klog.V(5).Infof("GRPC error: %v", err) return err } diff --git a/vendor/github.com/golang/glog/LICENSE b/vendor/k8s.io/klog/LICENSE similarity index 100% rename from vendor/github.com/golang/glog/LICENSE rename to vendor/k8s.io/klog/LICENSE diff --git a/vendor/github.com/golang/glog/glog.go b/vendor/k8s.io/klog/klog.go similarity index 93% rename from vendor/github.com/golang/glog/glog.go rename to vendor/k8s.io/klog/klog.go index 54bd7afdc..13bcc81a7 100644 --- a/vendor/github.com/golang/glog/glog.go +++ b/vendor/k8s.io/klog/klog.go @@ -14,7 +14,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -// Package glog implements logging analogous to the Google-internal C++ INFO/ERROR/V setup. +// Package klog implements logging analogous to the Google-internal C++ INFO/ERROR/V setup. // It provides functions Info, Warning, Error, Fatal, plus formatting variants such as // Infof. It also provides V-style logging controlled by the -v and -vmodule=file=2 flags. // @@ -68,7 +68,7 @@ // -vmodule=gopher*=3 // sets the V level to 3 in all Go files whose names begin "gopher". // -package glog +package klog import ( "bufio" @@ -396,13 +396,6 @@ type flushSyncWriter interface { } func init() { - flag.BoolVar(&logging.toStderr, "logtostderr", false, "log to standard error instead of files") - flag.BoolVar(&logging.alsoToStderr, "alsologtostderr", false, "log to standard error as well as files") - flag.Var(&logging.verbosity, "v", "log level for V logs") - flag.Var(&logging.stderrThreshold, "stderrthreshold", "logs at or above this threshold go to stderr") - flag.Var(&logging.vmodule, "vmodule", "comma-separated list of pattern=N settings for file-filtered logging") - flag.Var(&logging.traceLocation, "log_backtrace_at", "when logging hits line file:N, emit a stack trace") - // Default stderrThreshold is ERROR. logging.stderrThreshold = errorLog @@ -410,6 +403,22 @@ func init() { go logging.flushDaemon() } +// InitFlags is for explicitly initializing the flags +func InitFlags(flagset *flag.FlagSet) { + if flagset == nil { + flagset = flag.CommandLine + } + flagset.StringVar(&logging.logDir, "log_dir", "", "If non-empty, write log files in this directory") + flagset.StringVar(&logging.logFile, "log_file", "", "If non-empty, use this log file") + flagset.BoolVar(&logging.toStderr, "logtostderr", false, "log to standard error instead of files") + flagset.BoolVar(&logging.alsoToStderr, "alsologtostderr", false, "log to standard error as well as files") + flagset.Var(&logging.verbosity, "v", "log level for V logs") + flagset.BoolVar(&logging.skipHeaders, "skip_headers", false, "If true, avoid header prefixes in the log messages") + flagset.Var(&logging.stderrThreshold, "stderrthreshold", "logs at or above this threshold go to stderr") + flagset.Var(&logging.vmodule, "vmodule", "comma-separated list of pattern=N settings for file-filtered logging") + flagset.Var(&logging.traceLocation, "log_backtrace_at", "when logging hits line file:N, emit a stack trace") +} + // Flush flushes all pending log I/O. func Flush() { logging.lockAndFlushAll() @@ -453,6 +462,17 @@ type loggingT struct { // safely using atomic.LoadInt32. vmodule moduleSpec // The state of the -vmodule flag. verbosity Level // V logging level, the value of the -v flag/ + + // If non-empty, overrides the choice of directory in which to write logs. + // See createLogDirs for the full list of possible destinations. + logDir string + + // If non-empty, specifies the path of the file to write logs. mutually exclusive + // with the log-dir option. + logFile string + + // If true, do not add the prefix headers, useful when used with SetOutput + skipHeaders bool } // buffer holds a byte Buffer for reuse. The zero value is ready for use. @@ -556,6 +576,9 @@ func (l *loggingT) formatHeader(s severity, file string, line int) *buffer { s = infoLog // for safety. } buf := l.getBuffer() + if l.skipHeaders { + return buf + } // Avoid Fprintf, for speed. The format is so simple that we can do it quickly by hand. // It's worth about 3X. Fprintf is hard. @@ -667,6 +690,45 @@ func (l *loggingT) printWithFileLine(s severity, file string, line int, alsoToSt l.output(s, buf, file, line, alsoToStderr) } +// redirectBuffer is used to set an alternate destination for the logs +type redirectBuffer struct { + w io.Writer +} + +func (rb *redirectBuffer) Sync() error { + return nil +} + +func (rb *redirectBuffer) Flush() error { + return nil +} + +func (rb *redirectBuffer) Write(bytes []byte) (n int, err error) { + return rb.w.Write(bytes) +} + +// SetOutput sets the output destination for all severities +func SetOutput(w io.Writer) { + for s := fatalLog; s >= infoLog; s-- { + rb := &redirectBuffer{ + w: w, + } + logging.file[s] = rb + } +} + +// SetOutputBySeverity sets the output destination for specific severity +func SetOutputBySeverity(name string, w io.Writer) { + sev, ok := severityByName(name) + if !ok { + panic(fmt.Sprintf("SetOutputBySeverity(%q): unrecognized severity name", name)) + } + rb := &redirectBuffer{ + w: w, + } + logging.file[sev] = rb +} + // output writes the data to the log files and releases the buffer. func (l *loggingT) output(s severity, buf *buffer, file string, line int, alsoToStderr bool) { l.mu.Lock() @@ -676,10 +738,7 @@ func (l *loggingT) output(s severity, buf *buffer, file string, line int, alsoTo } } data := buf.Bytes() - if !flag.Parsed() { - os.Stderr.Write([]byte("ERROR: logging before flag.Parse: ")) - os.Stderr.Write(data) - } else if l.toStderr { + if l.toStderr { os.Stderr.Write(data) } else { if alsoToStderr || l.alsoToStderr || s >= l.stderrThreshold.get() { @@ -879,7 +938,7 @@ const flushInterval = 30 * time.Second // flushDaemon periodically flushes the log file buffers. func (l *loggingT) flushDaemon() { - for _ = range time.NewTicker(flushInterval).C { + for range time.NewTicker(flushInterval).C { l.lockAndFlushAll() } } diff --git a/vendor/github.com/golang/glog/glog_file.go b/vendor/k8s.io/klog/klog_file.go similarity index 90% rename from vendor/github.com/golang/glog/glog_file.go rename to vendor/k8s.io/klog/klog_file.go index 65075d281..b76a4e10b 100644 --- a/vendor/github.com/golang/glog/glog_file.go +++ b/vendor/k8s.io/klog/klog_file.go @@ -16,11 +16,10 @@ // File I/O for logs. -package glog +package klog import ( "errors" - "flag" "fmt" "os" "os/user" @@ -36,13 +35,9 @@ var MaxSize uint64 = 1024 * 1024 * 1800 // logDirs lists the candidate directories for new log files. var logDirs []string -// If non-empty, overrides the choice of directory in which to write logs. -// See createLogDirs for the full list of possible destinations. -var logDir = flag.String("log_dir", "", "If non-empty, write log files in this directory") - func createLogDirs() { - if *logDir != "" { - logDirs = append(logDirs, *logDir) + if logging.logDir != "" { + logDirs = append(logDirs, logging.logDir) } logDirs = append(logDirs, os.TempDir()) } @@ -103,6 +98,13 @@ var onceLogDirs sync.Once // successfully, create also attempts to update the symlink for that tag, ignoring // errors. func create(tag string, t time.Time) (f *os.File, filename string, err error) { + if logging.logFile != "" { + f, err := os.Create(logging.logFile) + if err == nil { + return f, logging.logFile, nil + } + return nil, "", fmt.Errorf("log: unable to create log: %v", err) + } onceLogDirs.Do(createLogDirs) if len(logDirs) == 0 { return nil, "", errors.New("log: no log dirs")