forked from michaeljsaenz/kview
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
143 lines (114 loc) · 4.62 KB
/
main.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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
package main
import (
"strings"
"time"
"fyne.io/fyne/v2"
"fyne.io/fyne/v2/app"
"fyne.io/fyne/v2/container"
"fyne.io/fyne/v2/layout"
"fyne.io/fyne/v2/theme"
"fyne.io/fyne/v2/widget"
"github.com/michaeljsaenz/kview/internal/k8s"
"github.com/michaeljsaenz/kview/internal/ui"
"github.com/michaeljsaenz/kview/internal/utils"
)
func main() {
// setup k8s clientset
clientset, config := k8s.GetClientSet()
// retrieve namespaces
namespaceList := k8s.GetNamespaces(*clientset)
// get current cluster context
currentContext := k8s.GetCurrentContext()
// create a new app, window title and size
app := app.New()
win := app.NewWindow("KView")
win.SetMaster()
win.Resize(fyne.NewSize(1200, 700))
win.CenterOnScreen()
// list binding, bind pod list (podData) to data
var podData []string
data, list := ui.GetListData(&podData)
// intial/base widgets and windows
topWindowLabel, topWindow, rightWindow, rightWindowTitle := ui.CreateWindows(currentContext)
podStatus, input, listTitle := ui.CreateBaseWidgets()
podLabelsLabel, podLabels, podLabelsScroll, podAnnotationsLabel, podAnnotations, podAnnotationsScroll,
podEventsLabel, podEvents, podEventsScroll, podLogsLabel, podLog, podLogScroll, podDetailLabel, podDetailLog, podDetailScroll,
podVolumesLabel, podVolumes, podVolumesScroll := ui.CreateBaseTabs()
podTabs, podLogTabs := ui.CreateBaseTabContainers(podLabelsLabel, podLabelsScroll, podAnnotationsLabel, podAnnotationsScroll,
podEventsLabel, podEventsScroll, podLogsLabel, podLogScroll, podDetailLabel, podDetailScroll, podVolumesLabel, podVolumesScroll)
// create the namespace dropdown list widget
namespaceListDropdown := widget.NewSelect(namespaceList, func(selectedNamespace string) {
if selectedNamespace != "" {
podData = k8s.GetPodDataWithNamespace(*clientset, selectedNamespace)
}
ui.UpdateInput(input, data, list)
})
namespaceListDropdown.PlaceHolder = "Select namespace..."
namespaceListDropdown.FocusGained()
// refresh and clear pod list data
refresh := widget.NewButtonWithIcon("Refresh", theme.ViewRefreshIcon(), func() {
if namespaceListDropdown.Selected == "" {
podData = []string{}
} else {
podData = k8s.GetPodDataWithNamespace(*clientset, namespaceListDropdown.Selected)
}
ui.RefreshData(input, data, list, podTabs, podLogTabs, podLogsLabel, podStatus, rightWindowTitle)
})
stringErrorResponse, errorPresent := utils.CheckForError(podData)
if !errorPresent {
stringErrorResponse, errorPresent = utils.CheckForError(namespaceList)
}
if errorPresent {
ui.SetupErrorUI(stringErrorResponse, namespaceListDropdown, input, app)
}
// search application name (input list field)
if !errorPresent {
input.OnSubmitted = func(s string) {
podData = ui.InputOnSubmitted(input, *clientset, namespaceListDropdown)
data.Reload()
list.UnselectAll()
}
}
yamlButton := ui.CreateIconButton("Application (Pod) YAML", theme.ZoomInIcon())
yamlButton.Hide()
execButtons := ui.CreateBaseExecIconButton("", theme.LoginIcon())
for _, execButton := range execButtons {
execButton.Hide()
}
gridOne := container.New(layout.NewGridLayout(1), yamlButton)
gridTwo := container.New(layout.NewGridLayoutWithColumns(2), execButtons[0], execButtons[1], execButtons[2],
execButtons[3], execButtons[4], execButtons[5], execButtons[6], execButtons[7], execButtons[8], execButtons[9])
ui.ListOnSelected(list, data, *clientset, *config, rightWindowTitle, podStatus, podLabels,
podAnnotations, podEvents, podVolumes, podLog, podDetailLog, podTabs, podLogTabs, podLogScroll,
podLogsLabel, app, yamlButton, execButtons, namespaceListDropdown)
//return tabs to initial tab (index 0)
list.OnUnselected = func(id widget.ListItemID) {
podTabs.SelectIndex(0)
podLogTabs.SelectIndex(0)
for _, execButton := range execButtons {
execButton.Hide()
}
}
rightContainer := container.NewBorder(
container.NewVBox(rightWindowTitle, podStatus, podTabs, podLogTabs, gridOne, gridTwo),
nil, nil, nil, rightWindow)
listContainer := container.NewBorder(container.NewVBox(listTitle, namespaceListDropdown, input),
nil, nil, nil, list)
// podData(list) left side, podData detail right side
split := container.NewHSplit(listContainer, rightContainer)
split.Offset = 0.3
// check current cluster context to update top window label
go func() {
for range time.Tick(time.Second * 5) {
currentContext = k8s.GetCurrentContext()
if strings.Contains(topWindowLabel.Text, currentContext) {
continue
} else {
topWindowLabel.Text = ("Cluster Context: " + currentContext)
topWindowLabel.Refresh()
}
}
}()
win.SetContent(container.NewBorder(topWindow, refresh, nil, nil, split))
win.ShowAndRun()
}