cleaning up a bit

mine
derailed 2019-02-01 18:55:32 -07:00
parent 48fbb3c1f3
commit b6208008ff
14 changed files with 46 additions and 47 deletions

View File

@ -13,7 +13,7 @@ for changes and offers subsequent commands to interact with observed resources.
--- ---
[![Go Report Card](https://goreportcard.com/badge/github.com/derailed/k9s)](https://goreportcard.com/report/github.com/derailed/k9s) [![Go Report Card](https://goreportcard.com/badge/github.com/derailed/k9s)](https://goreportcard.com/report/github.com/derailed/k9s)
[![Build Status](https://travis-ci.org/derailed/k9s.svg?branch=master)](https://travis-ci.org/derailed/k9s) [![Build Status](https://travis-ci.com/derailed/k9s.svg?branch=master)](https://travis-ci.com/derailed/k9s)
<br/> <br/>

View File

@ -74,7 +74,7 @@ func k8sCRB() *rbacv1.ClusterRoleBinding {
CreationTimestamp: metav1.Time{testTime()}, CreationTimestamp: metav1.Time{testTime()},
}, },
Subjects: []rbacv1.Subject{ Subjects: []rbacv1.Subject{
rbacv1.Subject{Kind: "test", Name: "fred", Namespace: "blee"}, {Kind: "test", Name: "fred", Namespace: "blee"},
}, },
} }
} }

View File

