forked from derailed/k9s
-
Notifications
You must be signed in to change notification settings - Fork 0
/
helpers.go
36 lines (30 loc) · 941 Bytes
/
helpers.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package model
import (
"context"
"time"
"github.com/cenkalti/backoff"
"github.com/derailed/tview"
runewidth "github.com/mattn/go-runewidth"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
// MetaFQN returns a fully qualified resource name.
func MetaFQN(m metav1.ObjectMeta) string {
return FQN(m.Namespace, m.Name)
}
// FQN returns a fully qualified resource name.
func FQN(ns, n string) string {
if ns == "" {
return n
}
return ns + "/" + n
}
// Truncate a string to the given l and suffix ellipsis if needed.
func Truncate(str string, width int) string {
return runewidth.Truncate(str, width, string(tview.SemigraphicsHorizontalEllipsis))
}
// NewExpBackOff returns a new exponential backoff timer.
func NewExpBackOff(ctx context.Context, start, max time.Duration) backoff.BackOffContext {
bf := backoff.NewExponentialBackOff()
bf.InitialInterval, bf.MaxElapsedTime = start, max
return backoff.WithContext(bf, ctx)
}