Merge pull request #316 from paivagustavo/command-aliases
add canonical full and short names for objectsmine
commit
07ce879806
|
|
@ -26,12 +26,12 @@ type RestMapper struct {
|
||||||
Connection
|
Connection
|
||||||
}
|
}
|
||||||
|
|
||||||
// Find a mapping given a resource name.
|
// Find a mapping given a resource kind.
|
||||||
func (*RestMapper) Find(res string) (*meta.RESTMapping, error) {
|
func (*RestMapper) Find(kind string) (*meta.RESTMapping, error) {
|
||||||
if m, ok := resMap[res]; ok {
|
if m, ok := kindToMapper[kind]; ok {
|
||||||
return m, nil
|
return m, nil
|
||||||
}
|
}
|
||||||
return nil, fmt.Errorf("no mapping for resource %s", res)
|
return nil, fmt.Errorf("no mapping for kind %s", kind)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ToRESTMapper map resources to kind, and map kind and version to interfaces for manipulating K8s objects.
|
// ToRESTMapper map resources to kind, and map kind and version to interfaces for manipulating K8s objects.
|
||||||
|
|
@ -116,18 +116,18 @@ func (*RestMapper) Name() meta.RESTScopeName {
|
||||||
return meta.RESTScopeNameNamespace
|
return meta.RESTScopeNameNamespace
|
||||||
}
|
}
|
||||||
|
|
||||||
var resMap = map[string]*meta.RESTMapping{
|
var kindToMapper = map[string]*meta.RESTMapping{
|
||||||
"ConfigMaps": {
|
"ConfigMap": {
|
||||||
Resource: schema.GroupVersionResource{Group: "", Version: "v1", Resource: "configmap"},
|
Resource: schema.GroupVersionResource{Group: "", Version: "v1", Resource: "configmap"},
|
||||||
GroupVersionKind: schema.GroupVersionKind{Group: "", Version: "v1", Kind: "ConfigMap"},
|
GroupVersionKind: schema.GroupVersionKind{Group: "", Version: "v1", Kind: "ConfigMap"},
|
||||||
Scope: RestMapping,
|
Scope: RestMapping,
|
||||||
},
|
},
|
||||||
"Pods": {
|
"Pod": {
|
||||||
Resource: schema.GroupVersionResource{Group: "", Version: "v1", Resource: "pod"},
|
Resource: schema.GroupVersionResource{Group: "", Version: "v1", Resource: "pod"},
|
||||||
GroupVersionKind: schema.GroupVersionKind{Group: "", Version: "v1", Kind: "Pod"},
|
GroupVersionKind: schema.GroupVersionKind{Group: "", Version: "v1", Kind: "Pod"},
|
||||||
Scope: RestMapping,
|
Scope: RestMapping,
|
||||||
},
|
},
|
||||||
"Services": {
|
"Service": {
|
||||||
Resource: schema.GroupVersionResource{Group: "", Version: "v1", Resource: "service"},
|
Resource: schema.GroupVersionResource{Group: "", Version: "v1", Resource: "service"},
|
||||||
GroupVersionKind: schema.GroupVersionKind{Group: "", Version: "v1", Kind: "Service"},
|
GroupVersionKind: schema.GroupVersionKind{Group: "", Version: "v1", Kind: "Service"},
|
||||||
Scope: RestMapping,
|
Scope: RestMapping,
|
||||||
|
|
@ -137,81 +137,81 @@ var resMap = map[string]*meta.RESTMapping{
|
||||||
GroupVersionKind: schema.GroupVersionKind{Group: "", Version: "v1", Kind: "Endpoints"},
|
GroupVersionKind: schema.GroupVersionKind{Group: "", Version: "v1", Kind: "Endpoints"},
|
||||||
Scope: RestMapping,
|
Scope: RestMapping,
|
||||||
},
|
},
|
||||||
"Namespaces": {
|
"Namespace": {
|
||||||
Resource: schema.GroupVersionResource{Group: "", Version: "v1", Resource: "namespace"},
|
Resource: schema.GroupVersionResource{Group: "", Version: "v1", Resource: "namespace"},
|
||||||
GroupVersionKind: schema.GroupVersionKind{Group: "", Version: "v1", Kind: "Namespace"},
|
GroupVersionKind: schema.GroupVersionKind{Group: "", Version: "v1", Kind: "Namespace"},
|
||||||
Scope: RestMapping,
|
Scope: RestMapping,
|
||||||
},
|
},
|
||||||
"Nodes": {
|
"Node": {
|
||||||
Resource: schema.GroupVersionResource{Group: "", Version: "v1", Resource: "node"},
|
Resource: schema.GroupVersionResource{Group: "", Version: "v1", Resource: "node"},
|
||||||
GroupVersionKind: schema.GroupVersionKind{Group: "", Version: "v1", Kind: "Node"},
|
GroupVersionKind: schema.GroupVersionKind{Group: "", Version: "v1", Kind: "Node"},
|
||||||
Scope: RestMapping,
|
Scope: RestMapping,
|
||||||
},
|
},
|
||||||
"PersistentVolumes": {
|
"PersistentVolume": {
|
||||||
Resource: schema.GroupVersionResource{Group: "", Version: "v1", Resource: "persistentvolume"},
|
Resource: schema.GroupVersionResource{Group: "", Version: "v1", Resource: "persistentvolume"},
|
||||||
GroupVersionKind: schema.GroupVersionKind{Group: "", Version: "v1", Kind: "PersistentVolume"},
|
GroupVersionKind: schema.GroupVersionKind{Group: "", Version: "v1", Kind: "PersistentVolume"},
|
||||||
Scope: RestMapping,
|
Scope: RestMapping,
|
||||||
},
|
},
|
||||||
"PersistentVolumeClaims": {
|
"PersistentVolumeClaim": {
|
||||||
Resource: schema.GroupVersionResource{Group: "", Version: "v1", Resource: "persistentvolumeclaim"},
|
Resource: schema.GroupVersionResource{Group: "", Version: "v1", Resource: "persistentvolumeclaim"},
|
||||||
GroupVersionKind: schema.GroupVersionKind{Group: "", Version: "v1", Kind: "PersistentVolumeClaim"},
|
GroupVersionKind: schema.GroupVersionKind{Group: "", Version: "v1", Kind: "PersistentVolumeClaim"},
|
||||||
Scope: RestMapping,
|
Scope: RestMapping,
|
||||||
},
|
},
|
||||||
"ReplicationControllers": {
|
"ReplicationController": {
|
||||||
Resource: schema.GroupVersionResource{Group: "", Version: "v1", Resource: "replicationcontroller"},
|
Resource: schema.GroupVersionResource{Group: "", Version: "v1", Resource: "replicationcontroller"},
|
||||||
GroupVersionKind: schema.GroupVersionKind{Group: "", Version: "v1", Kind: "ReplicationController"},
|
GroupVersionKind: schema.GroupVersionKind{Group: "", Version: "v1", Kind: "ReplicationController"},
|
||||||
Scope: RestMapping,
|
Scope: RestMapping,
|
||||||
},
|
},
|
||||||
"Secrets": {
|
"Secret": {
|
||||||
Resource: schema.GroupVersionResource{Group: "", Version: "v1", Resource: "secret"},
|
Resource: schema.GroupVersionResource{Group: "", Version: "v1", Resource: "secret"},
|
||||||
GroupVersionKind: schema.GroupVersionKind{Group: "", Version: "v1", Kind: "Secret"},
|
GroupVersionKind: schema.GroupVersionKind{Group: "", Version: "v1", Kind: "Secret"},
|
||||||
Scope: RestMapping,
|
Scope: RestMapping,
|
||||||
},
|
},
|
||||||
"StorageClasses": {
|
"StorageClasse": {
|
||||||
Resource: schema.GroupVersionResource{Group: "storage.k8s.io", Version: "v1", Resource: "storageclass"},
|
Resource: schema.GroupVersionResource{Group: "storage.k8s.io", Version: "v1", Resource: "storageclass"},
|
||||||
GroupVersionKind: schema.GroupVersionKind{Group: "storage.k8s.io", Version: "v1", Kind: "StorageClass"},
|
GroupVersionKind: schema.GroupVersionKind{Group: "storage.k8s.io", Version: "v1", Kind: "StorageClass"},
|
||||||
Scope: RestMapping,
|
Scope: RestMapping,
|
||||||
},
|
},
|
||||||
"ServiceAccounts": {
|
"ServiceAccount": {
|
||||||
Resource: schema.GroupVersionResource{Group: "", Version: "v1", Resource: "serviceaccount"},
|
Resource: schema.GroupVersionResource{Group: "", Version: "v1", Resource: "serviceaccount"},
|
||||||
GroupVersionKind: schema.GroupVersionKind{Group: "", Version: "v1", Kind: "ServiceAccount"},
|
GroupVersionKind: schema.GroupVersionKind{Group: "", Version: "v1", Kind: "ServiceAccount"},
|
||||||
Scope: RestMapping,
|
Scope: RestMapping,
|
||||||
},
|
},
|
||||||
|
|
||||||
"Deployments": {
|
"Deployment": {
|
||||||
Resource: schema.GroupVersionResource{Group: "apps", Version: "v1", Resource: "deployment"},
|
Resource: schema.GroupVersionResource{Group: "apps", Version: "v1", Resource: "deployment"},
|
||||||
GroupVersionKind: schema.GroupVersionKind{Group: "apps", Version: "v1", Kind: "Deployment"},
|
GroupVersionKind: schema.GroupVersionKind{Group: "apps", Version: "v1", Kind: "Deployment"},
|
||||||
Scope: RestMapping,
|
Scope: RestMapping,
|
||||||
},
|
},
|
||||||
"ReplicaSets": {
|
"ReplicaSet": {
|
||||||
Resource: schema.GroupVersionResource{Group: "apps", Version: "v1", Resource: "replicaset"},
|
Resource: schema.GroupVersionResource{Group: "apps", Version: "v1", Resource: "replicaset"},
|
||||||
GroupVersionKind: schema.GroupVersionKind{Group: "apps", Version: "v1", Kind: "ReplicaSet"},
|
GroupVersionKind: schema.GroupVersionKind{Group: "apps", Version: "v1", Kind: "ReplicaSet"},
|
||||||
Scope: RestMapping,
|
Scope: RestMapping,
|
||||||
},
|
},
|
||||||
"StatefulSets": {
|
"StatefulSet": {
|
||||||
Resource: schema.GroupVersionResource{Group: "apps", Version: "v1", Resource: "statefulsets"},
|
Resource: schema.GroupVersionResource{Group: "apps", Version: "v1", Resource: "statefulsets"},
|
||||||
GroupVersionKind: schema.GroupVersionKind{Group: "apps", Version: "v1", Kind: "StatefulSet"},
|
GroupVersionKind: schema.GroupVersionKind{Group: "apps", Version: "v1", Kind: "StatefulSet"},
|
||||||
Scope: RestMapping,
|
Scope: RestMapping,
|
||||||
},
|
},
|
||||||
|
|
||||||
"HorizontalPodAutoscalers": {
|
"HorizontalPodAutoscaler": {
|
||||||
Resource: schema.GroupVersionResource{Group: "autoscaling", Version: "v1", Resource: "horizontalpodautoscaler"},
|
Resource: schema.GroupVersionResource{Group: "autoscaling", Version: "v1", Resource: "horizontalpodautoscaler"},
|
||||||
GroupVersionKind: schema.GroupVersionKind{Group: "autoscaling", Version: "v1", Kind: "HorizontalPodAutoscaler"},
|
GroupVersionKind: schema.GroupVersionKind{Group: "autoscaling", Version: "v1", Kind: "HorizontalPodAutoscaler"},
|
||||||
Scope: RestMapping,
|
Scope: RestMapping,
|
||||||
},
|
},
|
||||||
|
|
||||||
"Jobs": {
|
"Job": {
|
||||||
Resource: schema.GroupVersionResource{Group: "batch", Version: "v1", Resource: "job"},
|
Resource: schema.GroupVersionResource{Group: "batch", Version: "v1", Resource: "job"},
|
||||||
GroupVersionKind: schema.GroupVersionKind{Group: "batch", Version: "v1", Kind: "Job"},
|
GroupVersionKind: schema.GroupVersionKind{Group: "batch", Version: "v1", Kind: "Job"},
|
||||||
Scope: RestMapping,
|
Scope: RestMapping,
|
||||||
},
|
},
|
||||||
"CronJobs": {
|
"CronJob": {
|
||||||
Resource: schema.GroupVersionResource{Group: "batch", Version: "v1", Resource: "cronjob"},
|
Resource: schema.GroupVersionResource{Group: "batch", Version: "v1", Resource: "cronjob"},
|
||||||
GroupVersionKind: schema.GroupVersionKind{Group: "batch", Version: "v1", Kind: "CronJob"},
|
GroupVersionKind: schema.GroupVersionKind{Group: "batch", Version: "v1", Kind: "CronJob"},
|
||||||
Scope: RestMapping,
|
Scope: RestMapping,
|
||||||
},
|
},
|
||||||
|
|
||||||
"DaemonSets": {
|
"DaemonSet": {
|
||||||
Resource: schema.GroupVersionResource{Group: "extensions", Version: "v1beta1", Resource: "daemonset"},
|
Resource: schema.GroupVersionResource{Group: "extensions", Version: "v1beta1", Resource: "daemonset"},
|
||||||
GroupVersionKind: schema.GroupVersionKind{Group: "extensions", Version: "v1beta1", Kind: "DaemonSet"},
|
GroupVersionKind: schema.GroupVersionKind{Group: "extensions", Version: "v1beta1", Kind: "DaemonSet"},
|
||||||
Scope: RestMapping,
|
Scope: RestMapping,
|
||||||
|
|
@ -222,45 +222,45 @@ var resMap = map[string]*meta.RESTMapping{
|
||||||
Scope: RestMapping,
|
Scope: RestMapping,
|
||||||
},
|
},
|
||||||
|
|
||||||
"ClusterRoles": {
|
"ClusterRole": {
|
||||||
Resource: schema.GroupVersionResource{Group: "rbac.authorization.k8s.io", Version: "v1", Resource: "clusterrole"},
|
Resource: schema.GroupVersionResource{Group: "rbac.authorization.k8s.io", Version: "v1", Resource: "clusterrole"},
|
||||||
GroupVersionKind: schema.GroupVersionKind{Group: "rbac.authorization.k8s.io", Version: "v1", Kind: "ClusterRole"},
|
GroupVersionKind: schema.GroupVersionKind{Group: "rbac.authorization.k8s.io", Version: "v1", Kind: "ClusterRole"},
|
||||||
Scope: RestMapping,
|
Scope: RestMapping,
|
||||||
},
|
},
|
||||||
"ClusterRoleBindings": {
|
"ClusterRoleBinding": {
|
||||||
Resource: schema.GroupVersionResource{Group: "rbac.authorization.k8s.io", Version: "v1", Resource: "clusterrolebinding"},
|
Resource: schema.GroupVersionResource{Group: "rbac.authorization.k8s.io", Version: "v1", Resource: "clusterrolebinding"},
|
||||||
GroupVersionKind: schema.GroupVersionKind{Group: "rbac.authorization.k8s.io", Version: "v1", Kind: "ClusterRoleBinding"},
|
GroupVersionKind: schema.GroupVersionKind{Group: "rbac.authorization.k8s.io", Version: "v1", Kind: "ClusterRoleBinding"},
|
||||||
Scope: RestMapping,
|
Scope: RestMapping,
|
||||||
},
|
},
|
||||||
"Roles": {
|
"Role": {
|
||||||
Resource: schema.GroupVersionResource{Group: "rbac.authorization.k8s.io", Version: "v1", Resource: "role"},
|
Resource: schema.GroupVersionResource{Group: "rbac.authorization.k8s.io", Version: "v1", Resource: "role"},
|
||||||
GroupVersionKind: schema.GroupVersionKind{Group: "rbac.authorization.k8s.io", Version: "v1", Kind: "Role"},
|
GroupVersionKind: schema.GroupVersionKind{Group: "rbac.authorization.k8s.io", Version: "v1", Kind: "Role"},
|
||||||
Scope: RestMapping,
|
Scope: RestMapping,
|
||||||
},
|
},
|
||||||
"RoleBindings": {
|
"RoleBinding": {
|
||||||
Resource: schema.GroupVersionResource{Group: "rbac.authorization.k8s.io", Version: "v1", Resource: "rolebinding"},
|
Resource: schema.GroupVersionResource{Group: "rbac.authorization.k8s.io", Version: "v1", Resource: "rolebinding"},
|
||||||
GroupVersionKind: schema.GroupVersionKind{Group: "rbac.authorization.k8s.io", Version: "v1", Kind: "RoleBinding"},
|
GroupVersionKind: schema.GroupVersionKind{Group: "rbac.authorization.k8s.io", Version: "v1", Kind: "RoleBinding"},
|
||||||
Scope: RestMapping,
|
Scope: RestMapping,
|
||||||
},
|
},
|
||||||
|
|
||||||
"CustomResourceDefinitions": {
|
"CustomResourceDefinition": {
|
||||||
Resource: schema.GroupVersionResource{Group: "apiextensions.k8s.io", Version: "v1beta1", Resource: "customresourcedefinitions"},
|
Resource: schema.GroupVersionResource{Group: "apiextensions.k8s.io", Version: "v1beta1", Resource: "customresourcedefinitions"},
|
||||||
GroupVersionKind: schema.GroupVersionKind{Group: "apiextensions.k8s.io", Version: "v1beta1", Kind: "CustomResourceDefinition"},
|
GroupVersionKind: schema.GroupVersionKind{Group: "apiextensions.k8s.io", Version: "v1beta1", Kind: "CustomResourceDefinition"},
|
||||||
Scope: RestMapping,
|
Scope: RestMapping,
|
||||||
},
|
},
|
||||||
"NetworkPolicies": {
|
"NetworkPolicy": {
|
||||||
Resource: schema.GroupVersionResource{Group: "extensions", Version: "v1beta1", Resource: "networkpolicies"},
|
Resource: schema.GroupVersionResource{Group: "extensions", Version: "v1beta1", Resource: "networkpolicies"},
|
||||||
GroupVersionKind: schema.GroupVersionKind{Group: "extensions", Version: "v1beta1", Kind: "NetworkPolicy"},
|
GroupVersionKind: schema.GroupVersionKind{Group: "extensions", Version: "v1beta1", Kind: "NetworkPolicy"},
|
||||||
Scope: RestMapping,
|
Scope: RestMapping,
|
||||||
},
|
},
|
||||||
|
|
||||||
"Events": {
|
"Event": {
|
||||||
Resource: schema.GroupVersionResource{Group: "events.k8s.io", Version: "v1beta1", Resource: "events"},
|
Resource: schema.GroupVersionResource{Group: "events.k8s.io", Version: "v1beta1", Resource: "events"},
|
||||||
GroupVersionKind: schema.GroupVersionKind{Group: "events.k8s.io", Version: "v1beta1", Kind: "Event"},
|
GroupVersionKind: schema.GroupVersionKind{Group: "events.k8s.io", Version: "v1beta1", Kind: "Event"},
|
||||||
Scope: RestMapping,
|
Scope: RestMapping,
|
||||||
},
|
},
|
||||||
|
|
||||||
"PodDisruptionBudgets": {
|
"PodDisruptionBudget": {
|
||||||
Resource: schema.GroupVersionResource{Group: "policy", Version: "v1beta1", Resource: "poddisruptionbudgets"},
|
Resource: schema.GroupVersionResource{Group: "policy", Version: "v1beta1", Resource: "poddisruptionbudgets"},
|
||||||
GroupVersionKind: schema.GroupVersionKind{Group: "policy", Version: "v1beta1", Kind: "PodDisruptionBudget"},
|
GroupVersionKind: schema.GroupVersionKind{Group: "policy", Version: "v1beta1", Kind: "PodDisruptionBudget"},
|
||||||
Scope: RestMapping,
|
Scope: RestMapping,
|
||||||
|
|
|
||||||
|
|
@ -107,7 +107,7 @@ func (v *aliasView) runCmd(evt *tcell.EventKey) *tcell.EventKey {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (v *aliasView) hydrate() resource.TableData {
|
func (v *aliasView) hydrate() resource.TableData {
|
||||||
cmds := make(map[string]resCmd, 40)
|
cmds := make(map[string]*resCmd, 40)
|
||||||
aliasCmds(v.app.Conn(), cmds)
|
aliasCmds(v.app.Conn(), cmds)
|
||||||
|
|
||||||
data := resource.TableData{
|
data := resource.TableData{
|
||||||
|
|
@ -119,7 +119,7 @@ func (v *aliasView) hydrate() resource.TableData {
|
||||||
for k := range cmds {
|
for k := range cmds {
|
||||||
fields := resource.Row{
|
fields := resource.Row{
|
||||||
ui.Pad(k, 30),
|
ui.Pad(k, 30),
|
||||||
ui.Pad(cmds[k].title, 30),
|
ui.Pad(cmds[k].kind, 30),
|
||||||
ui.Pad(cmds[k].api, 30),
|
ui.Pad(cmds[k].api, 30),
|
||||||
}
|
}
|
||||||
data.Rows[k] = &resource.RowEvent{
|
data.Rows[k] = &resource.RowEvent{
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,6 @@ func TestAliasView(t *testing.T) {
|
||||||
v.Init(nil, "")
|
v.Init(nil, "")
|
||||||
|
|
||||||
assert.Equal(t, 3, len(td.Header))
|
assert.Equal(t, 3, len(td.Header))
|
||||||
assert.Equal(t, 33, len(td.Rows))
|
assert.Equal(t, 41, len(td.Rows))
|
||||||
assert.Equal(t, "Aliases", v.getTitle())
|
assert.Equal(t, "Aliases", v.getTitle())
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -71,7 +71,7 @@ func (c *command) isStdCmd(cmd string) bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *command) isAliasCmd(cmd string) bool {
|
func (c *command) isAliasCmd(cmd string) bool {
|
||||||
cmds := make(map[string]resCmd, 30)
|
cmds := make(map[string]*resCmd, 30)
|
||||||
resourceViews(c.app.Conn(), cmds)
|
resourceViews(c.app.Conn(), cmds)
|
||||||
res, ok := cmds[cmd]
|
res, ok := cmds[cmd]
|
||||||
if !ok {
|
if !ok {
|
||||||
|
|
@ -83,7 +83,7 @@ func (c *command) isAliasCmd(cmd string) bool {
|
||||||
r = res.listFn(c.app.Conn(), resource.DefaultNamespace)
|
r = res.listFn(c.app.Conn(), resource.DefaultNamespace)
|
||||||
}
|
}
|
||||||
|
|
||||||
v := res.viewFn(res.title, c.app, r)
|
v := res.viewFn(res.kind, c.app, r)
|
||||||
if res.colorerFn != nil {
|
if res.colorerFn != nil {
|
||||||
v.setColorerFn(res.colorerFn)
|
v.setColorerFn(res.colorerFn)
|
||||||
}
|
}
|
||||||
|
|
@ -94,8 +94,7 @@ func (c *command) isAliasCmd(cmd string) bool {
|
||||||
v.setDecorateFn(res.decorateFn)
|
v.setDecorateFn(res.decorateFn)
|
||||||
}
|
}
|
||||||
|
|
||||||
const fmat = "Viewing resource %s..."
|
c.app.Flash().Infof("Viewing resource %s...", res.kind)
|
||||||
c.app.Flash().Infof(fmat, res.title)
|
|
||||||
log.Debug().Msgf("Running command %s", cmd)
|
log.Debug().Msgf("Running command %s", cmd)
|
||||||
c.exec(cmd, v)
|
c.exec(cmd, v)
|
||||||
|
|
||||||
|
|
@ -103,7 +102,7 @@ func (c *command) isAliasCmd(cmd string) bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *command) isCRDCmd(cmd string) bool {
|
func (c *command) isCRDCmd(cmd string) bool {
|
||||||
crds := map[string]resCmd{}
|
crds := map[string]*resCmd{}
|
||||||
allCRDs(c.app.Conn(), crds)
|
allCRDs(c.app.Conn(), crds)
|
||||||
res, ok := crds[cmd]
|
res, ok := crds[cmd]
|
||||||
if !ok {
|
if !ok {
|
||||||
|
|
@ -115,7 +114,7 @@ func (c *command) isCRDCmd(cmd string) bool {
|
||||||
name = res.singular
|
name = res.singular
|
||||||
}
|
}
|
||||||
v := newResourceView(
|
v := newResourceView(
|
||||||
res.title,
|
res.kind,
|
||||||
c.app,
|
c.app,
|
||||||
resource.NewCustomList(c.app.Conn(), "", res.api, res.version, name),
|
resource.NewCustomList(c.app.Conn(), "", res.api, res.version, name),
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -26,23 +26,49 @@ type (
|
||||||
resCmd struct {
|
resCmd struct {
|
||||||
crdCmd
|
crdCmd
|
||||||
|
|
||||||
title string
|
kind string
|
||||||
viewFn viewFn
|
viewFn viewFn
|
||||||
listFn listFn
|
listFn listFn
|
||||||
enterFn enterFn
|
enterFn enterFn
|
||||||
colorerFn ui.ColorerFunc
|
colorerFn ui.ColorerFunc
|
||||||
decorateFn decorateFn
|
decorateFn decorateFn
|
||||||
}
|
}
|
||||||
|
|
||||||
|
AliasConfig struct {
|
||||||
|
Aliases map[string]string `yaml:"aliases"`
|
||||||
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
func aliasCmds(c k8s.Connection, m map[string]resCmd) {
|
var DefaultAliasConfig = AliasConfig{
|
||||||
|
Aliases: map[string]string{
|
||||||
|
"Deployment": "dp",
|
||||||
|
"Secret": "sec",
|
||||||
|
"Jobs": "jo",
|
||||||
|
|
||||||
|
"ClusterRoles": "cr",
|
||||||
|
"ClusterRoleBindings": "crb",
|
||||||
|
"RoleBindings": "rb",
|
||||||
|
"Roles": "ro",
|
||||||
|
|
||||||
|
"NetworkPolicies": "np",
|
||||||
|
|
||||||
|
"Contexts": "ctx",
|
||||||
|
"Users": "usr",
|
||||||
|
"Groups": "grp",
|
||||||
|
"PortForward": "pf",
|
||||||
|
"Benchmark": "be",
|
||||||
|
"ScreenDumps": "sd",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
func aliasCmds(c k8s.Connection, m map[string]*resCmd) {
|
||||||
resourceViews(c, m)
|
resourceViews(c, m)
|
||||||
if c != nil {
|
if c != nil {
|
||||||
allCRDs(c, m)
|
allCRDs(c, m)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func allCRDs(c k8s.Connection, m map[string]resCmd) {
|
func allCRDs(c k8s.Connection, m map[string]*resCmd) {
|
||||||
crds, _ := resource.NewCustomResourceDefinitionList(c, resource.AllNamespaces).
|
crds, _ := resource.NewCustomResourceDefinitionList(c, resource.AllNamespaces).
|
||||||
Resource().
|
Resource().
|
||||||
List(resource.AllNamespaces)
|
List(resource.AllNamespaces)
|
||||||
|
|
@ -59,7 +85,7 @@ func allCRDs(c k8s.Connection, m map[string]resCmd) {
|
||||||
}
|
}
|
||||||
|
|
||||||
res := resCmd{
|
res := resCmd{
|
||||||
title: grp.Kind,
|
kind: grp.Kind,
|
||||||
crdCmd: crdCmd{
|
crdCmd: crdCmd{
|
||||||
api: grp.Group,
|
api: grp.Group,
|
||||||
version: grp.Version,
|
version: grp.Version,
|
||||||
|
|
@ -67,17 +93,17 @@ func allCRDs(c k8s.Connection, m map[string]resCmd) {
|
||||||
}
|
}
|
||||||
if p, ok := ff["plural"].(string); ok {
|
if p, ok := ff["plural"].(string); ok {
|
||||||
res.plural = p
|
res.plural = p
|
||||||
m[p] = res
|
m[p] = &res
|
||||||
}
|
}
|
||||||
|
|
||||||
if s, ok := ff["singular"].(string); ok {
|
if s, ok := ff["singular"].(string); ok {
|
||||||
res.singular = s
|
res.singular = s
|
||||||
m[s] = res
|
m[s] = &res
|
||||||
}
|
}
|
||||||
|
|
||||||
if aa, ok := ff["aliases"].([]interface{}); ok {
|
if aa, ok := ff["aliases"].([]interface{}); ok {
|
||||||
for _, a := range aa {
|
for _, a := range aa {
|
||||||
m[a.(string)] = res
|
m[a.(string)] = &res
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -122,372 +148,378 @@ func showSAPolicy(app *appView, _, _, selection string) {
|
||||||
app.inject(newPolicyView(app, mapFuSubject("ServiceAccount"), n))
|
app.inject(newPolicyView(app, mapFuSubject("ServiceAccount"), n))
|
||||||
}
|
}
|
||||||
|
|
||||||
func resourceViews(c k8s.Connection, m map[string]resCmd) {
|
func collect(commandList ...[]*resCmd) (accum []*resCmd) {
|
||||||
primRes(m)
|
for _, commands := range commandList {
|
||||||
coreRes(m)
|
accum = append(accum, commands...)
|
||||||
stateRes(m)
|
}
|
||||||
rbacRes(m)
|
return
|
||||||
apiExtRes(m)
|
}
|
||||||
batchRes(m)
|
|
||||||
appsRes(m)
|
func resourceViews(c k8s.Connection, cmdMap map[string]*resCmd) {
|
||||||
extRes(m)
|
commands := collect(
|
||||||
v1beta1Res(m)
|
primRes(), coreRes(), stateRes(), rbacRes(), apiExtRes(),
|
||||||
custRes(m)
|
batchRes(), appsRes(), extRes(), v1beta1Res(), custRes(),
|
||||||
|
)
|
||||||
|
|
||||||
if c != nil {
|
if c != nil {
|
||||||
hpaRes(c, m)
|
commands = append(commands, hpaRes(c)...)
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, rsc := range commands {
|
||||||
|
cmdMap[strings.ToLower(rsc.kind)] = rsc
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add default aliases
|
||||||
|
// TODO: read aliases from a config file.
|
||||||
|
for rsc, alias := range DefaultAliasConfig.Aliases {
|
||||||
|
if cmd, ok := cmdMap[strings.ToLower(rsc)]; ok {
|
||||||
|
addAlias(cmdMap, cmd, alias)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func stateRes(m map[string]resCmd) {
|
if c != nil {
|
||||||
m["cm"] = resCmd{
|
discoverAliasesFromServer(c, cmdMap)
|
||||||
title: "ConfigMaps",
|
}
|
||||||
crdCmd: crdCmd{
|
}
|
||||||
api: "",
|
|
||||||
},
|
func addAlias(cmdMap map[string]*resCmd, cmd *resCmd, alias string) {
|
||||||
|
if alias == "" {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
alias = strings.ToLower(alias)
|
||||||
|
if _, ok := cmdMap[alias]; !ok {
|
||||||
|
cmdMap[alias] = cmd
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func addAPIResourceAliases(cmds map[string]*resCmd, resource metav1.APIResource) {
|
||||||
|
if strings.Contains(resource.Name, "/") {
|
||||||
|
// Ignore resources that has slash, e.g.,
|
||||||
|
// deployment/status, namespace/finalizers and etc.
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if cmd, ok := cmds[strings.ToLower(resource.Kind)]; ok {
|
||||||
|
addAlias(cmds, cmd, resource.Name)
|
||||||
|
addAlias(cmds, cmd, resource.SingularName)
|
||||||
|
for _, sn := range resource.ShortNames {
|
||||||
|
addAlias(cmds, cmd, sn)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func discoverAliasesFromServer(con k8s.Connection, cmds map[string]*resCmd) {
|
||||||
|
_, resourceLists, _ := con.DialOrDie().Discovery().ServerGroupsAndResources()
|
||||||
|
for _, resourceList := range resourceLists {
|
||||||
|
for _, resource := range resourceList.APIResources {
|
||||||
|
addAPIResourceAliases(cmds, resource)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func stateRes() []*resCmd {
|
||||||
|
return []*resCmd{
|
||||||
|
{
|
||||||
|
kind: "ConfigMap",
|
||||||
viewFn: newResourceView,
|
viewFn: newResourceView,
|
||||||
listFn: resource.NewConfigMapList,
|
listFn: resource.NewConfigMapList,
|
||||||
}
|
|
||||||
m["pv"] = resCmd{
|
|
||||||
title: "PersistentVolumes",
|
|
||||||
crdCmd: crdCmd{
|
|
||||||
api: "",
|
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
kind: "PersistentVolume",
|
||||||
viewFn: newResourceView,
|
viewFn: newResourceView,
|
||||||
listFn: resource.NewPersistentVolumeList,
|
listFn: resource.NewPersistentVolumeList,
|
||||||
colorerFn: pvColorer,
|
colorerFn: pvColorer,
|
||||||
}
|
|
||||||
m["pvc"] = resCmd{
|
|
||||||
title: "PersistentVolumeClaims",
|
|
||||||
crdCmd: crdCmd{
|
|
||||||
api: "",
|
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
kind: "PersistentVolumeClaim",
|
||||||
viewFn: newResourceView,
|
viewFn: newResourceView,
|
||||||
listFn: resource.NewPersistentVolumeClaimList,
|
listFn: resource.NewPersistentVolumeClaimList,
|
||||||
colorerFn: pvcColorer,
|
colorerFn: pvcColorer,
|
||||||
}
|
|
||||||
m["sec"] = resCmd{
|
|
||||||
title: "Secrets",
|
|
||||||
crdCmd: crdCmd{
|
|
||||||
api: "",
|
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
kind: "Secret",
|
||||||
viewFn: newSecretView,
|
viewFn: newSecretView,
|
||||||
listFn: resource.NewSecretList,
|
listFn: resource.NewSecretList,
|
||||||
}
|
},
|
||||||
m["sc"] = resCmd{
|
{
|
||||||
title: "StorageClasses",
|
kind: "StorageClass",
|
||||||
crdCmd: crdCmd{
|
crdCmd: crdCmd{
|
||||||
api: "storage.k8s.io",
|
api: "storage.k8s.io",
|
||||||
},
|
},
|
||||||
viewFn: newResourceView,
|
viewFn: newResourceView,
|
||||||
listFn: resource.NewStorageClassList,
|
listFn: resource.NewStorageClassList,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func primRes(m map[string]resCmd) {
|
func primRes() []*resCmd {
|
||||||
m["no"] = resCmd{
|
return []*resCmd{
|
||||||
title: "Nodes",
|
{
|
||||||
crdCmd: crdCmd{
|
kind: "Node",
|
||||||
api: "",
|
|
||||||
},
|
|
||||||
viewFn: newNodeView,
|
viewFn: newNodeView,
|
||||||
listFn: resource.NewNodeList,
|
listFn: resource.NewNodeList,
|
||||||
colorerFn: nsColorer,
|
colorerFn: nsColorer,
|
||||||
}
|
|
||||||
m["ns"] = resCmd{
|
|
||||||
title: "Namespaces",
|
|
||||||
crdCmd: crdCmd{
|
|
||||||
api: "",
|
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
kind: "Namespace",
|
||||||
viewFn: newNamespaceView,
|
viewFn: newNamespaceView,
|
||||||
listFn: resource.NewNamespaceList,
|
listFn: resource.NewNamespaceList,
|
||||||
colorerFn: nsColorer,
|
colorerFn: nsColorer,
|
||||||
}
|
|
||||||
m["po"] = resCmd{
|
|
||||||
title: "Pods",
|
|
||||||
crdCmd: crdCmd{
|
|
||||||
api: "",
|
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
kind: "Pod",
|
||||||
viewFn: newPodView,
|
viewFn: newPodView,
|
||||||
listFn: resource.NewPodList,
|
listFn: resource.NewPodList,
|
||||||
colorerFn: podColorer,
|
colorerFn: podColorer,
|
||||||
}
|
|
||||||
m["sa"] = resCmd{
|
|
||||||
title: "ServiceAccounts",
|
|
||||||
crdCmd: crdCmd{
|
|
||||||
api: "",
|
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
kind: "ServiceAccount",
|
||||||
viewFn: newResourceView,
|
viewFn: newResourceView,
|
||||||
listFn: resource.NewServiceAccountList,
|
listFn: resource.NewServiceAccountList,
|
||||||
enterFn: showSAPolicy,
|
enterFn: showSAPolicy,
|
||||||
}
|
|
||||||
m["svc"] = resCmd{
|
|
||||||
title: "Services",
|
|
||||||
crdCmd: crdCmd{
|
|
||||||
api: "",
|
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
kind: "Service",
|
||||||
viewFn: newSvcView,
|
viewFn: newSvcView,
|
||||||
listFn: resource.NewServiceList,
|
listFn: resource.NewServiceList,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func coreRes(m map[string]resCmd) {
|
func coreRes() []*resCmd {
|
||||||
m["ctx"] = resCmd{
|
return []*resCmd{
|
||||||
title: "Contexts",
|
{
|
||||||
crdCmd: crdCmd{
|
kind: "Contexts",
|
||||||
api: "",
|
|
||||||
},
|
|
||||||
viewFn: newContextView,
|
viewFn: newContextView,
|
||||||
listFn: resource.NewContextList,
|
listFn: resource.NewContextList,
|
||||||
colorerFn: ctxColorer,
|
colorerFn: ctxColorer,
|
||||||
}
|
|
||||||
m["ds"] = resCmd{
|
|
||||||
title: "DaemonSets",
|
|
||||||
crdCmd: crdCmd{
|
|
||||||
api: "",
|
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
kind: "DaemonSet",
|
||||||
viewFn: newDaemonSetView,
|
viewFn: newDaemonSetView,
|
||||||
listFn: resource.NewDaemonSetList,
|
listFn: resource.NewDaemonSetList,
|
||||||
colorerFn: dpColorer,
|
colorerFn: dpColorer,
|
||||||
}
|
|
||||||
m["ep"] = resCmd{
|
|
||||||
title: "EndPoints",
|
|
||||||
crdCmd: crdCmd{
|
|
||||||
api: "",
|
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
kind: "EndPoints",
|
||||||
viewFn: newResourceView,
|
viewFn: newResourceView,
|
||||||
listFn: resource.NewEndpointsList,
|
listFn: resource.NewEndpointsList,
|
||||||
}
|
|
||||||
m["ev"] = resCmd{
|
|
||||||
title: "Events",
|
|
||||||
crdCmd: crdCmd{
|
|
||||||
api: "",
|
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
kind: "Event",
|
||||||
viewFn: newResourceView,
|
viewFn: newResourceView,
|
||||||
listFn: resource.NewEventList,
|
listFn: resource.NewEventList,
|
||||||
colorerFn: evColorer,
|
colorerFn: evColorer,
|
||||||
}
|
|
||||||
m["rc"] = resCmd{
|
|
||||||
title: "ReplicationControllers",
|
|
||||||
crdCmd: crdCmd{
|
|
||||||
api: "",
|
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
kind: "ReplicationController",
|
||||||
viewFn: newScalableResourceView,
|
viewFn: newScalableResourceView,
|
||||||
listFn: resource.NewReplicationControllerList,
|
listFn: resource.NewReplicationControllerList,
|
||||||
colorerFn: rsColorer,
|
colorerFn: rsColorer,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func custRes(m map[string]resCmd) {
|
func custRes() []*resCmd {
|
||||||
m["usr"] = resCmd{
|
return []*resCmd{
|
||||||
title: "Users",
|
{
|
||||||
crdCmd: crdCmd{
|
kind: "Users",
|
||||||
api: "",
|
|
||||||
},
|
|
||||||
viewFn: newSubjectView,
|
viewFn: newSubjectView,
|
||||||
}
|
|
||||||
m["grp"] = resCmd{
|
|
||||||
title: "Groups",
|
|
||||||
crdCmd: crdCmd{
|
|
||||||
api: "",
|
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
kind: "Groups",
|
||||||
viewFn: newSubjectView,
|
viewFn: newSubjectView,
|
||||||
}
|
|
||||||
m["pf"] = resCmd{
|
|
||||||
title: "PortForward",
|
|
||||||
crdCmd: crdCmd{
|
|
||||||
api: "",
|
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
kind: "PortForward",
|
||||||
viewFn: newForwardView,
|
viewFn: newForwardView,
|
||||||
}
|
|
||||||
m["be"] = resCmd{
|
|
||||||
title: "Benchmark",
|
|
||||||
crdCmd: crdCmd{
|
|
||||||
api: "",
|
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
kind: "Benchmark",
|
||||||
viewFn: newBenchView,
|
viewFn: newBenchView,
|
||||||
}
|
|
||||||
m["sd"] = resCmd{
|
|
||||||
title: "ScreenDumps",
|
|
||||||
crdCmd: crdCmd{
|
|
||||||
api: "",
|
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
kind: "ScreenDumps",
|
||||||
viewFn: newDumpView,
|
viewFn: newDumpView,
|
||||||
}
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
func rbacRes(m map[string]resCmd) {
|
}
|
||||||
m["cr"] = resCmd{
|
|
||||||
title: "ClusterRoles",
|
func rbacRes() []*resCmd {
|
||||||
|
return []*resCmd{
|
||||||
|
{
|
||||||
|
kind: "ClusterRole",
|
||||||
crdCmd: crdCmd{
|
crdCmd: crdCmd{
|
||||||
api: "rbac.authorization.k8s.io",
|
api: "rbac.authorization.k8s.io",
|
||||||
},
|
},
|
||||||
viewFn: newResourceView,
|
viewFn: newResourceView,
|
||||||
listFn: resource.NewClusterRoleList,
|
listFn: resource.NewClusterRoleList,
|
||||||
enterFn: showRBAC,
|
enterFn: showRBAC,
|
||||||
}
|
},
|
||||||
m["crb"] = resCmd{
|
{
|
||||||
title: "ClusterRoleBindings",
|
kind: "ClusterRoleBinding",
|
||||||
crdCmd: crdCmd{
|
crdCmd: crdCmd{
|
||||||
api: "rbac.authorization.k8s.io",
|
api: "rbac.authorization.k8s.io",
|
||||||
},
|
},
|
||||||
viewFn: newResourceView,
|
viewFn: newResourceView,
|
||||||
listFn: resource.NewClusterRoleBindingList,
|
listFn: resource.NewClusterRoleBindingList,
|
||||||
enterFn: showClusterRole,
|
enterFn: showClusterRole,
|
||||||
}
|
},
|
||||||
|
{
|
||||||
m["rb"] = resCmd{
|
kind: "RoleBinding",
|
||||||
title: "RoleBindings",
|
|
||||||
crdCmd: crdCmd{
|
crdCmd: crdCmd{
|
||||||
api: "rbac.authorization.k8s.io",
|
api: "rbac.authorization.k8s.io",
|
||||||
},
|
},
|
||||||
viewFn: newResourceView,
|
viewFn: newResourceView,
|
||||||
listFn: resource.NewRoleBindingList,
|
listFn: resource.NewRoleBindingList,
|
||||||
enterFn: showRole,
|
enterFn: showRole,
|
||||||
}
|
},
|
||||||
m["ro"] = resCmd{
|
{
|
||||||
title: "Roles",
|
kind: "Role",
|
||||||
crdCmd: crdCmd{
|
crdCmd: crdCmd{
|
||||||
api: "rbac.authorization.k8s.io",
|
api: "rbac.authorization.k8s.io",
|
||||||
},
|
},
|
||||||
viewFn: newResourceView,
|
viewFn: newResourceView,
|
||||||
listFn: resource.NewRoleList,
|
listFn: resource.NewRoleList,
|
||||||
enterFn: showRBAC,
|
enterFn: showRBAC,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func apiExtRes(m map[string]resCmd) {
|
func apiExtRes() []*resCmd {
|
||||||
m["crd"] = resCmd{
|
return []*resCmd{
|
||||||
title: "CustomResourceDefinitions",
|
{
|
||||||
|
kind: "CustomResourceDefinition",
|
||||||
crdCmd: crdCmd{
|
crdCmd: crdCmd{
|
||||||
api: "apiextensions.k8s.io",
|
api: "apiextensions.k8s.io",
|
||||||
},
|
},
|
||||||
viewFn: newResourceView,
|
viewFn: newResourceView,
|
||||||
listFn: resource.NewCustomResourceDefinitionList,
|
listFn: resource.NewCustomResourceDefinitionList,
|
||||||
enterFn: showCRD,
|
enterFn: showCRD,
|
||||||
}
|
},
|
||||||
m["np"] = resCmd{
|
{
|
||||||
title: "NetworkPolicies",
|
kind: "NetworkPolicy",
|
||||||
crdCmd: crdCmd{
|
crdCmd: crdCmd{
|
||||||
api: "apiextensions.k8s.io",
|
api: "apiextensions.k8s.io",
|
||||||
},
|
},
|
||||||
viewFn: newResourceView,
|
viewFn: newResourceView,
|
||||||
listFn: resource.NewNetworkPolicyList,
|
listFn: resource.NewNetworkPolicyList,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func batchRes(m map[string]resCmd) {
|
func batchRes() []*resCmd {
|
||||||
m["cj"] = resCmd{
|
return []*resCmd{
|
||||||
title: "CronJobs",
|
{
|
||||||
|
kind: "CronJob",
|
||||||
crdCmd: crdCmd{
|
crdCmd: crdCmd{
|
||||||
api: "batch",
|
api: "batch",
|
||||||
},
|
},
|
||||||
viewFn: newCronJobView,
|
viewFn: newCronJobView,
|
||||||
listFn: resource.NewCronJobList,
|
listFn: resource.NewCronJobList,
|
||||||
}
|
},
|
||||||
m["jo"] = resCmd{
|
{
|
||||||
title: "Jobs",
|
kind: "Job",
|
||||||
crdCmd: crdCmd{
|
crdCmd: crdCmd{
|
||||||
api: "batch",
|
api: "batch",
|
||||||
},
|
},
|
||||||
viewFn: newJobView,
|
viewFn: newJobView,
|
||||||
listFn: resource.NewJobList,
|
listFn: resource.NewJobList,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func appsRes(m map[string]resCmd) {
|
func appsRes() []*resCmd {
|
||||||
m["dp"] = resCmd{
|
return []*resCmd{
|
||||||
title: "Deployments",
|
{
|
||||||
|
kind: "Deployment",
|
||||||
crdCmd: crdCmd{
|
crdCmd: crdCmd{
|
||||||
api: "apps",
|
api: "apps",
|
||||||
},
|
},
|
||||||
viewFn: newDeployView,
|
viewFn: newDeployView,
|
||||||
listFn: resource.NewDeploymentList,
|
listFn: resource.NewDeploymentList,
|
||||||
colorerFn: dpColorer,
|
colorerFn: dpColorer,
|
||||||
}
|
},
|
||||||
m["rs"] = resCmd{
|
{
|
||||||
title: "ReplicaSets",
|
kind: "ReplicaSet",
|
||||||
crdCmd: crdCmd{
|
crdCmd: crdCmd{
|
||||||
api: "apps",
|
api: "apps",
|
||||||
},
|
},
|
||||||
viewFn: newReplicaSetView,
|
viewFn: newReplicaSetView,
|
||||||
listFn: resource.NewReplicaSetList,
|
listFn: resource.NewReplicaSetList,
|
||||||
colorerFn: rsColorer,
|
colorerFn: rsColorer,
|
||||||
}
|
},
|
||||||
m["sts"] = resCmd{
|
{
|
||||||
title: "StatefulSets",
|
kind: "StatefulSet",
|
||||||
crdCmd: crdCmd{
|
crdCmd: crdCmd{
|
||||||
api: "apps",
|
api: "apps",
|
||||||
},
|
},
|
||||||
viewFn: newStatefulSetView,
|
viewFn: newStatefulSetView,
|
||||||
listFn: resource.NewStatefulSetList,
|
listFn: resource.NewStatefulSetList,
|
||||||
colorerFn: stsColorer,
|
colorerFn: stsColorer,
|
||||||
}
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
func extRes(m map[string]resCmd) {
|
}
|
||||||
m["ing"] = resCmd{
|
|
||||||
title: "Ingress",
|
func extRes() []*resCmd {
|
||||||
|
return []*resCmd{
|
||||||
|
{
|
||||||
|
kind: "Ingress",
|
||||||
crdCmd: crdCmd{
|
crdCmd: crdCmd{
|
||||||
api: "extensions",
|
api: "extensions",
|
||||||
},
|
},
|
||||||
viewFn: newResourceView,
|
viewFn: newResourceView,
|
||||||
listFn: resource.NewIngressList,
|
listFn: resource.NewIngressList,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func v1beta1Res(m map[string]resCmd) {
|
func v1beta1Res() []*resCmd {
|
||||||
m["pdb"] = resCmd{
|
return []*resCmd{
|
||||||
title: "PodDisruptionBudgets",
|
{
|
||||||
|
kind: "PodDisruptionBudget",
|
||||||
crdCmd: crdCmd{
|
crdCmd: crdCmd{
|
||||||
api: "v1.beta1",
|
api: "v1.beta1",
|
||||||
},
|
},
|
||||||
viewFn: newResourceView,
|
viewFn: newResourceView,
|
||||||
listFn: resource.NewPDBList,
|
listFn: resource.NewPDBList,
|
||||||
colorerFn: pdbColorer,
|
colorerFn: pdbColorer,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func hpaRes(c k8s.Connection, cmds map[string]resCmd) {
|
func hpaRes(c k8s.Connection) []*resCmd {
|
||||||
rev, ok, err := c.SupportsRes("autoscaling", []string{"v1", "v2beta1", "v2beta2"})
|
rev, ok, err := c.SupportsRes("autoscaling", []string{"v1", "v2beta1", "v2beta2"})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error().Err(err).Msg("Checking HPA")
|
log.Error().Err(err).Msg("Checking HPA")
|
||||||
return
|
return nil
|
||||||
}
|
}
|
||||||
if !ok {
|
if !ok {
|
||||||
log.Error().Msg("HPA are not supported on this cluster")
|
log.Error().Msg("HPA are not supported on this cluster")
|
||||||
return
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
hpa := &resCmd{
|
||||||
|
kind: "HorizontalPodAutoscaler",
|
||||||
|
crdCmd: crdCmd{
|
||||||
|
api: "autoscaling",
|
||||||
|
},
|
||||||
|
viewFn: newResourceView,
|
||||||
}
|
}
|
||||||
|
|
||||||
switch rev {
|
switch rev {
|
||||||
case "v1":
|
case "v1":
|
||||||
cmds["hpa"] = resCmd{
|
hpa.listFn = resource.NewHorizontalPodAutoscalerV1List
|
||||||
title: "HorizontalPodAutoscalers",
|
|
||||||
crdCmd: crdCmd{
|
|
||||||
api: "autoscaling",
|
|
||||||
},
|
|
||||||
viewFn: newResourceView,
|
|
||||||
listFn: resource.NewHorizontalPodAutoscalerV1List,
|
|
||||||
}
|
|
||||||
case "v2beta1":
|
case "v2beta1":
|
||||||
cmds["hpa"] = resCmd{
|
hpa.listFn = resource.NewHorizontalPodAutoscalerV2Beta1List
|
||||||
title: "HorizontalPodAutoscalers",
|
|
||||||
crdCmd: crdCmd{
|
|
||||||
api: "autoscaling",
|
|
||||||
},
|
|
||||||
viewFn: newResourceView,
|
|
||||||
listFn: resource.NewHorizontalPodAutoscalerV2Beta1List,
|
|
||||||
}
|
|
||||||
case "v2beta2":
|
case "v2beta2":
|
||||||
cmds["hpa"] = resCmd{
|
hpa.listFn = resource.NewHorizontalPodAutoscalerList
|
||||||
title: "HorizontalPodAutoscalers",
|
|
||||||
crdCmd: crdCmd{
|
|
||||||
api: "autoscaling",
|
|
||||||
},
|
|
||||||
viewFn: newResourceView,
|
|
||||||
listFn: resource.NewHorizontalPodAutoscalerList,
|
|
||||||
}
|
|
||||||
default:
|
default:
|
||||||
log.Panic().Msgf("K9s unsupported HPA version. Exiting!")
|
log.Panic().Msgf("K9s unsupported HPA version. Exiting!")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return []*resCmd{hpa}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue