summaryrefslogtreecommitdiff
path: root/vendor/k8s.io/klog/v2
diff options
context:
space:
mode:
authorDaniel J Walsh <dwalsh@redhat.com>2022-02-17 13:46:51 -0500
committerDaniel J Walsh <dwalsh@redhat.com>2022-02-22 14:38:57 -0500
commit80c5962dba7f5ecd6b602aecd0df479bd04391b1 (patch)
treea1d7fada738182c2eb8cd6993f33625ae704ba94 /vendor/k8s.io/klog/v2
parentd3903a85910979d8212028cf814574047015db58 (diff)
downloadpodman-80c5962dba7f5ecd6b602aecd0df479bd04391b1.tar.gz
podman-80c5962dba7f5ecd6b602aecd0df479bd04391b1.tar.bz2
podman-80c5962dba7f5ecd6b602aecd0df479bd04391b1.zip
Add containers-common spec and command to podman
Since containers-common package is tied to specific versions of Podman, add tools to build the package into the contrib directory This should help other distributions to figure out which commont package to ship. Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
Diffstat (limited to 'vendor/k8s.io/klog/v2')
-rw-r--r--vendor/k8s.io/klog/v2/OWNERS2
-rw-r--r--vendor/k8s.io/klog/v2/go.mod2
-rw-r--r--vendor/k8s.io/klog/v2/go.sum4
-rw-r--r--vendor/k8s.io/klog/v2/klog.go106
4 files changed, 79 insertions, 35 deletions
diff --git a/vendor/k8s.io/klog/v2/OWNERS b/vendor/k8s.io/klog/v2/OWNERS
index 380e514f2..ad5063fdf 100644
--- a/vendor/k8s.io/klog/v2/OWNERS
+++ b/vendor/k8s.io/klog/v2/OWNERS
@@ -15,5 +15,5 @@ approvers:
- tallclair
- piosz
- brancz
- - DirectXMan12
- lavalamp
+ - serathius
diff --git a/vendor/k8s.io/klog/v2/go.mod b/vendor/k8s.io/klog/v2/go.mod
index eb297b6a1..31aefba74 100644
--- a/vendor/k8s.io/klog/v2/go.mod
+++ b/vendor/k8s.io/klog/v2/go.mod
@@ -2,4 +2,4 @@ module k8s.io/klog/v2
go 1.13
-require github.com/go-logr/logr v0.4.0
+require github.com/go-logr/logr v1.2.0
diff --git a/vendor/k8s.io/klog/v2/go.sum b/vendor/k8s.io/klog/v2/go.sum
index 5778f8174..919fbadbc 100644
--- a/vendor/k8s.io/klog/v2/go.sum
+++ b/vendor/k8s.io/klog/v2/go.sum
@@ -1,2 +1,2 @@
-github.com/go-logr/logr v0.4.0 h1:K7/B1jt6fIBQVd4Owv2MqGQClcgf0R266+7C/QjRcLc=
-github.com/go-logr/logr v0.4.0/go.mod h1:z6/tIYblkpsD+a4lm/fGIIU9mZ+XfAiaFtq7xTgseGU=
+github.com/go-logr/logr v1.2.0 h1:QK40JKJyMdUDz+h+xvCsru/bJhvG0UxvePV0ufL/AcE=
+github.com/go-logr/logr v1.2.0/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
diff --git a/vendor/k8s.io/klog/v2/klog.go b/vendor/k8s.io/klog/v2/klog.go
index 1e187f763..45efbb075 100644
--- a/vendor/k8s.io/klog/v2/klog.go
+++ b/vendor/k8s.io/klog/v2/klog.go
@@ -509,7 +509,7 @@ type loggingT struct {
addDirHeader bool
// If set, all output will be redirected unconditionally to the provided logr.Logger
- logr logr.Logger
+ logr *logr.Logger
// If true, messages will not be propagated to lower severity log levels
oneOutput bool
@@ -698,11 +698,11 @@ 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, filter LogFilter, args ...interface{}) {
+func (l *loggingT) println(s severity, logger *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
- if logr != nil {
+ // if logger is set, we clear the generated header as we rely on the backing
+ // logger implementation to print headers
+ if logger != nil {
l.putBuffer(buf)
buf = l.getBuffer()
}
@@ -710,18 +710,18 @@ func (l *loggingT) println(s severity, logr logr.Logger, filter LogFilter, args
args = filter.Filter(args)
}
fmt.Fprintln(buf, args...)
- l.output(s, logr, buf, 0 /* depth */, file, line, false)
+ l.output(s, logger, buf, 0 /* depth */, file, line, false)
}
-func (l *loggingT) print(s severity, logr logr.Logger, filter LogFilter, args ...interface{}) {
- l.printDepth(s, logr, filter, 1, args...)
+func (l *loggingT) print(s severity, logger *logr.Logger, filter LogFilter, args ...interface{}) {
+ l.printDepth(s, logger, filter, 1, args...)
}
-func (l *loggingT) printDepth(s severity, logr logr.Logger, filter LogFilter, depth int, args ...interface{}) {
+func (l *loggingT) printDepth(s severity, logger *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
- if logr != nil {
+ if logger != nil {
l.putBuffer(buf)
buf = l.getBuffer()
}
@@ -732,14 +732,14 @@ func (l *loggingT) printDepth(s severity, logr logr.Logger, filter LogFilter, de
if buf.Bytes()[buf.Len()-1] != '\n' {
buf.WriteByte('\n')
}
- l.output(s, logr, buf, depth, file, line, false)
+ l.output(s, logger, buf, depth, file, line, false)
}
-func (l *loggingT) printf(s severity, logr logr.Logger, filter LogFilter, format string, args ...interface{}) {
+func (l *loggingT) printf(s severity, logger *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
- if logr != nil {
+ if logger != nil {
l.putBuffer(buf)
buf = l.getBuffer()
}
@@ -750,17 +750,17 @@ func (l *loggingT) printf(s severity, logr logr.Logger, filter LogFilter, format
if buf.Bytes()[buf.Len()-1] != '\n' {
buf.WriteByte('\n')
}
- l.output(s, logr, buf, 0 /* depth */, file, line, false)
+ l.output(s, logger, buf, 0 /* depth */, file, line, false)
}
// 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, filter LogFilter, file string, line int, alsoToStderr bool, args ...interface{}) {
+func (l *loggingT) printWithFileLine(s severity, logger *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
- if logr != nil {
+ if logger != nil {
l.putBuffer(buf)
buf = l.getBuffer()
}
@@ -771,28 +771,28 @@ func (l *loggingT) printWithFileLine(s severity, logr logr.Logger, filter LogFil
if buf.Bytes()[buf.Len()-1] != '\n' {
buf.WriteByte('\n')
}
- l.output(s, logr, buf, 2 /* depth */, file, line, alsoToStderr)
+ l.output(s, logger, buf, 2 /* depth */, file, line, alsoToStderr)
}
// if loggr is specified, will call loggr.Error, otherwise output with logging module.
-func (l *loggingT) errorS(err error, loggr logr.Logger, filter LogFilter, depth int, msg string, keysAndValues ...interface{}) {
+func (l *loggingT) errorS(err error, logger *logr.Logger, filter LogFilter, depth int, msg string, keysAndValues ...interface{}) {
if filter != nil {
msg, keysAndValues = filter.FilterS(msg, keysAndValues)
}
- if loggr != nil {
- logr.WithCallDepth(loggr, depth+2).Error(err, msg, keysAndValues...)
+ if logger != nil {
+ logger.WithCallDepth(depth+2).Error(err, msg, keysAndValues...)
return
}
l.printS(err, errorLog, depth+1, msg, keysAndValues...)
}
// if loggr is specified, will call loggr.Info, otherwise output with logging module.
-func (l *loggingT) infoS(loggr logr.Logger, filter LogFilter, depth int, msg string, keysAndValues ...interface{}) {
+func (l *loggingT) infoS(logger *logr.Logger, filter LogFilter, depth int, msg string, keysAndValues ...interface{}) {
if filter != nil {
msg, keysAndValues = filter.FilterS(msg, keysAndValues)
}
- if loggr != nil {
- logr.WithCallDepth(loggr, depth+2).Info(msg, keysAndValues...)
+ if logger != nil {
+ logger.WithCallDepth(depth+2).Info(msg, keysAndValues...)
return
}
l.printS(nil, infoLog, depth+1, msg, keysAndValues...)
@@ -862,11 +862,23 @@ func (rb *redirectBuffer) Write(bytes []byte) (n int, err error) {
// Use as:
// ...
// klog.SetLogger(zapr.NewLogger(zapLog))
+//
+// To remove a backing logr implemention, use ClearLogger. Setting an
+// empty logger with SetLogger(logr.Logger{}) does not work.
func SetLogger(logr logr.Logger) {
logging.mu.Lock()
defer logging.mu.Unlock()
- logging.logr = logr
+ logging.logr = &logr
+}
+
+// ClearLogger removes a backing logr implementation if one was set earlier
+// with SetLogger.
+func ClearLogger() {
+ logging.mu.Lock()
+ defer logging.mu.Unlock()
+
+ logging.logr = nil
}
// SetOutput sets the output destination for all severities
@@ -904,7 +916,7 @@ func LogToStderr(stderr bool) {
}
// output writes the data to the log files and releases the buffer.
-func (l *loggingT) output(s severity, log logr.Logger, buf *buffer, depth int, file string, line int, alsoToStderr bool) {
+func (l *loggingT) output(s severity, log *logr.Logger, buf *buffer, depth int, file string, line int, alsoToStderr bool) {
l.mu.Lock()
if l.traceLocation.isSet() {
if l.traceLocation.match(file, line) {
@@ -916,9 +928,9 @@ func (l *loggingT) output(s severity, log logr.Logger, buf *buffer, depth int, f
// TODO: set 'severity' and caller information as structured log info
// keysAndValues := []interface{}{"severity", severityName[s], "file", file, "line", line}
if s == errorLog {
- logr.WithCallDepth(l.logr, depth+3).Error(nil, string(data))
+ l.logr.WithCallDepth(depth+3).Error(nil, string(data))
} else {
- logr.WithCallDepth(log, depth+3).Info(string(data))
+ log.WithCallDepth(depth + 3).Info(string(data))
}
} else if l.toStderr {
os.Stderr.Write(data)
@@ -1269,7 +1281,7 @@ func (l *loggingT) setV(pc uintptr) Level {
// See the documentation of V for more information.
type Verbose struct {
enabled bool
- logr logr.Logger
+ logr *logr.Logger
filter LogFilter
}
@@ -1277,7 +1289,8 @@ func newVerbose(level Level, b bool) Verbose {
if logging.logr == nil {
return Verbose{b, nil, logging.filter}
}
- return Verbose{b, logging.logr.V(int(level)), logging.filter}
+ v := logging.logr.V(int(level))
+ return Verbose{b, &v, logging.filter}
}
// V reports whether verbosity at the call site is at least the requested level.
@@ -1315,9 +1328,14 @@ func V(level Level) Verbose {
if runtime.Callers(2, logging.pcs[:]) == 0 {
return newVerbose(level, false)
}
- v, ok := logging.vmap[logging.pcs[0]]
+ // runtime.Callers returns "return PCs", but we want
+ // to look up the symbolic information for the call,
+ // so subtract 1 from the PC. runtime.CallersFrames
+ // would be cleaner, but allocates.
+ pc := logging.pcs[0] - 1
+ v, ok := logging.vmap[pc]
if !ok {
- v = logging.setV(logging.pcs[0])
+ v = logging.setV(pc)
}
return newVerbose(level, v >= level)
}
@@ -1573,6 +1591,15 @@ func (ref ObjectRef) String() string {
return ref.Name
}
+// MarshalLog ensures that loggers with support for structured output will log
+// as a struct by removing the String method via a custom type.
+func (ref ObjectRef) MarshalLog() interface{} {
+ type or ObjectRef
+ return or(ref)
+}
+
+var _ logr.Marshaler = ObjectRef{}
+
// KMetadata is a subset of the kubernetes k8s.io/apimachinery/pkg/apis/meta/v1.Object interface
// this interface may expand in the future, but will always be a subset of the
// kubernetes k8s.io/apimachinery/pkg/apis/meta/v1.Object interface
@@ -1603,3 +1630,20 @@ func KRef(namespace, name string) ObjectRef {
Namespace: namespace,
}
}
+
+// KObjs returns slice of ObjectRef from an slice of ObjectMeta
+func KObjs(arg interface{}) []ObjectRef {
+ s := reflect.ValueOf(arg)
+ if s.Kind() != reflect.Slice {
+ return nil
+ }
+ objectRefs := make([]ObjectRef, 0, s.Len())
+ for i := 0; i < s.Len(); i++ {
+ if v, ok := s.Index(i).Interface().(KMetadata); ok {
+ objectRefs = append(objectRefs, KObj(v))
+ } else {
+ return nil
+ }
+ }
+ return objectRefs
+}