From 32c3b61090aeb6b4a85572de9a2cd420f064c9bd Mon Sep 17 00:00:00 2001 From: Vinayak Goyal Date: Thu, 19 Nov 2020 15:36:22 -0800 Subject: [PATCH] Update k8s.io/klog to k8s.io/klog/v2 for gke-exec-auth-plugin --- cmd/cloud-controller-manager/app/BUILD | 1 - cmd/gke-exec-auth-plugin/BUILD | 1 + cmd/gke-exec-auth-plugin/cache.go | 2 +- cmd/gke-exec-auth-plugin/main.go | 2 +- cmd/gke-exec-auth-plugin/request.go | 2 +- cmd/gke-exec-auth-plugin/tpm.go | 2 +- go.mod | 1 + go.sum | 2 + vendor/k8s.io/klog/v2/README.md | 6 +- vendor/k8s.io/klog/v2/SECURITY.md | 22 +++ vendor/k8s.io/klog/v2/klog.go | 177 ++++++++++++------ vendor/k8s.io/kubernetes/pkg/util/flag/BUILD | 14 -- .../k8s.io/kubernetes/pkg/util/flag/flags.go | 153 --------------- vendor/modules.txt | 3 +- 14 files changed, 155 insertions(+), 233 deletions(-) create mode 100644 vendor/k8s.io/klog/v2/SECURITY.md delete mode 100644 vendor/k8s.io/kubernetes/pkg/util/flag/BUILD delete mode 100644 vendor/k8s.io/kubernetes/pkg/util/flag/flags.go diff --git a/cmd/cloud-controller-manager/app/BUILD b/cmd/cloud-controller-manager/app/BUILD index 707ae69743..3ecdb12e02 100644 --- a/cmd/cloud-controller-manager/app/BUILD +++ b/cmd/cloud-controller-manager/app/BUILD @@ -34,7 +34,6 @@ go_library( "//vendor/k8s.io/component-base/version/verflag:go_default_library", "//vendor/k8s.io/klog:go_default_library", "//vendor/k8s.io/kubernetes/pkg/features:go_default_library", - "//vendor/k8s.io/kubernetes/pkg/util/flag:go_default_library", "//vendor/k8s.io/utils/net:go_default_library", ], ) diff --git a/cmd/gke-exec-auth-plugin/BUILD b/cmd/gke-exec-auth-plugin/BUILD index 95bc93d411..7eeacb2a51 100644 --- a/cmd/gke-exec-auth-plugin/BUILD +++ b/cmd/gke-exec-auth-plugin/BUILD @@ -36,6 +36,7 @@ go_library( "//vendor/k8s.io/client-go/util/certificate/csr:go_default_library", "//vendor/k8s.io/client-go/util/keyutil:go_default_library", "//vendor/k8s.io/klog:go_default_library", + "//vendor/k8s.io/klog/v2:go_default_library", ], ) diff --git a/cmd/gke-exec-auth-plugin/cache.go b/cmd/gke-exec-auth-plugin/cache.go index ef1a2934a7..5ae946e507 100644 --- a/cmd/gke-exec-auth-plugin/cache.go +++ b/cmd/gke-exec-auth-plugin/cache.go @@ -14,7 +14,7 @@ import ( "time" "k8s.io/client-go/util/keyutil" - "k8s.io/klog" + "k8s.io/klog/v2" ) const ( diff --git a/cmd/gke-exec-auth-plugin/main.go b/cmd/gke-exec-auth-plugin/main.go index a4f973a959..a19dc63e7f 100644 --- a/cmd/gke-exec-auth-plugin/main.go +++ b/cmd/gke-exec-auth-plugin/main.go @@ -14,7 +14,7 @@ import ( "k8s.io/apimachinery/pkg/runtime/serializer" "k8s.io/client-go/pkg/apis/clientauthentication" clientauthv1alpha1 "k8s.io/client-go/pkg/apis/clientauthentication/v1alpha1" - "k8s.io/klog" + "k8s.io/klog/v2" ) const ( diff --git a/cmd/gke-exec-auth-plugin/request.go b/cmd/gke-exec-auth-plugin/request.go index 27a16549f6..8d3db782ba 100644 --- a/cmd/gke-exec-auth-plugin/request.go +++ b/cmd/gke-exec-auth-plugin/request.go @@ -19,7 +19,7 @@ import ( "k8s.io/client-go/util/cert" "k8s.io/client-go/util/certificate/csr" "k8s.io/client-go/util/keyutil" - "k8s.io/klog" + "k8s.io/klog/v2" ) const ( diff --git a/cmd/gke-exec-auth-plugin/tpm.go b/cmd/gke-exec-auth-plugin/tpm.go index 56429b6398..a1b26ccc86 100644 --- a/cmd/gke-exec-auth-plugin/tpm.go +++ b/cmd/gke-exec-auth-plugin/tpm.go @@ -18,7 +18,7 @@ import ( "k8s.io/cloud-provider-gcp/pkg/nodeidentity" "k8s.io/cloud-provider-gcp/pkg/tpmattest" - "k8s.io/klog" + "k8s.io/klog/v2" ) const ( diff --git a/go.mod b/go.mod index 358e1d8999..a52cbae00e 100644 --- a/go.mod +++ b/go.mod @@ -64,6 +64,7 @@ require ( k8s.io/cluster-bootstrap v0.19.0 // indirect k8s.io/cri-api v0.19.0 // indirect k8s.io/klog v1.0.0 + k8s.io/klog/v2 v2.4.0 k8s.io/kube-aggregator v0.19.0 // indirect k8s.io/kube-proxy v0.19.0 // indirect k8s.io/kube-scheduler v0.19.0 // indirect diff --git a/go.sum b/go.sum index a9be77f5a1..ec5f65260e 100644 --- a/go.sum +++ b/go.sum @@ -1139,6 +1139,8 @@ k8s.io/klog v1.0.0/go.mod h1:4Bi6QPql/J/LkTDqv7R/cd3hPo4k2DG6Ptcz060Ez5I= k8s.io/klog/v2 v2.0.0/go.mod h1:PBfzABfn139FHAV07az/IF9Wp1bkk3vpT2XSJ76fSDE= k8s.io/klog/v2 v2.2.0 h1:XRvcwJozkgZ1UQJmfMGpvRthQHOvihEhYtDfAaxMz/A= k8s.io/klog/v2 v2.2.0/go.mod h1:Od+F08eJP+W3HUb4pSrPpgp9DGU4GzlpG/TmITuYh/Y= +k8s.io/klog/v2 v2.4.0 h1:7+X0fUguPyrKEC4WjH8iGDg3laWgMo5tMnRTIGTTxGQ= +k8s.io/klog/v2 v2.4.0/go.mod h1:Od+F08eJP+W3HUb4pSrPpgp9DGU4GzlpG/TmITuYh/Y= k8s.io/kube-aggregator v0.18.0/go.mod h1:ateewQ5QbjMZF/dihEFXwaEwoA4v/mayRvzfmvb6eqI= k8s.io/kube-aggregator v0.19.0 h1:rL4fsftMaqkKjaibArYDaBeqN41CHaJzgRJjUB9IrIg= k8s.io/kube-aggregator v0.19.0/go.mod h1:1Ln45PQggFAG8xOqWPIYMxUq8WNtpPnYsbUJ39DpF/A= diff --git a/vendor/k8s.io/klog/v2/README.md b/vendor/k8s.io/klog/v2/README.md index 2f9f6f0d82..64d29622e8 100644 --- a/vendor/k8s.io/klog/v2/README.md +++ b/vendor/k8s.io/klog/v2/README.md @@ -27,7 +27,7 @@ Historical context is available here: How to use klog =============== -- Replace imports for `github.com/golang/glog` with `k8s.io/klog` +- Replace imports for `"github.com/golang/glog"` with `"k8s.io/klog/v2"` - Use `klog.InitFlags(nil)` explicitly for initializing global flags as we no longer use `init()` method to register the flags - You can now use `log_file` instead of `log_dir` for logging to a single file (See `examples/log_file/usage_log_file.go`) - If you want to redirect everything logged using klog somewhere else (say syslog!), you can use `klog.SetOutput()` method and supply a `io.Writer`. (See `examples/set_output/usage_set_output.go`) @@ -35,6 +35,10 @@ How to use klog **NOTE**: please use the newer go versions that support semantic import versioning in modules, ideally go 1.11.4 or greater. +### Coexisting with klog/v2 + +See [this example](examples/coexist_klog_v1_and_v2/) to see how to coexist with both klog/v1 and klog/v2. + ### Coexisting with glog This package can be used side by side with glog. [This example](examples/coexist_glog/coexist_glog.go) shows how to initialize and synchronize flags from the global `flag.CommandLine` FlagSet. In addition, the example makes use of stderr as combined output by setting `alsologtostderr` (or `logtostderr`) to `true`. diff --git a/vendor/k8s.io/klog/v2/SECURITY.md b/vendor/k8s.io/klog/v2/SECURITY.md new file mode 100644 index 0000000000..2083d44cdf --- /dev/null +++ b/vendor/k8s.io/klog/v2/SECURITY.md @@ -0,0 +1,22 @@ +# Security Policy + +## Security Announcements + +Join the [kubernetes-security-announce] group for security and vulnerability announcements. + +You can also subscribe to an RSS feed of the above using [this link][kubernetes-security-announce-rss]. + +## Reporting a Vulnerability + +Instructions for reporting a vulnerability can be found on the +[Kubernetes Security and Disclosure Information] page. + +## Supported Versions + +Information about supported Kubernetes versions can be found on the +[Kubernetes version and version skew support policy] page on the Kubernetes website. + +[kubernetes-security-announce]: https://groups.google.com/forum/#!forum/kubernetes-security-announce +[kubernetes-security-announce-rss]: https://groups.google.com/forum/feed/kubernetes-security-announce/msgs/rss_v2_0.xml?num=50 +[Kubernetes version and version skew support policy]: https://kubernetes.io/docs/setup/release/version-skew-policy/#supported-versions +[Kubernetes Security and Disclosure Information]: https://kubernetes.io/docs/reference/issues-security/security/#report-a-vulnerability diff --git a/vendor/k8s.io/klog/v2/klog.go b/vendor/k8s.io/klog/v2/klog.go index ae2b861382..23cced6250 100644 --- a/vendor/k8s.io/klog/v2/klog.go +++ b/vendor/k8s.io/klog/v2/klog.go @@ -413,6 +413,7 @@ func init() { logging.skipHeaders = false logging.addDirHeader = false logging.skipLogHeaders = false + logging.oneOutput = false go logging.flushDaemon() } @@ -432,6 +433,7 @@ func InitFlags(flagset *flag.FlagSet) { flagset.Var(&logging.verbosity, "v", "number for the log level verbosity") flagset.BoolVar(&logging.addDirHeader, "add_dir_header", logging.addDirHeader, "If true, adds the file directory to the header of the log messages") flagset.BoolVar(&logging.skipHeaders, "skip_headers", logging.skipHeaders, "If true, avoid header prefixes in the log messages") + flagset.BoolVar(&logging.oneOutput, "one_output", logging.oneOutput, "If true, only write logs to their native severity level (vs also writing to each lower severity level") flagset.BoolVar(&logging.skipLogHeaders, "skip_log_headers", logging.skipLogHeaders, "If true, avoid headers when opening log files") 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") @@ -505,6 +507,12 @@ type loggingT struct { // If set, all output will be redirected unconditionally to the provided logr.Logger logr logr.Logger + + // If true, messages will not be propagated to lower severity log levels + oneOutput bool + + // If set, all output will be filtered through the filter. + filter LogFilter } // buffer holds a byte Buffer for reuse. The zero value is ready for use. @@ -687,7 +695,7 @@ func (buf *buffer) someDigits(i, d int) int { return copy(buf.tmp[i:], buf.tmp[j:]) } -func (l *loggingT) println(s severity, logr logr.Logger, args ...interface{}) { +func (l *loggingT) println(s severity, logr logr.Logger, filter LogFilter, args ...interface{}) { buf, file, line := l.header(s, 0) // if logr is set, we clear the generated header as we rely on the backing // logr implementation to print headers @@ -695,15 +703,18 @@ func (l *loggingT) println(s severity, logr logr.Logger, args ...interface{}) { l.putBuffer(buf) buf = l.getBuffer() } + if filter != nil { + args = filter.Filter(args) + } fmt.Fprintln(buf, args...) l.output(s, logr, buf, file, line, false) } -func (l *loggingT) print(s severity, logr logr.Logger, args ...interface{}) { - l.printDepth(s, logr, 1, args...) +func (l *loggingT) print(s severity, logr logr.Logger, filter LogFilter, args ...interface{}) { + l.printDepth(s, logr, filter, 1, args...) } -func (l *loggingT) printDepth(s severity, logr logr.Logger, depth int, args ...interface{}) { +func (l *loggingT) printDepth(s severity, logr logr.Logger, filter LogFilter, depth int, args ...interface{}) { buf, file, line := l.header(s, depth) // if logr is set, we clear the generated header as we rely on the backing // logr implementation to print headers @@ -711,6 +722,9 @@ func (l *loggingT) printDepth(s severity, logr logr.Logger, depth int, args ...i l.putBuffer(buf) buf = l.getBuffer() } + if filter != nil { + args = filter.Filter(args) + } fmt.Fprint(buf, args...) if buf.Bytes()[buf.Len()-1] != '\n' { buf.WriteByte('\n') @@ -718,7 +732,7 @@ func (l *loggingT) printDepth(s severity, logr logr.Logger, depth int, args ...i l.output(s, logr, buf, file, line, false) } -func (l *loggingT) printf(s severity, logr logr.Logger, format string, args ...interface{}) { +func (l *loggingT) printf(s severity, logr logr.Logger, filter LogFilter, format string, args ...interface{}) { buf, file, line := l.header(s, 0) // if logr is set, we clear the generated header as we rely on the backing // logr implementation to print headers @@ -726,6 +740,9 @@ func (l *loggingT) printf(s severity, logr logr.Logger, format string, args ...i l.putBuffer(buf) buf = l.getBuffer() } + if filter != nil { + format, args = filter.FilterF(format, args) + } fmt.Fprintf(buf, format, args...) if buf.Bytes()[buf.Len()-1] != '\n' { buf.WriteByte('\n') @@ -736,7 +753,7 @@ func (l *loggingT) printf(s severity, logr logr.Logger, format string, args ...i // printWithFileLine behaves like print but uses the provided file and line number. If // alsoLogToStderr is true, the log message always appears on standard error; it // will also appear in the log file unless --logtostderr is set. -func (l *loggingT) printWithFileLine(s severity, logr logr.Logger, file string, line int, alsoToStderr bool, args ...interface{}) { +func (l *loggingT) printWithFileLine(s severity, logr logr.Logger, filter LogFilter, file string, line int, alsoToStderr bool, args ...interface{}) { buf := l.formatHeader(s, file, line) // if logr is set, we clear the generated header as we rely on the backing // logr implementation to print headers @@ -744,6 +761,9 @@ func (l *loggingT) printWithFileLine(s severity, logr logr.Logger, file string, l.putBuffer(buf) buf = l.getBuffer() } + if filter != nil { + args = filter.Filter(args) + } fmt.Fprint(buf, args...) if buf.Bytes()[buf.Len()-1] != '\n' { buf.WriteByte('\n') @@ -752,18 +772,24 @@ func (l *loggingT) printWithFileLine(s severity, logr logr.Logger, file string, } // if loggr is specified, will call loggr.Error, otherwise output with logging module. -func (l *loggingT) errorS(err error, loggr logr.Logger, msg string, keysAndValues ...interface{}) { +func (l *loggingT) errorS(err error, loggr logr.Logger, filter LogFilter, msg string, keysAndValues ...interface{}) { + if filter != nil { + msg, keysAndValues = filter.FilterS(msg, keysAndValues) + } if loggr != nil { - loggr.Error(err, msg, keysAndValues) + loggr.Error(err, msg, keysAndValues...) return } l.printS(err, msg, keysAndValues...) } // if loggr is specified, will call loggr.Info, otherwise output with logging module. -func (l *loggingT) infoS(loggr logr.Logger, msg string, keysAndValues ...interface{}) { +func (l *loggingT) infoS(loggr logr.Logger, filter LogFilter, msg string, keysAndValues ...interface{}) { + if filter != nil { + msg, keysAndValues = filter.FilterS(msg, keysAndValues) + } if loggr != nil { - loggr.Info(msg, keysAndValues) + loggr.Info(msg, keysAndValues...) return } l.printS(nil, msg, keysAndValues...) @@ -785,7 +811,7 @@ func (l *loggingT) printS(err error, msg string, keysAndValues ...interface{}) { } else { s = errorLog } - l.printDepth(s, logging.logr, 2, b) + l.printDepth(s, logging.logr, nil, 2, b) } const missingValue = "(MISSING)" @@ -919,18 +945,22 @@ func (l *loggingT) output(s severity, log logr.Logger, buf *buffer, file string, } } - switch s { - case fatalLog: - l.file[fatalLog].Write(data) - fallthrough - case errorLog: - l.file[errorLog].Write(data) - fallthrough - case warningLog: - l.file[warningLog].Write(data) - fallthrough - case infoLog: - l.file[infoLog].Write(data) + if l.oneOutput { + l.file[s].Write(data) + } else { + switch s { + case fatalLog: + l.file[fatalLog].Write(data) + fallthrough + case errorLog: + l.file[errorLog].Write(data) + fallthrough + case warningLog: + l.file[warningLog].Write(data) + fallthrough + case infoLog: + l.file[infoLog].Write(data) + } } } } @@ -1077,11 +1107,19 @@ func (sb *syncBuffer) rotateFile(now time.Time, startup bool) error { } var err error sb.file, _, err = create(severityName[sb.sev], now, startup) - sb.nbytes = 0 if err != nil { return err } - + if startup { + fileInfo, err := sb.file.Stat() + if err != nil { + return fmt.Errorf("file stat could not get fileinfo: %v", err) + } + // init file size + sb.nbytes = uint64(fileInfo.Size()) + } else { + sb.nbytes = 0 + } sb.Writer = bufio.NewWriterSize(sb.file, bufferSize) if sb.logger.skipLogHeaders { @@ -1197,7 +1235,7 @@ func (lb logBridge) Write(b []byte) (n int, err error) { } // printWithFileLine with alsoToStderr=true, so standard log messages // always appear on standard error. - logging.printWithFileLine(severity(lb), logging.logr, file, line, true, text) + logging.printWithFileLine(severity(lb), logging.logr, logging.filter, file, line, true, text) return len(b), nil } @@ -1232,13 +1270,14 @@ func (l *loggingT) setV(pc uintptr) Level { type Verbose struct { enabled bool logr logr.Logger + filter LogFilter } func newVerbose(level Level, b bool) Verbose { if logging.logr == nil { - return Verbose{b, nil} + return Verbose{b, nil, logging.filter} } - return Verbose{b, logging.logr.V(int(level))} + return Verbose{b, logging.logr.V(int(level)), logging.filter} } // V reports whether verbosity at the call site is at least the requested level. @@ -1265,7 +1304,7 @@ func V(level Level) Verbose { return newVerbose(level, true) } - // It's off globally but it vmodule may still be set. + // It's off globally but vmodule may still be set. // Here is another cheap but safe test to see if vmodule is enabled. if atomic.LoadInt32(&logging.filterLength) > 0 { // Now we need a proper lock to use the logging structure. The pcs field @@ -1296,7 +1335,7 @@ func (v Verbose) Enabled() bool { // See the documentation of V for usage. func (v Verbose) Info(args ...interface{}) { if v.enabled { - logging.print(infoLog, v.logr, args...) + logging.print(infoLog, v.logr, v.filter, args...) } } @@ -1304,7 +1343,7 @@ func (v Verbose) Info(args ...interface{}) { // See the documentation of V for usage. func (v Verbose) Infoln(args ...interface{}) { if v.enabled { - logging.println(infoLog, v.logr, args...) + logging.println(infoLog, v.logr, v.filter, args...) } } @@ -1312,7 +1351,7 @@ func (v Verbose) Infoln(args ...interface{}) { // See the documentation of V for usage. func (v Verbose) Infof(format string, args ...interface{}) { if v.enabled { - logging.printf(infoLog, v.logr, format, args...) + logging.printf(infoLog, v.logr, v.filter, format, args...) } } @@ -1320,40 +1359,47 @@ func (v Verbose) Infof(format string, args ...interface{}) { // See the documentation of V for usage. func (v Verbose) InfoS(msg string, keysAndValues ...interface{}) { if v.enabled { - logging.infoS(v.logr, msg, keysAndValues...) + logging.infoS(v.logr, v.filter, msg, keysAndValues...) } } -// Error is equivalent to the global Error function, guarded by the value of v. -// See the documentation of V for usage. +// Deprecated: Use ErrorS instead. func (v Verbose) Error(err error, msg string, args ...interface{}) { if v.enabled { - logging.errorS(err, v.logr, msg, args...) + logging.errorS(err, v.logr, v.filter, msg, args...) + } +} + +// ErrorS is equivalent to the global Error function, guarded by the value of v. +// See the documentation of V for usage. +func (v Verbose) ErrorS(err error, msg string, keysAndValues ...interface{}) { + if v.enabled { + logging.errorS(err, v.logr, v.filter, msg, keysAndValues...) } } // Info logs to the INFO log. // Arguments are handled in the manner of fmt.Print; a newline is appended if missing. func Info(args ...interface{}) { - logging.print(infoLog, logging.logr, args...) + logging.print(infoLog, logging.logr, logging.filter, args...) } // InfoDepth acts as Info but uses depth to determine which call frame to log. // InfoDepth(0, "msg") is the same as Info("msg"). func InfoDepth(depth int, args ...interface{}) { - logging.printDepth(infoLog, logging.logr, depth, args...) + logging.printDepth(infoLog, logging.logr, logging.filter, depth, args...) } // Infoln logs to the INFO log. // Arguments are handled in the manner of fmt.Println; a newline is always appended. func Infoln(args ...interface{}) { - logging.println(infoLog, logging.logr, args...) + logging.println(infoLog, logging.logr, logging.filter, args...) } // Infof logs to the INFO log. // Arguments are handled in the manner of fmt.Printf; a newline is appended if missing. func Infof(format string, args ...interface{}) { - logging.printf(infoLog, logging.logr, format, args...) + logging.printf(infoLog, logging.logr, logging.filter, format, args...) } // InfoS structured logs to the INFO log. @@ -1365,55 +1411,55 @@ func Infof(format string, args ...interface{}) { // output: // >> I1025 00:15:15.525108 1 controller_utils.go:116] "Pod status updated" pod="kubedns" status="ready" func InfoS(msg string, keysAndValues ...interface{}) { - logging.infoS(logging.logr, msg, keysAndValues...) + logging.infoS(logging.logr, logging.filter, msg, keysAndValues...) } // Warning logs to the WARNING and INFO logs. // Arguments are handled in the manner of fmt.Print; a newline is appended if missing. func Warning(args ...interface{}) { - logging.print(warningLog, logging.logr, args...) + logging.print(warningLog, logging.logr, logging.filter, args...) } // WarningDepth acts as Warning but uses depth to determine which call frame to log. // WarningDepth(0, "msg") is the same as Warning("msg"). func WarningDepth(depth int, args ...interface{}) { - logging.printDepth(warningLog, logging.logr, depth, args...) + logging.printDepth(warningLog, logging.logr, logging.filter, depth, args...) } // Warningln logs to the WARNING and INFO logs. // Arguments are handled in the manner of fmt.Println; a newline is always appended. func Warningln(args ...interface{}) { - logging.println(warningLog, logging.logr, args...) + logging.println(warningLog, logging.logr, logging.filter, args...) } // Warningf logs to the WARNING and INFO logs. // Arguments are handled in the manner of fmt.Printf; a newline is appended if missing. func Warningf(format string, args ...interface{}) { - logging.printf(warningLog, logging.logr, format, args...) + logging.printf(warningLog, logging.logr, logging.filter, format, args...) } // Error logs to the ERROR, WARNING, and INFO logs. // Arguments are handled in the manner of fmt.Print; a newline is appended if missing. func Error(args ...interface{}) { - logging.print(errorLog, logging.logr, args...) + logging.print(errorLog, logging.logr, logging.filter, args...) } // ErrorDepth acts as Error but uses depth to determine which call frame to log. // ErrorDepth(0, "msg") is the same as Error("msg"). func ErrorDepth(depth int, args ...interface{}) { - logging.printDepth(errorLog, logging.logr, depth, args...) + logging.printDepth(errorLog, logging.logr, logging.filter, depth, args...) } // Errorln logs to the ERROR, WARNING, and INFO logs. // Arguments are handled in the manner of fmt.Println; a newline is always appended. func Errorln(args ...interface{}) { - logging.println(errorLog, logging.logr, args...) + logging.println(errorLog, logging.logr, logging.filter, args...) } // Errorf logs to the ERROR, WARNING, and INFO logs. // Arguments are handled in the manner of fmt.Printf; a newline is appended if missing. func Errorf(format string, args ...interface{}) { - logging.printf(errorLog, logging.logr, format, args...) + logging.printf(errorLog, logging.logr, logging.filter, format, args...) } // ErrorS structured logs to the ERROR, WARNING, and INFO logs. @@ -1426,34 +1472,34 @@ func Errorf(format string, args ...interface{}) { // output: // >> E1025 00:15:15.525108 1 controller_utils.go:114] "Failed to update pod status" err="timeout" func ErrorS(err error, msg string, keysAndValues ...interface{}) { - logging.errorS(err, logging.logr, msg, keysAndValues...) + logging.errorS(err, logging.logr, logging.filter, msg, keysAndValues...) } // Fatal logs to the FATAL, ERROR, WARNING, and INFO logs, // including a stack trace of all running goroutines, then calls os.Exit(255). // Arguments are handled in the manner of fmt.Print; a newline is appended if missing. func Fatal(args ...interface{}) { - logging.print(fatalLog, logging.logr, args...) + logging.print(fatalLog, logging.logr, logging.filter, args...) } // FatalDepth acts as Fatal but uses depth to determine which call frame to log. // FatalDepth(0, "msg") is the same as Fatal("msg"). func FatalDepth(depth int, args ...interface{}) { - logging.printDepth(fatalLog, logging.logr, depth, args...) + logging.printDepth(fatalLog, logging.logr, logging.filter, depth, args...) } // Fatalln logs to the FATAL, ERROR, WARNING, and INFO logs, // including a stack trace of all running goroutines, then calls os.Exit(255). // Arguments are handled in the manner of fmt.Println; a newline is always appended. func Fatalln(args ...interface{}) { - logging.println(fatalLog, logging.logr, args...) + logging.println(fatalLog, logging.logr, logging.filter, args...) } // Fatalf logs to the FATAL, ERROR, WARNING, and INFO logs, // including a stack trace of all running goroutines, then calls os.Exit(255). // Arguments are handled in the manner of fmt.Printf; a newline is appended if missing. func Fatalf(format string, args ...interface{}) { - logging.printf(fatalLog, logging.logr, format, args...) + logging.printf(fatalLog, logging.logr, logging.filter, format, args...) } // fatalNoStacks is non-zero if we are to exit without dumping goroutine stacks. @@ -1464,27 +1510,42 @@ var fatalNoStacks uint32 // Arguments are handled in the manner of fmt.Print; a newline is appended if missing. func Exit(args ...interface{}) { atomic.StoreUint32(&fatalNoStacks, 1) - logging.print(fatalLog, logging.logr, args...) + logging.print(fatalLog, logging.logr, logging.filter, args...) } // ExitDepth acts as Exit but uses depth to determine which call frame to log. // ExitDepth(0, "msg") is the same as Exit("msg"). func ExitDepth(depth int, args ...interface{}) { atomic.StoreUint32(&fatalNoStacks, 1) - logging.printDepth(fatalLog, logging.logr, depth, args...) + logging.printDepth(fatalLog, logging.logr, logging.filter, depth, args...) } // Exitln logs to the FATAL, ERROR, WARNING, and INFO logs, then calls os.Exit(1). func Exitln(args ...interface{}) { atomic.StoreUint32(&fatalNoStacks, 1) - logging.println(fatalLog, logging.logr, args...) + logging.println(fatalLog, logging.logr, logging.filter, args...) } // Exitf logs to the FATAL, ERROR, WARNING, and INFO logs, then calls os.Exit(1). // Arguments are handled in the manner of fmt.Printf; a newline is appended if missing. func Exitf(format string, args ...interface{}) { atomic.StoreUint32(&fatalNoStacks, 1) - logging.printf(fatalLog, logging.logr, format, args...) + logging.printf(fatalLog, logging.logr, logging.filter, format, args...) +} + +// LogFilter is a collection of functions that can filter all logging calls, +// e.g. for sanitization of arguments and prevent accidental leaking of secrets. +type LogFilter interface { + Filter(args []interface{}) []interface{} + FilterF(format string, args []interface{}) (string, []interface{}) + FilterS(msg string, keysAndValues []interface{}) (string, []interface{}) +} + +func SetLogFilter(filter LogFilter) { + logging.mu.Lock() + defer logging.mu.Unlock() + + logging.filter = filter } // ObjectRef references a kubernetes object diff --git a/vendor/k8s.io/kubernetes/pkg/util/flag/BUILD b/vendor/k8s.io/kubernetes/pkg/util/flag/BUILD deleted file mode 100644 index 330b399983..0000000000 --- a/vendor/k8s.io/kubernetes/pkg/util/flag/BUILD +++ /dev/null @@ -1,14 +0,0 @@ -load("@io_bazel_rules_go//go:def.bzl", "go_library") - -go_library( - name = "go_default_library", - srcs = ["flags.go"], - importmap = "k8s.io/cloud-provider-gcp/vendor/k8s.io/kubernetes/pkg/util/flag", - importpath = "k8s.io/kubernetes/pkg/util/flag", - visibility = ["//visibility:public"], - deps = [ - "//vendor/github.com/spf13/pflag:go_default_library", - "//vendor/k8s.io/apimachinery/pkg/util/net:go_default_library", - "//vendor/k8s.io/utils/net:go_default_library", - ], -) diff --git a/vendor/k8s.io/kubernetes/pkg/util/flag/flags.go b/vendor/k8s.io/kubernetes/pkg/util/flag/flags.go deleted file mode 100644 index 7c489e93ab..0000000000 --- a/vendor/k8s.io/kubernetes/pkg/util/flag/flags.go +++ /dev/null @@ -1,153 +0,0 @@ -/* -Copyright 2018 The Kubernetes Authors. - -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 flag - -import ( - "fmt" - "net" - - "github.com/spf13/pflag" - - utilnet "k8s.io/apimachinery/pkg/util/net" - utilsnet "k8s.io/utils/net" -) - -// TODO(mikedanese): remove these flag wrapper types when we remove command line flags - -var ( - _ pflag.Value = &IPVar{} - _ pflag.Value = &IPPortVar{} - _ pflag.Value = &PortRangeVar{} -) - -// IPVar is used for validating a command line option that represents an IP. It implements the pflag.Value interface -type IPVar struct { - Val *string -} - -// Set sets the flag value -func (v IPVar) Set(s string) error { - if len(s) == 0 { - v.Val = nil - return nil - } - if net.ParseIP(s) == nil { - return fmt.Errorf("%q is not a valid IP address", s) - } - if v.Val == nil { - // it's okay to panic here since this is programmer error - panic("the string pointer passed into IPVar should not be nil") - } - *v.Val = s - return nil -} - -// String returns the flag value -func (v IPVar) String() string { - if v.Val == nil { - return "" - } - return *v.Val -} - -// Type gets the flag type -func (v IPVar) Type() string { - return "ip" -} - -// IPPortVar is used for validating a command line option that represents an IP and a port. It implements the pflag.Value interface -type IPPortVar struct { - Val *string -} - -// Set sets the flag value -func (v IPPortVar) Set(s string) error { - if len(s) == 0 { - v.Val = nil - return nil - } - - if v.Val == nil { - // it's okay to panic here since this is programmer error - panic("the string pointer passed into IPPortVar should not be nil") - } - - // Both IP and IP:port are valid. - // Attempt to parse into IP first. - if net.ParseIP(s) != nil { - *v.Val = s - return nil - } - - // Can not parse into IP, now assume IP:port. - host, port, err := net.SplitHostPort(s) - if err != nil { - return fmt.Errorf("%q is not in a valid format (ip or ip:port): %v", s, err) - } - if net.ParseIP(host) == nil { - return fmt.Errorf("%q is not a valid IP address", host) - } - if _, err := utilsnet.ParsePort(port, true); err != nil { - return fmt.Errorf("%q is not a valid number", port) - } - *v.Val = s - return nil -} - -// String returns the flag value -func (v IPPortVar) String() string { - if v.Val == nil { - return "" - } - return *v.Val -} - -// Type gets the flag type -func (v IPPortVar) Type() string { - return "ipport" -} - -// PortRangeVar is used for validating a command line option that represents a port range. It implements the pflag.Value interface -type PortRangeVar struct { - Val *string -} - -// Set sets the flag value -func (v PortRangeVar) Set(s string) error { - if _, err := utilnet.ParsePortRange(s); err != nil { - return fmt.Errorf("%q is not a valid port range: %v", s, err) - } - if v.Val == nil { - // it's okay to panic here since this is programmer error - panic("the string pointer passed into PortRangeVar should not be nil") - } - *v.Val = s - return nil -} - -// String returns the flag value -func (v PortRangeVar) String() string { - if v.Val == nil { - return "" - } - return *v.Val -} - -// Type gets the flag type -func (v PortRangeVar) Type() string { - return "port-range" -} diff --git a/vendor/modules.txt b/vendor/modules.txt index a8961b50e6..1f7054a579 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -828,7 +828,7 @@ k8s.io/component-base/version k8s.io/component-base/version/verflag # k8s.io/klog v1.0.0 k8s.io/klog -# k8s.io/klog/v2 v2.2.0 +# k8s.io/klog/v2 v2.4.0 k8s.io/klog/v2 # k8s.io/kube-controller-manager v0.19.0 => k8s.io/kube-controller-manager v0.19.0 k8s.io/kube-controller-manager/config/v1alpha1 @@ -912,7 +912,6 @@ k8s.io/kubernetes/pkg/kubelet/types k8s.io/kubernetes/pkg/master/ports k8s.io/kubernetes/pkg/security/apparmor k8s.io/kubernetes/pkg/serviceaccount -k8s.io/kubernetes/pkg/util/flag k8s.io/kubernetes/pkg/util/hash k8s.io/kubernetes/pkg/util/parsers k8s.io/kubernetes/pkg/util/taints