-
Notifications
You must be signed in to change notification settings - Fork 0
/
meta.go
94 lines (75 loc) · 2.03 KB
/
meta.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
package kubernetes
import (
"time"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"github.com/weaveworks/scope/report"
)
// These constants are keys used in node metadata
const (
Name = report.KubernetesName
Namespace = report.KubernetesNamespace
Created = report.KubernetesCreated
LabelPrefix = "kubernetes_labels_"
VolumeClaimName = report.KubernetesVolumeClaim
)
// Meta represents a metadata information about a Kubernetes object
type Meta interface {
UID() string
Name() string
Namespace() string
Created() string
Labels() map[string]string
MetaNode(id string) report.Node
}
type meta struct {
ObjectMeta metav1.ObjectMeta
}
func (m meta) UID() string {
return string(m.ObjectMeta.UID)
}
func (m meta) Name() string {
return m.ObjectMeta.Name
}
func (m meta) Namespace() string {
return m.ObjectMeta.Namespace
}
func (m meta) Created() string {
return m.ObjectMeta.CreationTimestamp.Format(time.RFC3339Nano)
}
func (m meta) Labels() map[string]string {
return m.ObjectMeta.Labels
}
// MetaNode gets the node metadata
func (m meta) MetaNode(id string) report.Node {
return report.MakeNodeWith(id, map[string]string{
Name: m.Name(),
Namespace: m.Namespace(),
Created: m.Created(),
}).AddPrefixPropertyList(LabelPrefix, m.Labels())
}
type namespaceMeta struct {
ObjectMeta metav1.ObjectMeta
}
func (m namespaceMeta) UID() string {
return string(m.ObjectMeta.UID)
}
func (m namespaceMeta) Name() string {
return m.ObjectMeta.Name
}
func (m namespaceMeta) Namespace() string {
return m.ObjectMeta.Namespace
}
func (m namespaceMeta) Created() string {
return m.ObjectMeta.CreationTimestamp.Format(time.RFC3339Nano)
}
func (m namespaceMeta) Labels() map[string]string {
return m.ObjectMeta.Labels
}
// MetaNode gets the node metadata
// For namespaces, ObjectMeta.Namespace is not set
func (m namespaceMeta) MetaNode(id string) report.Node {
return report.MakeNodeWith(id, map[string]string{
Name: m.Name(),
Created: m.Created(),
}).AddPrefixPropertyList(LabelPrefix, m.Labels())
}