-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpod.go
More file actions
112 lines (102 loc) · 2.23 KB
/
pod.go
File metadata and controls
112 lines (102 loc) · 2.23 KB
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
package main
// NODEGROUP NODE NAMESPACE NAME READY STATUS RESTARTS AGE IP
// staging-spot ip-10-100-29-185.ec2.internal airflow airflow-db-migrations-696f99f8b5-j72q5 1/1 Running 0 23d 10.100.29.51
import (
"fmt"
corev1 "k8s.io/api/core/v1"
)
type Pod struct {
Nodegroup string
Node string
Namespace string
Name string
Ready string
Status string
Restarts string
Age string
IP string
Mem int64
Cpu int64
}
func PodIsReady(pod corev1.Pod) string {
running := 0
for _, item := range pod.Status.ContainerStatuses {
if item.Ready {
running = running + 1
}
}
return fmt.Sprintf("%d/%d", running, len(pod.Status.ContainerStatuses))
}
func GetContainerRestarts(pod corev1.Pod) string {
restarts := int32(0)
for _, item := range pod.Status.ContainerStatuses {
restarts = restarts + item.RestartCount
}
return fmt.Sprintf("%d", restarts)
}
func GetPodAge(pod corev1.Pod) string {
return "0" //fmt.Sprintf("%.fd", time.Since(pod.Status.StartTime.Time).Hours()/24)
}
func NewPod(pod corev1.Pod, nodegroup string) Pod {
return Pod{
Nodegroup: nodegroup,
Node: pod.Spec.NodeName,
Namespace: pod.Namespace,
Name: pod.Name,
Ready: PodIsReady(pod),
Status: fmt.Sprintf("%v", pod.Status.Phase),
Restarts: GetContainerRestarts(pod),
Age: GetPodAge(pod),
IP: pod.Status.PodIP,
Mem: 0,
Cpu: 0,
}
}
func (pod *Pod) String() []string {
return []string{
pod.Nodegroup,
pod.Node,
pod.Namespace,
pod.Name,
pod.Ready,
pod.Status,
pod.Restarts,
pod.Age,
pod.IP,
}
}
func (pod *Pod) UsageString() []string {
return []string{
pod.Nodegroup,
pod.Node,
pod.Namespace,
pod.Name,
fmt.Sprintf("%vm", pod.Cpu),
fmt.Sprintf("%vMi", pod.Mem),
}
}
func PodHeader() []string {
return []string{
"Nodegroup",
"Node",
"Namespace",
"Name",
"Ready",
"Status",
"Restarts",
"Age",
"IP",
"Cpu",
"Mem",
}
}
func PodUsageHeader() []string {
return []string{
"Nodegroup",
"Node",
"Namespace",
"Name",
"Cpu(Cores)",
"Mem(Bytes)",
}
}