summaryrefslogtreecommitdiff
path: root/vendor/k8s.io/apimachinery/pkg/util/runtime
diff options
context:
space:
mode:
authorValentin Rothberg <rothberg@redhat.com>2019-06-24 21:29:31 +0200
committerValentin Rothberg <rothberg@redhat.com>2019-06-24 21:29:31 +0200
commit2388222e98462fdbbe44f3e091b2b79d80956a9a (patch)
tree17078d861c20a3e48b19c750c6864c5f59248386 /vendor/k8s.io/apimachinery/pkg/util/runtime
parenta1a4a75abee2c381483a218e1660621ee416ef7c (diff)
downloadpodman-2388222e98462fdbbe44f3e091b2b79d80956a9a.tar.gz
podman-2388222e98462fdbbe44f3e091b2b79d80956a9a.tar.bz2
podman-2388222e98462fdbbe44f3e091b2b79d80956a9a.zip
update dependencies
Ran a `go get -u` and bumped K8s deps to 1.15.0. Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
Diffstat (limited to 'vendor/k8s.io/apimachinery/pkg/util/runtime')
-rw-r--r--vendor/k8s.io/apimachinery/pkg/util/runtime/runtime.go47
1 files changed, 24 insertions, 23 deletions
diff --git a/vendor/k8s.io/apimachinery/pkg/util/runtime/runtime.go b/vendor/k8s.io/apimachinery/pkg/util/runtime/runtime.go
index 1e7d3ce0b..3c886f46c 100644
--- a/vendor/k8s.io/apimachinery/pkg/util/runtime/runtime.go
+++ b/vendor/k8s.io/apimachinery/pkg/util/runtime/runtime.go
@@ -22,7 +22,7 @@ import (
"sync"
"time"
- "github.com/golang/glog"
+ "k8s.io/klog"
)
var (
@@ -62,27 +62,18 @@ func HandleCrash(additionalHandlers ...func(interface{})) {
// logPanic logs the caller tree when a panic occurs.
func logPanic(r interface{}) {
- callers := getCallers(r)
+ // Same as stdlib http server code. Manually allocate stack trace buffer size
+ // to prevent excessively large logs
+ const size = 64 << 10
+ stacktrace := make([]byte, size)
+ stacktrace = stacktrace[:runtime.Stack(stacktrace, false)]
if _, ok := r.(string); ok {
- glog.Errorf("Observed a panic: %s\n%v", r, callers)
+ klog.Errorf("Observed a panic: %s\n%s", r, stacktrace)
} else {
- glog.Errorf("Observed a panic: %#v (%v)\n%v", r, r, callers)
+ klog.Errorf("Observed a panic: %#v (%v)\n%s", r, r, stacktrace)
}
}
-func getCallers(r interface{}) string {
- callers := ""
- for i := 0; true; i++ {
- _, file, line, ok := runtime.Caller(i)
- if !ok {
- break
- }
- callers = callers + fmt.Sprintf("%v:%v\n", file, line)
- }
-
- return callers
-}
-
// ErrorHandlers is a list of functions which will be invoked when an unreturnable
// error occurs.
// TODO(lavalamp): for testability, this and the below HandleError function
@@ -115,7 +106,7 @@ func HandleError(err error) {
// logError prints an error with the call stack of the location it was reported
func logError(err error) {
- glog.ErrorDepth(2, err)
+ klog.ErrorDepth(2, err)
}
type rudimentaryErrorBackoff struct {
@@ -132,9 +123,8 @@ func (r *rudimentaryErrorBackoff) OnError(error) {
r.lastErrorTimeLock.Lock()
defer r.lastErrorTimeLock.Unlock()
d := time.Since(r.lastErrorTime)
- if d < r.minPeriod && d >= 0 {
+ if d < r.minPeriod {
// If the time moves backwards for any reason, do nothing
- // TODO: remove check "d >= 0" after go 1.8 is no longer supported
time.Sleep(r.minPeriod - d)
}
r.lastErrorTime = time.Now()
@@ -156,12 +146,23 @@ func GetCaller() string {
// handlers to handle errors and panics the same way.
func RecoverFromPanic(err *error) {
if r := recover(); r != nil {
- callers := getCallers(r)
+ // Same as stdlib http server code. Manually allocate stack trace buffer size
+ // to prevent excessively large logs
+ const size = 64 << 10
+ stacktrace := make([]byte, size)
+ stacktrace = stacktrace[:runtime.Stack(stacktrace, false)]
*err = fmt.Errorf(
- "recovered from panic %q. (err=%v) Call stack:\n%v",
+ "recovered from panic %q. (err=%v) Call stack:\n%s",
r,
*err,
- callers)
+ stacktrace)
+ }
+}
+
+// Must panics on non-nil errors. Useful to handling programmer level errors.
+func Must(err error) {
+ if err != nil {
+ panic(err)
}
}