refactor master/details

mine
derailed 2019-06-20 11:14:50 -06:00
parent 5b5fc4026f
commit 83a381d485
3 changed files with 51 additions and 22 deletions

View File

@ -68,13 +68,18 @@ type (
CheckListNSAccess() error
}
k8sClient struct {
client kubernetes.Interface
dClient dynamic.Interface
nsClient dynamic.NamespaceableResourceInterface
mxsClient *versioned.Clientset
}
// APIClient represents a Kubernetes api client.
APIClient struct {
k8sClient
config *Config
client kubernetes.Interface
dClient dynamic.Interface
nsClient dynamic.NamespaceableResourceInterface
mxsClient *versioned.Clientset
useMetricServer bool
log zerolog.Logger
mx sync.Mutex

View File

@ -8,24 +8,37 @@ import (
"github.com/derailed/tview"
)
type masterDetail struct {
*tview.Pages
type (
pageView struct {
*tview.Pages
app *appView
actions keyActions
currentNS string
selectedItem string
selectedRow int
selectedFn func() string
enterFn enterFn
extraActionsFn func(keyActions)
app *appView
actions keyActions
}
masterDetail struct {
*pageView
currentNS string
selectedItem string
selectedRow int
selectedFn func() string
enterFn enterFn
extraActionsFn func(keyActions)
}
)
func newPageView(app *appView) *pageView {
return &pageView{
Pages: tview.NewPages(),
app: app,
actions: make(keyActions),
}
}
func newMasterDetail(title string, app *appView, ns string) *masterDetail {
v := masterDetail{
Pages: tview.NewPages(),
app: app,
actions: make(keyActions),
pageView: newPageView(app),
currentNS: ns,
}

View File

@ -15,12 +15,17 @@ type (
enterFn func(app *appView, ns, resource, selection string)
decorateFn func(resource.TableData) resource.TableData
crdCmd struct {
version string
plural string
singular string
}
resCmd struct {
title string
crdCmd
api string
version string
plural string
singular string
title string
viewFn viewFn
listFn listFn
enterFn enterFn
@ -50,7 +55,13 @@ func allCRDs(c k8s.Connection, m map[string]resCmd) {
Version: ff["version"].(string),
}
res := resCmd{title: grp.Kind, api: grp.Group, version: grp.Version}
res := resCmd{
title: grp.Kind,
api: grp.Group,
crdCmd: crdCmd{
version: grp.Version,
},
}
if p, ok := ff["plural"].(string); ok {
res.plural = p
m[p] = res