code
stringlengths
12
335k
docstring
stringlengths
20
20.8k
func_name
stringlengths
1
105
language
stringclasses
1 value
repo
stringclasses
498 values
path
stringlengths
5
172
url
stringlengths
43
235
license
stringclasses
4 values
func Fatalf(format string, args ...interface{}) { logging.printf(severity.FatalLog, logging.logger, logging.filter, format, args...) }
Fatalf logs to the FATAL, ERROR, WARNING, and INFO logs, including a stack trace of all running goroutines, then calls OsExit(255). Arguments are handled in the manner of fmt.Printf; a newline is appended if missing.
Fatalf
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/klog/v2/klog.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/klog/v2/klog.go
Apache-2.0
func FatalfDepth(depth int, format string, args ...interface{}) { logging.printfDepth(severity.FatalLog, logging.logger, logging.filter, depth, format, args...) }
FatalfDepth acts as Fatalf but uses depth to determine which call frame to log. FatalfDepth(0, "msg", args...) is the same as Fatalf("msg", args...).
FatalfDepth
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/klog/v2/klog.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/klog/v2/klog.go
Apache-2.0
func Exit(args ...interface{}) { atomic.StoreUint32(&fatalNoStacks, 1) logging.print(severity.FatalLog, logging.logger, logging.filter, args...) }
Exit logs to the FATAL, ERROR, WARNING, and INFO logs, then calls OsExit(1). Arguments are handled in the manner of fmt.Print; a newline is appended if missing.
Exit
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/klog/v2/klog.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/klog/v2/klog.go
Apache-2.0
func ExitDepth(depth int, args ...interface{}) { atomic.StoreUint32(&fatalNoStacks, 1) logging.printDepth(severity.FatalLog, logging.logger, logging.filter, depth, args...) }
ExitDepth acts as Exit but uses depth to determine which call frame to log. ExitDepth(0, "msg") is the same as Exit("msg").
ExitDepth
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/klog/v2/klog.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/klog/v2/klog.go
Apache-2.0
func Exitln(args ...interface{}) { atomic.StoreUint32(&fatalNoStacks, 1) logging.println(severity.FatalLog, logging.logger, logging.filter, args...) }
Exitln logs to the FATAL, ERROR, WARNING, and INFO logs, then calls OsExit(1).
Exitln
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/klog/v2/klog.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/klog/v2/klog.go
Apache-2.0
func ExitlnDepth(depth int, args ...interface{}) { atomic.StoreUint32(&fatalNoStacks, 1) logging.printlnDepth(severity.FatalLog, logging.logger, logging.filter, depth, args...) }
ExitlnDepth acts as Exitln but uses depth to determine which call frame to log. ExitlnDepth(0, "msg") is the same as Exitln("msg").
ExitlnDepth
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/klog/v2/klog.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/klog/v2/klog.go
Apache-2.0
func Exitf(format string, args ...interface{}) { atomic.StoreUint32(&fatalNoStacks, 1) logging.printf(severity.FatalLog, logging.logger, logging.filter, format, args...) }
Exitf logs to the FATAL, ERROR, WARNING, and INFO logs, then calls OsExit(1). Arguments are handled in the manner of fmt.Printf; a newline is appended if missing.
Exitf
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/klog/v2/klog.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/klog/v2/klog.go
Apache-2.0
func ExitfDepth(depth int, format string, args ...interface{}) { atomic.StoreUint32(&fatalNoStacks, 1) logging.printfDepth(severity.FatalLog, logging.logger, logging.filter, depth, format, args...) }
ExitfDepth acts as Exitf but uses depth to determine which call frame to log. ExitfDepth(0, "msg", args...) is the same as Exitf("msg", args...).
ExitfDepth
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/klog/v2/klog.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/klog/v2/klog.go
Apache-2.0
func SetLogFilter(filter LogFilter) { logging.filter = filter }
SetLogFilter installs a filter that is used for all log calls. Modifying the filter is not thread-safe and should be done while no other goroutines invoke log calls, usually during program initialization.
SetLogFilter
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/klog/v2/klog.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/klog/v2/klog.go
Apache-2.0
func SetLogger(logger logr.Logger) { SetLoggerWithOptions(logger) }
SetLogger sets a Logger implementation that will be used as backing implementation of the traditional klog log calls. klog will do its own verbosity checks before calling logger.V().Info. logger.Error is always called, regardless of the klog verbosity settings. If set, all log lines will be suppressed from the regular output, and redirected to the logr implementation. 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. Modifying the logger is not thread-safe and should be done while no other goroutines invoke log calls, usually during program initialization.
SetLogger
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/klog/v2/contextual.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/klog/v2/contextual.go
Apache-2.0
func SetLoggerWithOptions(logger logr.Logger, opts ...LoggerOption) { logging.loggerOptions = loggerOptions{} for _, opt := range opts { opt(&logging.loggerOptions) } logging.logger = &logWriter{ Logger: logger, writeKlogBuffer: logging.loggerOptions.writeKlogBuffer, } }
SetLoggerWithOptions is a more flexible version of SetLogger. Without additional options, it behaves exactly like SetLogger. By passing ContextualLogger(true) as option, it can be used to set a logger that then will also get called directly by applications which retrieve it via FromContext, Background, or TODO. Supporting direct calls is recommended because it avoids the overhead of routing log entries through klogr into klog and then into the actual Logger backend.
SetLoggerWithOptions
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/klog/v2/contextual.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/klog/v2/contextual.go
Apache-2.0
func ContextualLogger(enabled bool) LoggerOption { return func(o *loggerOptions) { o.contextualLogger = enabled } }
ContextualLogger determines whether the logger passed to SetLoggerWithOptions may also get called directly. Such a logger cannot rely on verbosity checking in klog.
ContextualLogger
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/klog/v2/contextual.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/klog/v2/contextual.go
Apache-2.0
func FlushLogger(flush func()) LoggerOption { return func(o *loggerOptions) { o.flush = flush } }
FlushLogger provides a callback for flushing data buffered by the logger.
FlushLogger
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/klog/v2/contextual.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/klog/v2/contextual.go
Apache-2.0
func WriteKlogBuffer(write func([]byte)) LoggerOption { return func(o *loggerOptions) { o.writeKlogBuffer = write } }
WriteKlogBuffer sets a callback that will be invoked by klog to write output produced by non-structured log calls like Infof. The buffer will contain exactly the same data that klog normally would write into its own output stream(s). In particular this includes the header, if klog is configured to write one. The callback then can divert that data into its own output streams. The buffer may or may not end in a line break. Without such a callback, klog will call the logger's Info or Error method with just the message string (i.e. no header).
WriteKlogBuffer
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/klog/v2/contextual.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/klog/v2/contextual.go
Apache-2.0
func ClearLogger() { logging.logger = nil logging.loggerOptions = loggerOptions{} }
ClearLogger removes a backing Logger implementation if one was set earlier with SetLogger. Modifying the logger is not thread-safe and should be done while no other goroutines invoke log calls, usually during program initialization.
ClearLogger
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/klog/v2/contextual.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/klog/v2/contextual.go
Apache-2.0
func EnableContextualLogging(enabled bool) { logging.contextualLoggingEnabled = enabled }
EnableContextualLogging controls whether contextual logging is enabled. By default it is enabled. When disabled, FromContext avoids looking up the logger in the context and always returns the global logger. LoggerWithValues, LoggerWithName, and NewContext become no-ops and return their input logger respectively context. This may be useful to avoid the additional overhead for contextual logging. This must be called during initialization before goroutines are started.
EnableContextualLogging
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/klog/v2/contextual.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/klog/v2/contextual.go
Apache-2.0
func FromContext(ctx context.Context) Logger { if logging.contextualLoggingEnabled { if logger, err := logr.FromContext(ctx); err == nil { return logger } } return Background() }
FromContext retrieves a logger set by the caller or, if not set, falls back to the program's global logger (a Logger instance or klog itself).
FromContext
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/klog/v2/contextual.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/klog/v2/contextual.go
Apache-2.0
func TODO() Logger { return Background() }
TODO can be used as a last resort by code that has no means of receiving a logger from its caller. FromContext or an explicit logger parameter should be used instead.
TODO
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/klog/v2/contextual.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/klog/v2/contextual.go
Apache-2.0
func Background() Logger { if logging.loggerOptions.contextualLogger { // Is non-nil because logging.loggerOptions.contextualLogger is // only true if a logger was set. return logging.logger.Logger } return klogLogger }
Background retrieves the fallback logger. It should not be called before that logger was initialized by the program and not by code that should better receive a logger via its parameters. TODO can be used as a temporary solution for such code.
Background
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/klog/v2/contextual.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/klog/v2/contextual.go
Apache-2.0
func LoggerWithValues(logger Logger, kv ...interface{}) Logger { if logging.contextualLoggingEnabled { return logger.WithValues(kv...) } return logger }
LoggerWithValues returns logger.WithValues(...kv) when contextual logging is enabled, otherwise the logger.
LoggerWithValues
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/klog/v2/contextual.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/klog/v2/contextual.go
Apache-2.0
func LoggerWithName(logger Logger, name string) Logger { if logging.contextualLoggingEnabled { return logger.WithName(name) } return logger }
LoggerWithName returns logger.WithName(name) when contextual logging is enabled, otherwise the logger.
LoggerWithName
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/klog/v2/contextual.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/klog/v2/contextual.go
Apache-2.0
func NewContext(ctx context.Context, logger Logger) context.Context { if logging.contextualLoggingEnabled { return logr.NewContext(ctx, logger) } return ctx }
NewContext returns logr.NewContext(ctx, logger) when contextual logging is enabled, otherwise ctx.
NewContext
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/klog/v2/contextual.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/klog/v2/contextual.go
Apache-2.0
func NewKlogr() Logger { return New(&klogger{}) }
NewKlogr returns a logger that is functionally identical to klogr.NewWithOptions(klogr.FormatKlog), i.e. it passes through to klog. The difference is that it uses a simpler implementation.
NewKlogr
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/klog/v2/klogr.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/klog/v2/klogr.go
Apache-2.0
func (l klogger) WithName(name string) logr.LogSink { if l.hasPrefix { // Copy slice and modify value. No length checks and type // assertions are needed because hasPrefix is only true if the // first two elements exist and are key/value strings. v := make([]interface{}, 0, len(l.values)) v = append(v, l.values...) prefix, _ := v[1].(string) v[1] = prefix + "." + name l.values = v } else { // Preprend new key/value pair. v := make([]interface{}, 0, 2+len(l.values)) v = append(v, nameKey, name) v = append(v, l.values...) l.values = v l.hasPrefix = true } return &l }
WithName returns a new logr.Logger with the specified name appended. klogr uses '.' characters to separate name elements. Callers should not pass '.' in the provided name string, but this library does not actually enforce that.
WithName
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/klog/v2/klogr.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/klog/v2/klogr.go
Apache-2.0
func slogOutput(file string, line int, now time.Time, err error, s severity.Severity, msg string, kvList []interface{}) { // See infoS. if logging.logger != nil { // Taking this path happens when klog has a logger installed // as backend which doesn't support slog. Not good, we have to // guess about the call depth and drop the actual location. logger := logging.logger.WithCallDepth(2) if s > severity.ErrorLog { logger.Error(err, msg, kvList...) } else { logger.Info(msg, kvList...) } return } // See printS. b := buffer.GetBuffer() b.WriteString(strconv.Quote(msg)) if err != nil { serialize.KVListFormat(&b.Buffer, "err", err) } serialize.KVListFormat(&b.Buffer, kvList...) // See print + header. buf := logging.formatHeader(s, file, line, now) logging.printWithInfos(buf, file, line, s, nil, nil, 0, &b.Buffer) buffer.PutBuffer(b) }
slogOutput corresponds to several different functions in klog.go. It goes through some of the same checks and formatting steps before it ultimately converges by calling logging.printWithInfos.
slogOutput
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/klog/v2/klogr_slog.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/klog/v2/klogr_slog.go
Apache-2.0
func shortHostname(hostname string) string { if i := strings.Index(hostname, "."); i >= 0 { return hostname[:i] } return hostname }
shortHostname returns its argument, truncating at the first period. For instance, given "www.google.com" it returns "www".
shortHostname
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/klog/v2/klog_file.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/klog/v2/klog_file.go
Apache-2.0
func logName(tag string, t time.Time) (name, link string) { name = fmt.Sprintf("%s.%s.%s.log.%s.%04d%02d%02d-%02d%02d%02d.%d", program, host, getUserName(), tag, t.Year(), t.Month(), t.Day(), t.Hour(), t.Minute(), t.Second(), pid) return name, program + "." + tag }
logName returns a new log file name containing tag, with start time t, and the name for the symlink for tag.
logName
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/klog/v2/klog_file.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/klog/v2/klog_file.go
Apache-2.0
func create(tag string, t time.Time, startup bool) (f *os.File, filename string, err error) { if logging.logFile != "" { f, err := openOrCreate(logging.logFile, startup) 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") } name, link := logName(tag, t) var lastErr error for _, dir := range logDirs { fname := filepath.Join(dir, name) f, err := openOrCreate(fname, startup) if err == nil { symlink := filepath.Join(dir, link) _ = os.Remove(symlink) // ignore err _ = os.Symlink(name, symlink) // ignore err return f, fname, nil } lastErr = err } return nil, "", fmt.Errorf("log: cannot create log: %v", lastErr) }
create creates a new log file and returns the file and its filename, which contains tag ("INFO", "FATAL", etc.) and t. If the file is created successfully, create also attempts to update the symlink for that tag, ignoring errors. The startup argument indicates whether this is the initial startup of klog. If startup is true, existing files are opened for appending instead of truncated.
create
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/klog/v2/klog_file.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/klog/v2/klog_file.go
Apache-2.0
func openOrCreate(name string, startup bool) (*os.File, error) { if startup { f, err := os.OpenFile(name, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666) return f, err } f, err := os.Create(name) return f, err }
The startup argument indicates whether this is the initial startup of klog. If startup is true, existing files are opened for appending instead of truncated.
openOrCreate
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/klog/v2/klog_file.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/klog/v2/klog_file.go
Apache-2.0
func FlushAndExit(flushTimeout time.Duration, exitCode int) { timeoutFlush(flushTimeout) OsExit(exitCode) }
FlushAndExit flushes log data for a certain amount of time and then calls os.Exit. Combined with some logging call it provides a replacement for traditional calls like Fatal or Exit.
FlushAndExit
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/klog/v2/exit.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/klog/v2/exit.go
Apache-2.0
func timeoutFlush(timeout time.Duration) { done := make(chan bool, 1) go func() { Flush() // calls logging.lockAndFlushAll() done <- true }() select { case <-done: case <-time.After(timeout): fmt.Fprintln(os.Stderr, "klog: Flush took longer than", timeout) } }
timeoutFlush calls Flush and returns when it completes or after timeout elapses, whichever happens first. This is needed because the hooks invoked by Flush may deadlock when klog.Fatal is called from a hook that holds a lock. Flushing also might take too long.
timeoutFlush
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/klog/v2/exit.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/klog/v2/exit.go
Apache-2.0
func (RealClock) Now() time.Time { return time.Now() }
Now returns the current time.
Now
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/klog/v2/internal/clock/clock.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/klog/v2/internal/clock/clock.go
Apache-2.0
func (RealClock) Since(ts time.Time) time.Duration { return time.Since(ts) }
Since returns time since the specified timestamp.
Since
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/klog/v2/internal/clock/clock.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/klog/v2/internal/clock/clock.go
Apache-2.0
func (RealClock) After(d time.Duration) <-chan time.Time { return time.After(d) }
After is the same as time.After(d). This method does not allow to free/GC the backing timer before it fires. Use NewTimer instead.
After
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/klog/v2/internal/clock/clock.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/klog/v2/internal/clock/clock.go
Apache-2.0
func (RealClock) NewTimer(d time.Duration) Timer { return &realTimer{ timer: time.NewTimer(d), } }
NewTimer is the same as time.NewTimer(d)
NewTimer
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/klog/v2/internal/clock/clock.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/klog/v2/internal/clock/clock.go
Apache-2.0
func (RealClock) AfterFunc(d time.Duration, f func()) Timer { return &realTimer{ timer: time.AfterFunc(d, f), } }
AfterFunc is the same as time.AfterFunc(d, f).
AfterFunc
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/klog/v2/internal/clock/clock.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/klog/v2/internal/clock/clock.go
Apache-2.0
func (RealClock) NewTicker(d time.Duration) Ticker { return &realTicker{ ticker: time.NewTicker(d), } }
NewTicker returns a new Ticker.
NewTicker
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/klog/v2/internal/clock/clock.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/klog/v2/internal/clock/clock.go
Apache-2.0
func (RealClock) Sleep(d time.Duration) { time.Sleep(d) }
Sleep is the same as time.Sleep(d) Consider making the sleep interruptible by using 'select' on a context channel and a timer channel.
Sleep
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/klog/v2/internal/clock/clock.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/klog/v2/internal/clock/clock.go
Apache-2.0
func (r *realTimer) C() <-chan time.Time { return r.timer.C }
C returns the underlying timer's channel.
C
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/klog/v2/internal/clock/clock.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/klog/v2/internal/clock/clock.go
Apache-2.0
func (r *realTimer) Stop() bool { return r.timer.Stop() }
Stop calls Stop() on the underlying timer.
Stop
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/klog/v2/internal/clock/clock.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/klog/v2/internal/clock/clock.go
Apache-2.0
func (r *realTimer) Reset(d time.Duration) bool { return r.timer.Reset(d) }
Reset calls Reset() on the underlying timer.
Reset
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/klog/v2/internal/clock/clock.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/klog/v2/internal/clock/clock.go
Apache-2.0
func (f Formatter) KVFormat(b *bytes.Buffer, k, v interface{}) { // This is the version without slog support. Must be kept in sync with // the version in keyvalues_slog.go. b.WriteByte(' ') // Keys are assumed to be well-formed according to // https://github.com/kubernetes/community/blob/master/contributors/devel/sig-instrumentation/migration-to-structured-logging.md#name-arguments // for the sake of performance. Keys with spaces, // special characters, etc. will break parsing. if sK, ok := k.(string); ok { // Avoid one allocation when the key is a string, which // normally it should be. b.WriteString(sK) } else { b.WriteString(fmt.Sprintf("%s", k)) } // The type checks are sorted so that more frequently used ones // come first because that is then faster in the common // cases. In Kubernetes, ObjectRef (a Stringer) is more common // than plain strings // (https://github.com/kubernetes/kubernetes/pull/106594#issuecomment-975526235). switch v := v.(type) { case textWriter: writeTextWriterValue(b, v) case fmt.Stringer: writeStringValue(b, StringerToString(v)) case string: writeStringValue(b, v) case error: writeStringValue(b, ErrorToString(v)) case logr.Marshaler: value := MarshalerToValue(v) // A marshaler that returns a string is useful for // delayed formatting of complex values. We treat this // case like a normal string. This is useful for // multi-line support. // // We could do this by recursively formatting a value, // but that comes with the risk of infinite recursion // if a marshaler returns itself. Instead we call it // only once and rely on it returning the intended // value directly. switch value := value.(type) { case string: writeStringValue(b, value) default: f.formatAny(b, value) }
KVFormat serializes one key/value pair into the provided buffer. A space gets inserted before the pair.
KVFormat
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/klog/v2/internal/serialize/keyvalues_no_slog.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/klog/v2/internal/serialize/keyvalues_no_slog.go
Apache-2.0
func (f Formatter) KVFormat(b *bytes.Buffer, k, v interface{}) { // This is the version without slog support. Must be kept in sync with // the version in keyvalues_slog.go. b.WriteByte(' ') // Keys are assumed to be well-formed according to // https://github.com/kubernetes/community/blob/master/contributors/devel/sig-instrumentation/migration-to-structured-logging.md#name-arguments // for the sake of performance. Keys with spaces, // special characters, etc. will break parsing. if sK, ok := k.(string); ok { // Avoid one allocation when the key is a string, which // normally it should be. b.WriteString(sK) } else { b.WriteString(fmt.Sprintf("%s", k)) } // The type checks are sorted so that more frequently used ones // come first because that is then faster in the common // cases. In Kubernetes, ObjectRef (a Stringer) is more common // than plain strings // (https://github.com/kubernetes/kubernetes/pull/106594#issuecomment-975526235). // // slog.LogValuer does not need to be handled here because the handler will // already have resolved such special values to the final value for logging. switch v := v.(type) { case textWriter: writeTextWriterValue(b, v) case slog.Value: // This must come before fmt.Stringer because slog.Value implements // fmt.Stringer, but does not produce the output that we want. b.WriteByte('=') generateJSON(b, v) case fmt.Stringer: writeStringValue(b, StringerToString(v)) case string: writeStringValue(b, v) case error: writeStringValue(b, ErrorToString(v)) case logr.Marshaler: value := MarshalerToValue(v) // A marshaler that returns a string is useful for // delayed formatting of complex values. We treat this // case like a normal string. This is useful for // multi-line support. // // We could do this by recursively formatting a value, // but that comes with the risk of infinite recursion // if a marshaler returns itself. Instead we call it // only once and rely on it returning the intended // value directly. switch value := value.(type) { case string: writeStringValue(b, value) default: f.formatAny(b, value) }
KVFormat serializes one key/value pair into the provided buffer. A space gets inserted before the pair.
KVFormat
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/klog/v2/internal/serialize/keyvalues_slog.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/klog/v2/internal/serialize/keyvalues_slog.go
Apache-2.0
func generateJSON(b *bytes.Buffer, v interface{}) { switch v := v.(type) { case slog.Value: switch v.Kind() { case slog.KindGroup: // Format as a JSON group. We must not involve f.AnyToStringHook (if there is any), // because there is no guarantee that it produces valid JSON. b.WriteByte('{') for i, attr := range v.Group() { if i > 0 { b.WriteByte(',') } b.WriteString(strconv.Quote(attr.Key)) b.WriteByte(':') generateJSON(b, attr.Value) } b.WriteByte('}') case slog.KindLogValuer: generateJSON(b, v.Resolve()) default: // Peel off the slog.Value wrapper and format the actual value. generateJSON(b, v.Any()) } case fmt.Stringer: b.WriteString(strconv.Quote(StringerToString(v))) case logr.Marshaler: generateJSON(b, MarshalerToValue(v)) case slog.LogValuer: generateJSON(b, slog.AnyValue(v).Resolve().Any()) case string: b.WriteString(strconv.Quote(v)) case error: b.WriteString(strconv.Quote(v.Error())) default: formatAsJSON(b, v) }
generateJSON has the same preference for plain strings as KVFormat. In contrast to KVFormat it always produces valid JSON with no line breaks.
generateJSON
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/klog/v2/internal/serialize/keyvalues_slog.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/klog/v2/internal/serialize/keyvalues_slog.go
Apache-2.0
func WithValues(oldKV, newKV []interface{}) []interface{} { if len(newKV) == 0 { return oldKV } newLen := len(oldKV) + len(newKV) hasMissingValue := newLen%2 != 0 if hasMissingValue { newLen++ } // The new LogSink must have its own slice. kv := make([]interface{}, 0, newLen) kv = append(kv, oldKV...) kv = append(kv, newKV...) if hasMissingValue { kv = append(kv, missingValue) } return kv }
WithValues implements LogSink.WithValues. The old key/value pairs are assumed to be well-formed, the new ones are checked and padded if necessary. It returns a new slice.
WithValues
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/klog/v2/internal/serialize/keyvalues.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/klog/v2/internal/serialize/keyvalues.go
Apache-2.0
func MergeKVs(first, second []interface{}) []interface{} { maxLength := len(first) + (len(second)+1)/2*2 if maxLength == 0 { // Nothing to do at all. return nil } if len(first) == 0 && len(second)%2 == 0 { // Nothing to be overridden, second slice is well-formed // and can be used directly. return second } // Determine which keys are in the second slice so that we can skip // them when iterating over the first one. The code intentionally // favors performance over completeness: we assume that keys are string // constants and thus compare equal when the string values are equal. A // string constant being overridden by, for example, a fmt.Stringer is // not handled. overrides := map[interface{}]bool{} for i := 0; i < len(second); i += 2 { overrides[second[i]] = true } merged := make([]interface{}, 0, maxLength) for i := 0; i+1 < len(first); i += 2 { key := first[i] if overrides[key] { continue } merged = append(merged, key, first[i+1]) } merged = append(merged, second...) if len(merged)%2 != 0 { merged = append(merged, missingValue) } return merged }
MergeKVs deduplicates elements provided in two key/value slices. Keys in each slice are expected to be unique, so duplicates can only occur when the first and second slice contain the same key. When that happens, the key/value pair from the second slice is used. The first slice must be well-formed (= even key/value pairs). The second one may have a missing value, in which case the special "missing value" is added to the result.
MergeKVs
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/klog/v2/internal/serialize/keyvalues.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/klog/v2/internal/serialize/keyvalues.go
Apache-2.0
func (f Formatter) MergeAndFormatKVs(b *bytes.Buffer, first, second []interface{}) { if len(first) == 0 && len(second) == 0 { // Nothing to do at all. return } if len(first) == 0 && len(second)%2 == 0 { // Nothing to be overridden, second slice is well-formed // and can be used directly. for i := 0; i < len(second); i += 2 { f.KVFormat(b, second[i], second[i+1]) } return } // Determine which keys are in the second slice so that we can skip // them when iterating over the first one. The code intentionally // favors performance over completeness: we assume that keys are string // constants and thus compare equal when the string values are equal. A // string constant being overridden by, for example, a fmt.Stringer is // not handled. overrides := map[interface{}]bool{} for i := 0; i < len(second); i += 2 { overrides[second[i]] = true } for i := 0; i < len(first); i += 2 { key := first[i] if overrides[key] { continue } f.KVFormat(b, key, first[i+1]) } // Round down. l := len(second) l = l / 2 * 2 for i := 1; i < l; i += 2 { f.KVFormat(b, second[i-1], second[i]) } if len(second)%2 == 1 { f.KVFormat(b, second[len(second)-1], missingValue) } }
MergeKVsInto is a variant of MergeKVs which directly formats the key/value pairs into a buffer.
MergeAndFormatKVs
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/klog/v2/internal/serialize/keyvalues.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/klog/v2/internal/serialize/keyvalues.go
Apache-2.0
func (f Formatter) KVListFormat(b *bytes.Buffer, keysAndValues ...interface{}) { for i := 0; i < len(keysAndValues); i += 2 { var v interface{} k := keysAndValues[i] if i+1 < len(keysAndValues) { v = keysAndValues[i+1] } else { v = missingValue } f.KVFormat(b, k, v) } }
KVListFormat serializes all key/value pairs into the provided buffer. A space gets inserted before the first pair and between each pair.
KVListFormat
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/klog/v2/internal/serialize/keyvalues.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/klog/v2/internal/serialize/keyvalues.go
Apache-2.0
func (f Formatter) formatAny(b *bytes.Buffer, v interface{}) { b.WriteRune('=') if f.AnyToStringHook != nil { b.WriteString(f.AnyToStringHook(v)) return } formatAsJSON(b, v) }
formatAny is the fallback formatter for a value. It supports a hook (for example, for YAML encoding) and itself uses JSON encoding.
formatAny
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/klog/v2/internal/serialize/keyvalues.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/klog/v2/internal/serialize/keyvalues.go
Apache-2.0
func StringerToString(s fmt.Stringer) (ret string) { defer func() { if err := recover(); err != nil { ret = fmt.Sprintf("<panic: %s>", err) } }() ret = s.String() return }
StringerToString converts a Stringer to a string, handling panics if they occur.
StringerToString
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/klog/v2/internal/serialize/keyvalues.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/klog/v2/internal/serialize/keyvalues.go
Apache-2.0
func MarshalerToValue(m logr.Marshaler) (ret interface{}) { defer func() { if err := recover(); err != nil { ret = fmt.Sprintf("<panic: %s>", err) } }() ret = m.MarshalLog() return }
MarshalerToValue invokes a marshaler and catches panics.
MarshalerToValue
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/klog/v2/internal/serialize/keyvalues.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/klog/v2/internal/serialize/keyvalues.go
Apache-2.0
func ErrorToString(err error) (ret string) { defer func() { if err := recover(); err != nil { ret = fmt.Sprintf("<panic: %s>", err) } }() ret = err.Error() return }
ErrorToString converts an error to a string, handling panics if they occur.
ErrorToString
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/klog/v2/internal/serialize/keyvalues.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/klog/v2/internal/serialize/keyvalues.go
Apache-2.0
func ByName(s string) (Severity, bool) { s = strings.ToUpper(s) for i, name := range Name { if name == s { return Severity(i), true } } return 0, false }
ByName looks up a severity level by name.
ByName
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/klog/v2/internal/severity/severity.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/klog/v2/internal/severity/severity.go
Apache-2.0
func GetBuffer() *Buffer { b := buffers.Get().(*Buffer) b.Reset() return b }
GetBuffer returns a new, ready-to-use buffer.
GetBuffer
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/klog/v2/internal/buffer/buffer.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/klog/v2/internal/buffer/buffer.go
Apache-2.0
func PutBuffer(b *Buffer) { if b.Len() >= 256 { // Let big buffers die a natural death, without relying on // sync.Pool behavior. The documentation implies that items may // get deallocated while stored there ("If the Pool holds the // only reference when this [= be removed automatically] // happens, the item might be deallocated."), but // https://github.com/golang/go/issues/23199 leans more towards // having such a size limit. return } buffers.Put(b) }
PutBuffer returns a buffer to the free list.
PutBuffer
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/klog/v2/internal/buffer/buffer.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/klog/v2/internal/buffer/buffer.go
Apache-2.0
func Stacks(all bool) []byte { // We don't know how big the traces are, so grow a few times if they don't fit. Start large, though. n := 10000 if all { n = 100000 } var trace []byte for i := 0; i < 5; i++ { trace = make([]byte, n) nbytes := runtime.Stack(trace, all) if nbytes < len(trace) { return trace[:nbytes] } n *= 2 } return trace }
Stacks is a wrapper for runtime.Stack that attempts to recover the data for all goroutines or the calling one.
Stacks
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/klog/v2/internal/dbg/dbg.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/klog/v2/internal/dbg/dbg.go
Apache-2.0
func (RealClock) Now() time.Time { return time.Now() }
Now returns the current time.
Now
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/utils/clock/clock.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/utils/clock/clock.go
Apache-2.0
func (RealClock) Since(ts time.Time) time.Duration { return time.Since(ts) }
Since returns time since the specified timestamp.
Since
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/utils/clock/clock.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/utils/clock/clock.go
Apache-2.0
func (RealClock) After(d time.Duration) <-chan time.Time { return time.After(d) }
After is the same as time.After(d). This method does not allow to free/GC the backing timer before it fires. Use NewTimer instead.
After
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/utils/clock/clock.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/utils/clock/clock.go
Apache-2.0
func (RealClock) NewTimer(d time.Duration) Timer { return &realTimer{ timer: time.NewTimer(d), } }
NewTimer is the same as time.NewTimer(d)
NewTimer
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/utils/clock/clock.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/utils/clock/clock.go
Apache-2.0
func (RealClock) AfterFunc(d time.Duration, f func()) Timer { return &realTimer{ timer: time.AfterFunc(d, f), } }
AfterFunc is the same as time.AfterFunc(d, f).
AfterFunc
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/utils/clock/clock.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/utils/clock/clock.go
Apache-2.0
func (RealClock) Tick(d time.Duration) <-chan time.Time { return time.Tick(d) }
Tick is the same as time.Tick(d) This method does not allow to free/GC the backing ticker. Use NewTicker instead.
Tick
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/utils/clock/clock.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/utils/clock/clock.go
Apache-2.0
func (RealClock) NewTicker(d time.Duration) Ticker { return &realTicker{ ticker: time.NewTicker(d), } }
NewTicker returns a new Ticker.
NewTicker
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/utils/clock/clock.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/utils/clock/clock.go
Apache-2.0
func (RealClock) Sleep(d time.Duration) { time.Sleep(d) }
Sleep is the same as time.Sleep(d) Consider making the sleep interruptible by using 'select' on a context channel and a timer channel.
Sleep
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/utils/clock/clock.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/utils/clock/clock.go
Apache-2.0
func (r *realTimer) C() <-chan time.Time { return r.timer.C }
C returns the underlying timer's channel.
C
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/utils/clock/clock.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/utils/clock/clock.go
Apache-2.0
func (r *realTimer) Stop() bool { return r.timer.Stop() }
Stop calls Stop() on the underlying timer.
Stop
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/utils/clock/clock.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/utils/clock/clock.go
Apache-2.0
func (r *realTimer) Reset(d time.Duration) bool { return r.timer.Reset(d) }
Reset calls Reset() on the underlying timer.
Reset
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/utils/clock/clock.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/utils/clock/clock.go
Apache-2.0
func NewFakePassiveClock(t time.Time) *FakePassiveClock { return &FakePassiveClock{ time: t, } }
NewFakePassiveClock returns a new FakePassiveClock.
NewFakePassiveClock
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/utils/clock/testing/fake_clock.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/utils/clock/testing/fake_clock.go
Apache-2.0
func NewFakeClock(t time.Time) *FakeClock { return &FakeClock{ FakePassiveClock: *NewFakePassiveClock(t), } }
NewFakeClock constructs a fake clock set to the provided time.
NewFakeClock
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/utils/clock/testing/fake_clock.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/utils/clock/testing/fake_clock.go
Apache-2.0
func (f *FakePassiveClock) Now() time.Time { f.lock.RLock() defer f.lock.RUnlock() return f.time }
Now returns f's time.
Now
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/utils/clock/testing/fake_clock.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/utils/clock/testing/fake_clock.go
Apache-2.0
func (f *FakePassiveClock) Since(ts time.Time) time.Duration { f.lock.RLock() defer f.lock.RUnlock() return f.time.Sub(ts) }
Since returns time since the time in f.
Since
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/utils/clock/testing/fake_clock.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/utils/clock/testing/fake_clock.go
Apache-2.0
func (f *FakePassiveClock) SetTime(t time.Time) { f.lock.Lock() defer f.lock.Unlock() f.time = t }
SetTime sets the time on the FakePassiveClock.
SetTime
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/utils/clock/testing/fake_clock.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/utils/clock/testing/fake_clock.go
Apache-2.0
func (f *FakeClock) After(d time.Duration) <-chan time.Time { f.lock.Lock() defer f.lock.Unlock() stopTime := f.time.Add(d) ch := make(chan time.Time, 1) // Don't block! f.waiters = append(f.waiters, &fakeClockWaiter{ targetTime: stopTime, destChan: ch, }) return ch }
After is the fake version of time.After(d).
After
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/utils/clock/testing/fake_clock.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/utils/clock/testing/fake_clock.go
Apache-2.0
func (f *FakeClock) NewTimer(d time.Duration) clock.Timer { f.lock.Lock() defer f.lock.Unlock() stopTime := f.time.Add(d) ch := make(chan time.Time, 1) // Don't block! timer := &fakeTimer{ fakeClock: f, waiter: fakeClockWaiter{ targetTime: stopTime, destChan: ch, }, } f.waiters = append(f.waiters, &timer.waiter) return timer }
NewTimer constructs a fake timer, akin to time.NewTimer(d).
NewTimer
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/utils/clock/testing/fake_clock.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/utils/clock/testing/fake_clock.go
Apache-2.0
func (f *FakeClock) AfterFunc(d time.Duration, cb func()) clock.Timer { f.lock.Lock() defer f.lock.Unlock() stopTime := f.time.Add(d) ch := make(chan time.Time, 1) // Don't block! timer := &fakeTimer{ fakeClock: f, waiter: fakeClockWaiter{ targetTime: stopTime, destChan: ch, afterFunc: cb, }, } f.waiters = append(f.waiters, &timer.waiter) return timer }
AfterFunc is the Fake version of time.AfterFunc(d, cb).
AfterFunc
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/utils/clock/testing/fake_clock.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/utils/clock/testing/fake_clock.go
Apache-2.0
func (f *FakeClock) Tick(d time.Duration) <-chan time.Time { if d <= 0 { return nil } f.lock.Lock() defer f.lock.Unlock() tickTime := f.time.Add(d) ch := make(chan time.Time, 1) // hold one tick f.waiters = append(f.waiters, &fakeClockWaiter{ targetTime: tickTime, stepInterval: d, skipIfBlocked: true, destChan: ch, }) return ch }
Tick constructs a fake ticker, akin to time.Tick
Tick
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/utils/clock/testing/fake_clock.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/utils/clock/testing/fake_clock.go
Apache-2.0
func (f *FakeClock) NewTicker(d time.Duration) clock.Ticker { f.lock.Lock() defer f.lock.Unlock() tickTime := f.time.Add(d) ch := make(chan time.Time, 1) // hold one tick f.waiters = append(f.waiters, &fakeClockWaiter{ targetTime: tickTime, stepInterval: d, skipIfBlocked: true, destChan: ch, }) return &fakeTicker{ c: ch, } }
NewTicker returns a new Ticker.
NewTicker
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/utils/clock/testing/fake_clock.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/utils/clock/testing/fake_clock.go
Apache-2.0
func (f *FakeClock) Step(d time.Duration) { f.lock.Lock() defer f.lock.Unlock() f.setTimeLocked(f.time.Add(d)) }
Step moves the clock by Duration and notifies anyone that's called After, Tick, or NewTimer.
Step
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/utils/clock/testing/fake_clock.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/utils/clock/testing/fake_clock.go
Apache-2.0
func (f *FakeClock) SetTime(t time.Time) { f.lock.Lock() defer f.lock.Unlock() f.setTimeLocked(t) }
SetTime sets the time.
SetTime
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/utils/clock/testing/fake_clock.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/utils/clock/testing/fake_clock.go
Apache-2.0
func (f *FakeClock) setTimeLocked(t time.Time) { f.time = t newWaiters := make([]*fakeClockWaiter, 0, len(f.waiters)) for i := range f.waiters { w := f.waiters[i] if !w.targetTime.After(t) { if w.skipIfBlocked { select { case w.destChan <- t: w.fired = true default: } } else { w.destChan <- t w.fired = true } if w.afterFunc != nil { w.afterFunc() } if w.stepInterval > 0 { for !w.targetTime.After(t) { w.targetTime = w.targetTime.Add(w.stepInterval) } newWaiters = append(newWaiters, w) } } else { newWaiters = append(newWaiters, f.waiters[i]) } } f.waiters = newWaiters }
Actually changes the time and checks any waiters. f must be write-locked.
setTimeLocked
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/utils/clock/testing/fake_clock.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/utils/clock/testing/fake_clock.go
Apache-2.0
func (f *FakeClock) HasWaiters() bool { f.lock.RLock() defer f.lock.RUnlock() return len(f.waiters) > 0 }
HasWaiters returns true if After or AfterFunc has been called on f but not yet satisfied (so you can write race-free tests).
HasWaiters
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/utils/clock/testing/fake_clock.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/utils/clock/testing/fake_clock.go
Apache-2.0
func (f *FakeClock) Sleep(d time.Duration) { f.Step(d) }
Sleep is akin to time.Sleep
Sleep
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/utils/clock/testing/fake_clock.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/utils/clock/testing/fake_clock.go
Apache-2.0
func (i *IntervalClock) Now() time.Time { i.Time = i.Time.Add(i.Duration) return i.Time }
Now returns i's time.
Now
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/utils/clock/testing/fake_clock.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/utils/clock/testing/fake_clock.go
Apache-2.0
func (i *IntervalClock) Since(ts time.Time) time.Duration { return i.Time.Sub(ts) }
Since returns time since the time in i.
Since
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/utils/clock/testing/fake_clock.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/utils/clock/testing/fake_clock.go
Apache-2.0
func (*IntervalClock) After(d time.Duration) <-chan time.Time { panic("IntervalClock doesn't implement After") }
After is unimplemented, will panic. TODO: make interval clock use FakeClock so this can be implemented.
After
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/utils/clock/testing/fake_clock.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/utils/clock/testing/fake_clock.go
Apache-2.0
func (*IntervalClock) NewTimer(d time.Duration) clock.Timer { panic("IntervalClock doesn't implement NewTimer") }
NewTimer is unimplemented, will panic. TODO: make interval clock use FakeClock so this can be implemented.
NewTimer
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/utils/clock/testing/fake_clock.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/utils/clock/testing/fake_clock.go
Apache-2.0
func (*IntervalClock) AfterFunc(d time.Duration, f func()) clock.Timer { panic("IntervalClock doesn't implement AfterFunc") }
AfterFunc is unimplemented, will panic. TODO: make interval clock use FakeClock so this can be implemented.
AfterFunc
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/utils/clock/testing/fake_clock.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/utils/clock/testing/fake_clock.go
Apache-2.0
func (*IntervalClock) Tick(d time.Duration) <-chan time.Time { panic("IntervalClock doesn't implement Tick") }
Tick is unimplemented, will panic. TODO: make interval clock use FakeClock so this can be implemented.
Tick
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/utils/clock/testing/fake_clock.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/utils/clock/testing/fake_clock.go
Apache-2.0
func (*IntervalClock) NewTicker(d time.Duration) clock.Ticker { panic("IntervalClock doesn't implement NewTicker") }
NewTicker has no implementation yet and is omitted. TODO: make interval clock use FakeClock so this can be implemented.
NewTicker
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/utils/clock/testing/fake_clock.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/utils/clock/testing/fake_clock.go
Apache-2.0
func (*IntervalClock) Sleep(d time.Duration) { panic("IntervalClock doesn't implement Sleep") }
Sleep is unimplemented, will panic.
Sleep
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/utils/clock/testing/fake_clock.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/utils/clock/testing/fake_clock.go
Apache-2.0
func (f *fakeTimer) C() <-chan time.Time { return f.waiter.destChan }
C returns the channel that notifies when this timer has fired.
C
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/utils/clock/testing/fake_clock.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/utils/clock/testing/fake_clock.go
Apache-2.0
func (f *fakeTimer) Stop() bool { f.fakeClock.lock.Lock() defer f.fakeClock.lock.Unlock() newWaiters := make([]*fakeClockWaiter, 0, len(f.fakeClock.waiters)) for i := range f.fakeClock.waiters { w := f.fakeClock.waiters[i] if w != &f.waiter { newWaiters = append(newWaiters, w) } } f.fakeClock.waiters = newWaiters return !f.waiter.fired }
Stop stops the timer and returns true if the timer has not yet fired, or false otherwise.
Stop
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/utils/clock/testing/fake_clock.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/utils/clock/testing/fake_clock.go
Apache-2.0
func (f *fakeTimer) Reset(d time.Duration) bool { f.fakeClock.lock.Lock() defer f.fakeClock.lock.Unlock() active := !f.waiter.fired f.waiter.fired = false f.waiter.targetTime = f.fakeClock.time.Add(d) var isWaiting bool for i := range f.fakeClock.waiters { w := f.fakeClock.waiters[i] if w == &f.waiter { isWaiting = true break } } if !isWaiting { f.fakeClock.waiters = append(f.fakeClock.waiters, &f.waiter) } return active }
Reset resets the timer to the fake clock's "now" + d. It returns true if the timer has not yet fired, or false otherwise.
Reset
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/utils/clock/testing/fake_clock.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/utils/clock/testing/fake_clock.go
Apache-2.0
func (i *SimpleIntervalClock) Now() time.Time { i.Time = i.Time.Add(i.Duration) return i.Time }
Now returns i's time.
Now
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/utils/clock/testing/simple_interval_clock.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/utils/clock/testing/simple_interval_clock.go
Apache-2.0
func (i *SimpleIntervalClock) Since(ts time.Time) time.Duration { return i.Time.Sub(ts) }
Since returns time since the time in i.
Since
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/utils/clock/testing/simple_interval_clock.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/utils/clock/testing/simple_interval_clock.go
Apache-2.0
func NewLocalPort(desc, ip string, ipFamily IPFamily, port int, protocol Protocol) (*LocalPort, error) { if protocol != TCP && protocol != UDP { return nil, fmt.Errorf("Unsupported protocol %s", protocol) } if ipFamily != IPFamilyUnknown && ipFamily != IPv4 && ipFamily != IPv6 { return nil, fmt.Errorf("Invalid IP family %s", ipFamily) } if ip != "" { parsedIP := ParseIPSloppy(ip) if parsedIP == nil { return nil, fmt.Errorf("invalid ip address %s", ip) } if ipFamily != IPFamilyUnknown { if IPFamily(parsedIP) != ipFamily { return nil, fmt.Errorf("ip address and family mismatch %s, %s", ip, ipFamily) } } } return &LocalPort{Description: desc, IP: ip, IPFamily: ipFamily, Port: port, Protocol: protocol}, nil }
NewLocalPort returns a LocalPort instance and ensures IPFamily and IP are consistent and that the given protocol is valid.
NewLocalPort
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/utils/net/port.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/utils/net/port.go
Apache-2.0
func (l *listenPortOpener) OpenLocalPort(lp *LocalPort) (Closeable, error) { return openLocalPort(lp) }
OpenLocalPort holds the given local port open.
OpenLocalPort
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/utils/net/port.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/utils/net/port.go
Apache-2.0
func IsDualStackIPs(ips []net.IP) (bool, error) { v4Found := false v6Found := false for i, ip := range ips { switch IPFamilyOf(ip) { case IPv4: v4Found = true case IPv6: v6Found = true default: return false, fmt.Errorf("invalid IP[%d]: %v", i, ip) } } return (v4Found && v6Found), nil }
IsDualStackIPs returns true if: - all elements of ips are valid - at least one IP from each family (v4 and v6) is present
IsDualStackIPs
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/utils/net/ipfamily.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/utils/net/ipfamily.go
Apache-2.0
func IsDualStackIPStrings(ips []string) (bool, error) { parsedIPs := make([]net.IP, 0, len(ips)) for i, ip := range ips { parsedIP := ParseIPSloppy(ip) if parsedIP == nil { return false, fmt.Errorf("invalid IP[%d]: %v", i, ip) } parsedIPs = append(parsedIPs, parsedIP) } return IsDualStackIPs(parsedIPs) }
IsDualStackIPStrings returns true if: - all elements of ips can be parsed as IPs - at least one IP from each family (v4 and v6) is present
IsDualStackIPStrings
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/utils/net/ipfamily.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/utils/net/ipfamily.go
Apache-2.0
func IsDualStackCIDRs(cidrs []*net.IPNet) (bool, error) { v4Found := false v6Found := false for i, cidr := range cidrs { switch IPFamilyOfCIDR(cidr) { case IPv4: v4Found = true case IPv6: v6Found = true default: return false, fmt.Errorf("invalid CIDR[%d]: %v", i, cidr) } } return (v4Found && v6Found), nil }
IsDualStackCIDRs returns true if: - all elements of cidrs are non-nil - at least one CIDR from each family (v4 and v6) is present
IsDualStackCIDRs
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/utils/net/ipfamily.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/utils/net/ipfamily.go
Apache-2.0