11package view
22
33import (
4- "bytes"
54 "fmt"
65 "github.com/charmbracelet/bubbles/table"
76 tea "github.com/charmbracelet/bubbletea"
87 "github.com/flyhope/kubetea/comm"
98 "github.com/flyhope/kubetea/k8s"
109 "github.com/flyhope/kubetea/ui"
1110 "github.com/sirupsen/logrus"
12- "html/template"
1311 v1 "k8s.io/api/core/v1"
1412 "sort"
1513 "time"
@@ -19,8 +17,7 @@ import (
1917type podModel struct {
2018 ui.Abstract
2119 * ui.TableFilter
22- app string
23- templates []* template.Template
20+ app string
2421}
2522
2623// 更新数据
@@ -31,39 +28,16 @@ func (c *podModel) updateData(force bool) {
3128 return
3229 }
3330
34- rows := make ([]table.Row , 0 )
31+ rows := make ([]table.Row , 0 , len ( pods . Items ) )
3532 for _ , pod := range pods .Items {
3633 if pod .Labels ["app" ] == c .app {
37-
38- row := make (table.Row , 0 , len (c .templates ))
39- for _ , tmpl := range c .templates {
40- var buf bytes.Buffer
41- if errExecute := tmpl .Execute (& buf , pod ); errExecute != nil {
42- logrus .Warnln (errExecute )
43- }
44- row = append (row , buf .String ())
45- }
46- rows = append (rows , row )
34+ rows = append (rows , TemplateRender (comm .ConfigTemplatePod , pod ))
4735
4836 //name := pod.Name
4937 ////if strings.Index(name, app) == 0 {
5038 //// name = name[len(app):]
5139 //// name = strings.TrimLeft(name, "-_.")
5240 ////}
53- //
54- //// 格式化时间输出
55- //timeStr := "-"
56- //if startTime := pod.Status.StartTime; startTime != nil {
57- // timeStr = startTime.Format(time.DateTime)
58- //}
59- //
60- //rows = append(rows, table.Row{
61- // name,
62- // pod.Status.PodIP,
63- // PodPhaseView(pod),
64- // PodReadyView(pod),
65- // timeStr,
66- //})
6741 }
6842 }
6943
@@ -80,21 +54,16 @@ func (c *podModel) updateData(force bool) {
8054
8155// ShowPod 获取POD列表
8256func ShowPod (app string , lastModel tea.Model ) (tea.Model , error ) {
83- templates , errTmpl := NewTmplParseSlice (comm .ShowKubeteaConfig ().Template .Pod .Body )
84- if errTmpl != nil {
85- return nil , errTmpl
86- }
8757
8858 // 渲染UI
8959 m := & podModel {
9060 Abstract : ui.Abstract {LastModel : lastModel },
9161 TableFilter : ui .NewTableFilter (),
9262 app : app ,
93- templates : templates ,
9463 }
9564 m .Abstract .Model = m
9665
97- m .TableFilter .Table = ui .NewTableWithData (comm .ShowKubeteaConfig ().Template . Pod . Column , nil )
66+ m .TableFilter .Table = ui .NewTableWithData (comm .ShowKubeteaConfig ().ShowTemplateColumn ( comm . ConfigTemplatePod ) , nil )
9867 m .TableFilter .Focus ()
9968 m .updateData (false )
10069
@@ -154,8 +123,8 @@ var phaseAlias = map[v1.PodPhase]string{
154123 "Terminating" : "✴️" ,
155124}
156125
157- // PodPhaseView 友好显示POD状态
158- func PodPhaseView (pod v1.Pod ) string {
126+ // podPhaseView 友好显示POD状态
127+ func podPhaseView (pod v1.Pod ) string {
159128 phase := pod .Status .Phase
160129 if pod .DeletionTimestamp != nil {
161130 phase = "Terminating"
@@ -168,8 +137,8 @@ func PodPhaseView(pod v1.Pod) string {
168137 return result
169138}
170139
171- // PodReadyView 友好显示POD的Ready状态
172- func PodReadyView (pod v1.Pod ) string {
140+ // podReadyView 友好显示POD的Ready状态
141+ func podReadyView (pod v1.Pod ) string {
173142 for _ , condition := range pod .Status .Conditions {
174143 if condition .Type == v1 .PodReady && condition .Status == v1 .ConditionTrue {
175144 return "✔️"
0 commit comments