Skip to content

Commit f245531

Browse files
authored
Merge pull request #9 from flyhope/1-show-pod-list-panic
add Terminated & Read State, fix panic
2 parents e37b378 + 38d41a1 commit f245531

File tree

2 files changed

+28
-11
lines changed

2 files changed

+28
-11
lines changed

view/container.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ func ShowContainer(podName string, lastModel tea.Model) (tea.Model, error) {
5858
m.Table = ui.NewTableWithData([]table.Column{
5959
{Title: "容器名称", Width: 0},
6060
{Title: "镜像地址", Width: 0},
61-
{Title: "状态", Width: 5},
61+
{Title: "状态", Width: 4},
6262
{Title: "就绪", Width: 4},
6363
}, nil)
6464
m.updateData(false)
@@ -118,10 +118,10 @@ func getBoolString(val bool) string {
118118
func getContainerState(status v1.ContainerStatus) string {
119119
if status.State.Waiting != nil {
120120
return "♾️"
121-
} else if status.State.Running != nil {
122-
return "✔️"
123121
} else if status.State.Terminated != nil {
124122
return "✴️"
123+
} else if status.State.Running != nil {
124+
return "✔️"
125125
}
126126
return "❓️"
127127
}

view/pod.go

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,15 @@ func (c *podModel) updateData(force bool) {
4040

4141
// 格式化时间输出
4242
timeStr := "-"
43-
startTime := pod.Status.StartTime
44-
if startTime == nil {
45-
timeStr = pod.Status.StartTime.Format(time.DateTime)
43+
if startTime := pod.Status.StartTime; startTime != nil {
44+
timeStr = startTime.Format(time.DateTime)
4645
}
4746

4847
rows = append(rows, table.Row{
4948
name,
5049
pod.Status.PodIP,
51-
PodPhaseView(pod.Status.Phase),
50+
PodPhaseView(pod),
51+
PodReadyView(pod),
5252
timeStr,
5353
})
5454
}
@@ -76,7 +76,8 @@ func ShowPod(app string, lastModel tea.Model) (tea.Model, error) {
7676
m.TableFilter.Table = ui.NewTableWithData([]table.Column{
7777
{Title: "名称", Width: 0},
7878
{Title: "IP", Width: 15},
79-
{Title: "状态", Width: 9},
79+
{Title: "状态", Width: 4},
80+
{Title: "就绪", Width: 4},
8081
{Title: "启动时间", Width: 19},
8182
}, nil)
8283
m.TableFilter.Focus()
@@ -135,13 +136,29 @@ var phaseAlias = map[v1.PodPhase]string{
135136
v1.PodSucceeded: "🔅",
136137
v1.PodFailed: "❌️",
137138
v1.PodUnknown: "❓️",
139+
"Terminating": "✴️",
138140
}
139141

140142
// PodPhaseView 友好显示POD状态
141-
func PodPhaseView(phaes v1.PodPhase) string {
142-
result := phaseAlias[phaes]
143+
func PodPhaseView(pod v1.Pod) string {
144+
phase := pod.Status.Phase
145+
if pod.DeletionTimestamp != nil {
146+
phase = "Terminating"
147+
}
148+
149+
result := phaseAlias[phase]
143150
if result == "" {
144-
result = string(phaes)
151+
result = string(phase)
145152
}
146153
return result
147154
}
155+
156+
// PodReadyView 友好显示POD的Ready状态
157+
func PodReadyView(pod v1.Pod) string {
158+
for _, condition := range pod.Status.Conditions {
159+
if condition.Type == v1.PodReady && condition.Status == v1.ConditionTrue {
160+
return "✔️"
161+
}
162+
}
163+
return "❌️"
164+
}

0 commit comments

Comments
 (0)