-
Notifications
You must be signed in to change notification settings - Fork 1
/
pod.go
53 lines (44 loc) · 1.25 KB
/
pod.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
package k8s
import (
"strings"
"time"
"github.com/filipecaixeta/logviewer/internal/source"
v1 "k8s.io/api/core/v1"
)
type Pod struct {
Name string `json:"name"`
UID string `json:"uid"`
Labels map[string]string `json:"-"`
CreationTimestamp time.Time `json:"creationTimestamp"`
Namespace string `json:"namespace"`
Status string `json:"status"`
Containers []*Container `json:"containers"`
}
func (n *Pod) Children() []source.ListItem {
return source.Convert2ListItems(n.Containers)
}
func (n *Pod) String() string {
return n.Name
}
func (n *Pod) FilterValue() string {
return n.Name
}
func NewPod(pod v1.Pod) *Pod {
containers := make([]*Container, len(pod.Spec.Containers))
for i, c := range pod.Spec.Containers {
containers[i] = &Container{
Name: c.Name,
Image: c.Image,
ImageTag: c.Image[strings.Index(c.Image, ":")+1:],
}
}
return &Pod{
Name: pod.Name,
UID: string(pod.UID),
Labels: pod.Labels,
CreationTimestamp: pod.CreationTimestamp.Time,
Namespace: pod.Namespace,
Status: string(pod.Status.Phase),
Containers: containers,
}
}