@ -106,7 +106,7 @@ func k8sCR() *rbacv1.ClusterRole {
CreationTimestamp: metav1.Time{testTime()}, CreationTimestamp: metav1.Time{testTime()},
}, },
Rules: []rbacv1.PolicyRule{ Rules: []rbacv1.PolicyRule{
rbacv1.PolicyRule{ {
Verbs: []string{"get", "list"}, Verbs: []string{"get", "list"},
APIGroups: []string{""}, APIGroups: []string{""},
ResourceNames: []string{"pod"}, ResourceNames: []string{"pod"},

View File

@ -30,6 +30,7 @@ func init() {
} }
type ( type (
// ApiGroup represents a K8s resource descriptor.
ApiGroup struct { ApiGroup struct {
Resource string Resource string
Group, Kind, Version string Group, Kind, Version string

View File

@ -33,7 +33,7 @@ func TestNodeMarshal(t *testing.T) {
mx := NewMockMetricsIfc() mx := NewMockMetricsIfc()
m.When(mx.PerNodeMetrics([]v1.Node{*k8sNode()})). m.When(mx.PerNodeMetrics([]v1.Node{*k8sNode()})).
ThenReturn(map[string]k8s.Metric{"fred": k8s.Metric{}}, nil) ThenReturn(map[string]k8s.Metric{"fred": {}}, nil)
ca := NewMockCaller() ca := NewMockCaller()
m.When(ca.Get("blee", "fred")).ThenReturn(k8sNode(), nil) m.When(ca.Get("blee", "fred")).ThenReturn(k8sNode(), nil)
@ -49,7 +49,7 @@ func TestNodeListData(t *testing.T) {
mx := NewMockMetricsIfc() mx := NewMockMetricsIfc()
m.When(mx.PerNodeMetrics([]v1.Node{*k8sNode()})). m.When(mx.PerNodeMetrics([]v1.Node{*k8sNode()})).
ThenReturn(map[string]k8s.Metric{"fred": k8s.Metric{}}, nil) ThenReturn(map[string]k8s.Metric{"fred": {}}, nil)
ca := NewMockCaller() ca := NewMockCaller()
m.When(ca.List("")).ThenReturn(k8s.Collection{*k8sNode()}, nil) m.When(ca.List("")).ThenReturn(k8s.Collection{*k8sNode()}, nil)
@ -78,7 +78,7 @@ func TestNodeListDescribe(t *testing.T) {
mx := NewMockMetricsIfc() mx := NewMockMetricsIfc()
m.When(mx.PerNodeMetrics([]v1.Node{*k8sNode()})). m.When(mx.PerNodeMetrics([]v1.Node{*k8sNode()})).
ThenReturn(map[string]k8s.Metric{"fred": k8s.Metric{}}, nil) ThenReturn(map[string]k8s.Metric{"fred": {}}, nil)
ca := NewMockCaller() ca := NewMockCaller()
m.When(ca.Get("blee", "fred")).ThenReturn(k8sNode(), nil) m.When(ca.Get("blee", "fred")).ThenReturn(k8sNode(), nil)
l := resource.NewNodeListWithArgs("blee", resource.NewNodeWithArgs(ca, mx)) l := resource.NewNodeListWithArgs("blee", resource.NewNodeWithArgs(ca, mx))

View File

@ -36,7 +36,7 @@ func TestPodMarshal(t *testing.T) {
setup(t) setup(t)
mx := NewMockMetricsIfc() mx := NewMockMetricsIfc()
m.When(mx.PodMetrics()).ThenReturn(map[string]k8s.Metric{"fred": k8s.Metric{}}, nil) m.When(mx.PodMetrics()).ThenReturn(map[string]k8s.Metric{"fred": {}}, nil)
ca := NewMockCaller() ca := NewMockCaller()
m.When(ca.Get("blee", "fred")).ThenReturn(k8sPod(), nil) m.When(ca.Get("blee", "fred")).ThenReturn(k8sPod(), nil)
@ -51,7 +51,7 @@ func TestPodListData(t *testing.T) {
setup(t) setup(t)
mx := NewMockMetricsIfc() mx := NewMockMetricsIfc()
m.When(mx.PodMetrics()).ThenReturn(map[string]k8s.Metric{"fred": k8s.Metric{}}, nil) m.When(mx.PodMetrics()).ThenReturn(map[string]k8s.Metric{"fred": {}}, nil)
ca := NewMockCaller() ca := NewMockCaller()
m.When(ca.List("")).ThenReturn(k8s.Collection{*k8sPod()}, nil) m.When(ca.List("")).ThenReturn(k8s.Collection{*k8sPod()}, nil)
@ -79,7 +79,7 @@ func TestPodListDescribe(t *testing.T) {
setup(t) setup(t)
mx := NewMockMetricsIfc() mx := NewMockMetricsIfc()
m.When(mx.PodMetrics()).ThenReturn(map[string]k8s.Metric{"fred": k8s.Metric{}}, nil) m.When(mx.PodMetrics()).ThenReturn(map[string]k8s.Metric{"fred": {}}, nil)
ca := NewMockCaller() ca := NewMockCaller()
m.When(ca.Get("blee", "fred")).ThenReturn(k8sPod(), nil) m.When(ca.Get("blee", "fred")).ThenReturn(k8sPod(), nil)
l := resource.NewPodListWithArgs("blee", resource.NewPodWithArgs(ca, mx)) l := resource.NewPodListWithArgs("blee", resource.NewPodWithArgs(ca, mx))

View File

@ -106,9 +106,7 @@ func k8sSA() *v1.ServiceAccount {
Namespace: "blee", Namespace: "blee",
CreationTimestamp: metav1.Time{testTime()}, CreationTimestamp: metav1.Time{testTime()},
}, },
Secrets: []v1.ObjectReference{ Secrets: []v1.ObjectReference{{Name: "blee"}},
v1.ObjectReference{Name: "blee"},
},
} }
} }

View File

@ -32,11 +32,11 @@ func TestToPorts(t *testing.T) {
e string e string
}{ }{
{[]v1.ServicePort{ {[]v1.ServicePort{
v1.ServicePort{Name: "http", Port: 80, NodePort: 90, Protocol: "TCP"}}, {Name: "http", Port: 80, NodePort: 90, Protocol: "TCP"}},
"http:80►90", "http:80►90",
}, },
{[]v1.ServicePort{ {[]v1.ServicePort{
v1.ServicePort{Port: 80, NodePort: 30080, Protocol: "UDP"}}, {Port: 80, NodePort: 30080, Protocol: "UDP"}},
"80►30080UDP", "80►30080UDP",
}, },
} }
@ -48,9 +48,9 @@ func TestToPorts(t *testing.T) {
func BenchmarkToPorts(b *testing.B) { func BenchmarkToPorts(b *testing.B) {
var s Service var s Service
sp := []v1.ServicePort{ sp := []v1.ServicePort{
v1.ServicePort{Name: "http", Port: 80, NodePort: 90, Protocol: "TCP"}, {Name: "http", Port: 80, NodePort: 90, Protocol: "TCP"},
v1.ServicePort{Port: 80, NodePort: 90, Protocol: "TCP"}, {Port: 80, NodePort: 90, Protocol: "TCP"},
v1.ServicePort{Name: "http", Port: 80, NodePort: 90, Protocol: "TCP"}, {Name: "http", Port: 80, NodePort: 90, Protocol: "TCP"},
} }
b.ResetTimer() b.ResetTimer()
b.ReportAllocs() b.ReportAllocs()

View File

@ -123,7 +123,7 @@ func k8sSVC() *v1.Service {
ExternalIPs: []string{"2.2.2.2"}, ExternalIPs: []string{"2.2.2.2"},
Selector: map[string]string{"fred": "blee"}, Selector: map[string]string{"fred": "blee"},
Ports: []v1.ServicePort{ Ports: []v1.ServicePort{
v1.ServicePort{ {
Name: "http", Name: "http",
Port: 90, Port: 90,
Protocol: "TCP", Protocol: "TCP",

View File

@ -3,8 +3,8 @@ package views
import ( import (
"strings" "strings"
"github.com/gdamore/tcell"
"github.com/derailed/k9s/resource" "github.com/derailed/k9s/resource"
"github.com/gdamore/tcell"
"k8s.io/apimachinery/pkg/watch" "k8s.io/apimachinery/pkg/watch"
) )

View File

@ -3,8 +3,8 @@ package views
import ( import (
"testing" "testing"
"github.com/gdamore/tcell"
"github.com/derailed/k9s/resource" "github.com/derailed/k9s/resource"
"github.com/gdamore/tcell"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"k8s.io/apimachinery/pkg/watch" "k8s.io/apimachinery/pkg/watch"
) )

View File

@ -1,8 +1,8 @@
package views package views
import ( import (
"github.com/gdamore/tcell"
"github.com/derailed/k9s/resource" "github.com/derailed/k9s/resource"
"github.com/gdamore/tcell"
) )
type contextView struct { type contextView struct {

View File

@ -21,175 +21,175 @@ type (
) )
var cmdMap = map[string]resCmd{ var cmdMap = map[string]resCmd{
"cm": resCmd{ "cm": {
title: "Config Maps", title: "Config Maps",
api: "core", api: "core",
viewFn: newResourceView, viewFn: newResourceView,
listFn: resource.NewConfigMapList, listFn: resource.NewConfigMapList,
colorerFn: defaultColorer, colorerFn: defaultColorer,
}, },
"cr": resCmd{ "cr": {
title: "Cluster Roles", title: "Cluster Roles",
api: "rbac.authorization.k8s.io", api: "rbac.authorization.k8s.io",
viewFn: newResourceView, viewFn: newResourceView,
listFn: resource.NewClusterRoleList, listFn: resource.NewClusterRoleList,
colorerFn: defaultColorer, colorerFn: defaultColorer,
}, },
"crb": resCmd{ "crb": {
title: "Cluster Role Bindings", title: "Cluster Role Bindings",
api: "rbac.authorization.k8s.io", api: "rbac.authorization.k8s.io",
viewFn: newResourceView, viewFn: newResourceView,
listFn: resource.NewClusterRoleBindingList, listFn: resource.NewClusterRoleBindingList,
colorerFn: defaultColorer, colorerFn: defaultColorer,
}, },
"crd": resCmd{ "crd": {
title: "Custom Resource Definitions", title: "Custom Resource Definitions",
api: "apiextensions.k8s.io", api: "apiextensions.k8s.io",
viewFn: newResourceView, viewFn: newResourceView,
listFn: resource.NewCRDList, listFn: resource.NewCRDList,
colorerFn: defaultColorer, colorerFn: defaultColorer,
}, },
"cjo": resCmd{ "cjo": {
title: "CronJobs", title: "CronJobs",
api: "batch", api: "batch",
viewFn: newResourceView, viewFn: newResourceView,
listFn: resource.NewCronJobList, listFn: resource.NewCronJobList,
colorerFn: defaultColorer, colorerFn: defaultColorer,
}, },
"ctx": resCmd{ "ctx": {
title: "Contexts", title: "Contexts",
api: "core", api: "core",
viewFn: newContextView, viewFn: newContextView,
listFn: resource.NewContextList, listFn: resource.NewContextList,
colorerFn: ctxColorer, colorerFn: ctxColorer,
}, },
"ds": resCmd{ "ds": {
title: "DaemonSets", title: "DaemonSets",
api: "core", api: "core",
viewFn: newResourceView, viewFn: newResourceView,
listFn: resource.NewDaemonSetList, listFn: resource.NewDaemonSetList,
colorerFn: dpColorer, colorerFn: dpColorer,
}, },
"dp": resCmd{ "dp": {
title: "Deployments", title: "Deployments",
api: "apps", api: "apps",
viewFn: newResourceView, viewFn: newResourceView,
listFn: resource.NewDeploymentList, listFn: resource.NewDeploymentList,
colorerFn: dpColorer, colorerFn: dpColorer,
}, },
"ep": resCmd{ "ep": {
title: "EndPoints", title: "EndPoints",
api: "core", api: "core",
viewFn: newResourceView, viewFn: newResourceView,
listFn: resource.NewEndpointsList, listFn: resource.NewEndpointsList,
colorerFn: defaultColorer, colorerFn: defaultColorer,
}, },
"ev": resCmd{ "ev": {
title: "Events", title: "Events",
api: "core", api: "core",
viewFn: newResourceView, viewFn: newResourceView,
listFn: resource.NewEventList, listFn: resource.NewEventList,
colorerFn: evColorer, colorerFn: evColorer,
}, },
"hpa": resCmd{ "hpa": {
title: "Horizontal Pod Autoscalers", title: "Horizontal Pod Autoscalers",
api: "autoscaling", api: "autoscaling",
viewFn: newResourceView, viewFn: newResourceView,
listFn: resource.NewHPAList, listFn: resource.NewHPAList,
colorerFn: defaultColorer, colorerFn: defaultColorer,
}, },
"ing": resCmd{ "ing": {
title: "Ingress", title: "Ingress",
api: "extensions", api: "extensions",
viewFn: newResourceView, viewFn: newResourceView,
listFn: resource.NewIngressList, listFn: resource.NewIngressList,
colorerFn: defaultColorer, colorerFn: defaultColorer,
}, },
"jo": resCmd{ "jo": {
title: "Jobs", title: "Jobs",
api: "batch", api: "batch",
viewFn: newResourceView, viewFn: newResourceView,
listFn: resource.NewJobList, listFn: resource.NewJobList,
colorerFn: defaultColorer, colorerFn: defaultColorer,
}, },
"no": resCmd{ "no": {
title: "Nodes", title: "Nodes",
api: "core", api: "core",
viewFn: newResourceView, viewFn: newResourceView,
listFn: resource.NewNodeList, listFn: resource.NewNodeList,
colorerFn: nsColorer, colorerFn: nsColorer,
}, },
"ns": resCmd{ "ns": {
title: "Namespaces", title: "Namespaces",
api: "core", api: "core",
viewFn: newResourceView, viewFn: newResourceView,
listFn: resource.NewNamespaceList, listFn: resource.NewNamespaceList,
colorerFn: nsColorer, colorerFn: nsColorer,
}, },
"po": resCmd{ "po": {
title: "Pods", title: "Pods",
api: "core", api: "core",
viewFn: newPodView, viewFn: newPodView,
listFn: resource.NewPodList, listFn: resource.NewPodList,
colorerFn: podColorer, colorerFn: podColorer,
}, },
"pv": resCmd{ "pv": {
title: "Persistent Volumes", title: "Persistent Volumes",
api: "core", api: "core",
viewFn: newResourceView, viewFn: newResourceView,
listFn: resource.NewPVList, listFn: resource.NewPVList,
colorerFn: pvColorer, colorerFn: pvColorer,
}, },
"pvc": resCmd{ "pvc": {
title: "Persistent Volume Claims", title: "Persistent Volume Claims",
api: "core", api: "core",
viewFn: newResourceView, viewFn: newResourceView,
listFn: resource.NewPVCList, listFn: resource.NewPVCList,
colorerFn: pvcColorer, colorerFn: pvcColorer,
}, },
"rb": resCmd{ "rb": {
title: "Role Bindings", title: "Role Bindings",
api: "rbac.authorization.k8s.io", api: "rbac.authorization.k8s.io",
viewFn: newResourceView, viewFn: newResourceView,
listFn: resource.NewRoleBindingList, listFn: resource.NewRoleBindingList,
colorerFn: defaultColorer, colorerFn: defaultColorer,
}, },
"ro": resCmd{ "ro": {
title: "Roles", title: "Roles",
api: "rbac.authorization.k8s.io", api: "rbac.authorization.k8s.io",
viewFn: newResourceView, viewFn: newResourceView,
listFn: resource.NewRoleList, listFn: resource.NewRoleList,
colorerFn: defaultColorer, colorerFn: defaultColorer,
}, },
"rs": resCmd{ "rs": {
title: "Replica Sets", title: "Replica Sets",
api: "apps", api: "apps",
viewFn: newResourceView, viewFn: newResourceView,
listFn: resource.NewReplicaSetList, listFn: resource.NewReplicaSetList,
colorerFn: rsColorer, colorerFn: rsColorer,
}, },
"sa": resCmd{ "sa": {
title: "Service Accounts", title: "Service Accounts",
api: "core", api: "core",
viewFn: newResourceView, viewFn: newResourceView,
listFn: resource.NewServiceAccountList, listFn: resource.NewServiceAccountList,
colorerFn: defaultColorer, colorerFn: defaultColorer,
}, },
"sec": resCmd{ "sec": {
title: "Secrets", title: "Secrets",
api: "core", api: "core",
viewFn: newResourceView, viewFn: newResourceView,
listFn: resource.NewSecretList, listFn: resource.NewSecretList,
colorerFn: defaultColorer, colorerFn: defaultColorer,
}, },
"sts": resCmd{ "sts": {
title: "StatefulSets", title: "StatefulSets",
api: "apps", api: "apps",
viewFn: newResourceView, viewFn: newResourceView,
listFn: resource.NewStatefulSetList, listFn: resource.NewStatefulSetList,
colorerFn: stsColorer, colorerFn: stsColorer,
}, },
"svc": resCmd{ "svc": {
title: "Services", title: "Services",
api: "core", api: "core",
viewFn: newResourceView, viewFn: newResourceView,

View File

@ -3,8 +3,8 @@ package views
import ( import (
"context" "context"
"github.com/gdamore/tcell"
"github.com/derailed/k9s/resource" "github.com/derailed/k9s/resource"
"github.com/gdamore/tcell"
"github.com/k8sland/tview" "github.com/k8sland/tview"
) )