-
Notifications
You must be signed in to change notification settings - Fork 5
/
tools.go
61 lines (56 loc) · 1.32 KB
/
tools.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package configmap
import (
"time"
corev1 "k8s.io/api/core/v1"
)
// GetData get configmap data.
func (h *Handler) GetData(object interface{}) (map[string]string, error) {
switch val := object.(type) {
case string:
cm, err := h.Get(val)
if err != nil {
return nil, err
}
return cm.Data, nil
case *corev1.ConfigMap:
return val.Data, nil
case corev1.ConfigMap:
return val.Data, nil
default:
return nil, ErrInvalidToolsType
}
}
// NumData get the number of configmap data.
func (h *Handler) NumData(object interface{}) (int, error) {
switch val := object.(type) {
case string:
cm, err := h.Get(val)
if err != nil {
return 0, err
}
return len(cm.Data), nil
case *corev1.ConfigMap:
return len(val.Data), nil
case corev1.ConfigMap:
return len(val.Data), nil
default:
return 0, ErrInvalidToolsType
}
}
// GetAge returns configmap age.
func (h *Handler) GetAge(object interface{}) (time.Duration, error) {
switch val := object.(type) {
case string:
cm, err := h.Get(val)
if err != nil {
return time.Duration(0), err
}
return time.Now().Sub(cm.CreationTimestamp.Time), nil
case *corev1.ConfigMap:
return time.Now().Sub(val.CreationTimestamp.Time), nil
case corev1.ConfigMap:
return time.Now().Sub(val.CreationTimestamp.Time), nil
default:
return time.Duration(0), ErrInvalidToolsType
}
}