From ec626e991cab8789458bd49b61c41dc557199cd3 Mon Sep 17 00:00:00 2001 From: derailed Date: Mon, 25 Mar 2019 18:46:31 -0600 Subject: [PATCH] added cpu/mem req tracking for nodeview --- change_logs/release_0.3.2.md | 29 ++ cmd/root.go | 4 + internal/config/mock_connection_test.go | 46 +++ internal/k8s/api.go | 25 +- internal/resource/context_test.go | 16 +- internal/resource/helpers.go | 11 + internal/resource/mock_clustermeta_test.go | 46 +++ internal/resource/mock_connection_test.go | 46 +++ internal/resource/mock_metricsservice_test.go | 170 -------- internal/resource/mock_resource_test.go | 375 ------------------ ..._test.go => mock_switchablecruder_test.go} | 108 ++--- internal/resource/no.go | 118 +++++- internal/resource/no_test.go | 2 +- internal/views/no.go | 8 +- 14 files changed, 381 insertions(+), 623 deletions(-) create mode 100644 change_logs/release_0.3.2.md delete mode 100644 internal/resource/mock_metricsservice_test.go delete mode 100644 internal/resource/mock_resource_test.go rename internal/resource/{mock_switchableresource_test.go => mock_switchablecruder_test.go} (56%) diff --git a/change_logs/release_0.3.2.md b/change_logs/release_0.3.2.md new file mode 100644 index 00000000..23470199 --- /dev/null +++ b/change_logs/release_0.3.2.md @@ -0,0 +1,29 @@ +# Release v0.3.2 + +## Notes + +Thank you to all that contributed with flushing out issues with K9s! I'll try +to mark some of these issues as fixed. But if you don't mind grab the latest +rev and see if we're happier with some of the fixes! + +If you've filed an issue please help me verify and close. + +Thank you so much for your support!! + +--- + +## Change Logs + +1. [Feature #124](https://github.com/derailed/k9s/issues/124) + 1. *NodeView* Add current cpu/memory percentages to track current load on nodes. + 2. *NodeView* Add requested cpu/memory percentages to track how much containers + resources are requested on the cluster. + 3. *NodeView* Add requested cpu/memory raw metrics + 4. *NodeView* Add corresponding column sorters + + +--- + +## Resolved Bugs + ++ None diff --git a/cmd/root.go b/cmd/root.go index 1573cd96..d9e35aec 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -83,9 +83,13 @@ func loadConfiguration() *config.Config { k9sCfg.K9s.RefreshRate = refreshRate k9sCfg.Refine(k8sFlags) k9sCfg.SetConnection(k8s.InitConnectionOrDie(k8sCfg, log.Logger)) + log.Info().Msg("✅ Kubernetes connectivity") k9sCfg.Save() + // k8s.NewNode(k9sCfg.GetConnection()).FetchReqLimit("minikube") + // os.Exit(0) + return k9sCfg } diff --git a/internal/config/mock_connection_test.go b/internal/config/mock_connection_test.go index edaf7a5a..da3b5584 100644 --- a/internal/config/mock_connection_test.go +++ b/internal/config/mock_connection_test.go @@ -189,6 +189,25 @@ func (mock *MockConnection) ValidNamespaces() ([]v1.Namespace, error) { return ret0, ret1 } +func (mock *MockConnection) ValidPods(_param0 string) ([]v1.Pod, error) { + if mock == nil { + panic("mock must not be nil. Use myMock := NewMockConnection().") + } + params := []pegomock.Param{_param0} + result := pegomock.GetGenericMockFrom(mock).Invoke("ValidPods", params, []reflect.Type{reflect.TypeOf((*[]v1.Pod)(nil)).Elem(), reflect.TypeOf((*error)(nil)).Elem()}) + var ret0 []v1.Pod + var ret1 error + if len(result) != 0 { + if result[0] != nil { + ret0 = result[0].([]v1.Pod) + } + if result[1] != nil { + ret1 = result[1].(error) + } + } + return ret0, ret1 +} + func (mock *MockConnection) VerifyWasCalledOnce() *VerifierConnection { return &VerifierConnection{ mock: mock, @@ -442,3 +461,30 @@ func (c *Connection_ValidNamespaces_OngoingVerification) GetCapturedArguments() func (c *Connection_ValidNamespaces_OngoingVerification) GetAllCapturedArguments() { } + +func (verifier *VerifierConnection) ValidPods(_param0 string) *Connection_ValidPods_OngoingVerification { + params := []pegomock.Param{_param0} + methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "ValidPods", params, verifier.timeout) + return &Connection_ValidPods_OngoingVerification{mock: verifier.mock, methodInvocations: methodInvocations} +} + +type Connection_ValidPods_OngoingVerification struct { + mock *MockConnection + methodInvocations []pegomock.MethodInvocation +} + +func (c *Connection_ValidPods_OngoingVerification) GetCapturedArguments() string { + _param0 := c.GetAllCapturedArguments() + return _param0[len(_param0)-1] +} + +func (c *Connection_ValidPods_OngoingVerification) GetAllCapturedArguments() (_param0 []string) { + params := pegomock.GetGenericMockFrom(c.mock).GetInvocationParams(c.methodInvocations) + if len(params) > 0 { + _param0 = make([]string, len(params[0])) + for u, param := range params[0] { + _param0[u] = param.(string) + } + } + return +} diff --git a/internal/k8s/api.go b/internal/k8s/api.go index c7e13628..5454dc88 100644 --- a/internal/k8s/api.go +++ b/internal/k8s/api.go @@ -1,10 +1,13 @@ package k8s import ( + "fmt" + "github.com/rs/zerolog" "github.com/rs/zerolog/log" v1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/fields" "k8s.io/apimachinery/pkg/runtime/schema" "k8s.io/client-go/dynamic" "k8s.io/client-go/kubernetes" @@ -50,6 +53,7 @@ type ( IsNamespaced(n string) bool SupportsResource(group string) bool ValidNamespaces() ([]v1.Namespace, error) + ValidPods(node string) ([]v1.Pod, error) } // APIClient represents a Kubernetes api client. @@ -83,6 +87,23 @@ func (a *APIClient) ValidNamespaces() ([]v1.Namespace, error) { return nn.Items, nil } +// ValidPods returns a collection of all availble pods on a given node. +func (a *APIClient) ValidPods(node string) ([]v1.Pod, error) { + const selFmt = "spec.nodeName=%s,status.phase!=%s,status.phase!=%s" + fieldSelector, err := fields.ParseSelector(fmt.Sprintf(selFmt, node, v1.PodSucceeded, v1.PodFailed)) + if err != nil { + return nil, err + } + + pods, err := a.DialOrDie().Core().Pods("").List(metav1.ListOptions{ + FieldSelector: fieldSelector.String(), + }) + if err != nil { + return nil, err + } + return pods.Items, nil +} + // IsNamespaced check on server if given resource is namespaced func (a *APIClient) IsNamespaced(res string) bool { list, _ := a.DialOrDie().Discovery().ServerPreferredResources() @@ -126,7 +147,7 @@ func (a *APIClient) DialOrDie() kubernetes.Interface { var err error if a.client, err = kubernetes.NewForConfig(a.RestConfigOrDie()); err != nil { - a.log.Panic().Err(err) + a.log.Fatal().Msgf("Unable to connect to api server %v", err) } return a.client } @@ -135,7 +156,7 @@ func (a *APIClient) DialOrDie() kubernetes.Interface { func (a *APIClient) RestConfigOrDie() *restclient.Config { cfg, err := a.config.RESTConfig() if err != nil { - a.log.Panic().Err(err) + a.log.Panic().Msgf("Unable to connect to api server %v", err) } return cfg } diff --git a/internal/resource/context_test.go b/internal/resource/context_test.go index 8d86e204..e4bbe7fb 100644 --- a/internal/resource/context_test.go +++ b/internal/resource/context_test.go @@ -23,7 +23,7 @@ func NewContextWithArgs(c k8s.Connection, s resource.SwitchableCruder) *resource func TestCTXSwitch(t *testing.T) { mc := NewMockConnection() - mr := NewMockSwitchableResource() + mr := NewMockSwitchableCruder() m.When(mr.Switch("fred")).ThenReturn(nil) ctx := NewContextWithArgs(mc, mr) @@ -35,7 +35,7 @@ func TestCTXSwitch(t *testing.T) { func TestCTXList(t *testing.T) { mc := NewMockConnection() - mr := NewMockSwitchableResource() + mr := NewMockSwitchableCruder() m.When(mr.List("blee")).ThenReturn(k8s.Collection{*k8sNamedCTX()}, nil) ctx := NewContextWithArgs(mc, mr) @@ -48,7 +48,7 @@ func TestCTXList(t *testing.T) { func TestCTXDelete(t *testing.T) { mc := NewMockConnection() - mr := NewMockSwitchableResource() + mr := NewMockSwitchableCruder() m.When(mr.Delete("", "fred")).ThenReturn(nil) ctx := NewContextWithArgs(mc, mr) @@ -59,7 +59,7 @@ func TestCTXDelete(t *testing.T) { func TestCTXListHasName(t *testing.T) { mc := NewMockConnection() - mr := NewMockSwitchableResource() + mr := NewMockSwitchableCruder() ctx := NewContextWithArgs(mc, mr) l := NewContextListWithArgs("blee", ctx) @@ -69,7 +69,7 @@ func TestCTXListHasName(t *testing.T) { func TestCTXListHasNamespace(t *testing.T) { mc := NewMockConnection() - mr := NewMockSwitchableResource() + mr := NewMockSwitchableCruder() ctx := NewContextWithArgs(mc, mr) l := NewContextListWithArgs("blee", ctx) @@ -79,7 +79,7 @@ func TestCTXListHasNamespace(t *testing.T) { func TestCTXListHasResource(t *testing.T) { mc := NewMockConnection() - mr := NewMockSwitchableResource() + mr := NewMockSwitchableCruder() ctx := NewContextWithArgs(mc, mr) l := NewContextListWithArgs("blee", ctx) @@ -89,7 +89,7 @@ func TestCTXListHasResource(t *testing.T) { func TestCTXHeader(t *testing.T) { mc := NewMockConnection() - mr := NewMockSwitchableResource() + mr := NewMockSwitchableCruder() ctx := NewContextWithArgs(mc, mr) @@ -99,7 +99,7 @@ func TestCTXHeader(t *testing.T) { func TestCTXFields(t *testing.T) { mc := NewMockConnection() m.When(mc.Config()).ThenReturn(k8sConfig()) - mr := NewMockSwitchableResource() + mr := NewMockSwitchableCruder() m.When(mr.MustCurrentContextName()).ThenReturn("test") ctx := NewContextWithArgs(mc, mr) diff --git a/internal/resource/helpers.go b/internal/resource/helpers.go index e48e45ba..a8857499 100644 --- a/internal/resource/helpers.go +++ b/internal/resource/helpers.go @@ -36,6 +36,17 @@ const ( NAValue = "" ) +func asPerc(f float64) string { + return fmt.Sprintf("%d%%", int(f)) +} + +func toPerc(v1, v2 float64) float64 { + if v2 == 0 { + return 0 + } + return (v1 / v2) * 100 +} + func namespaced(n string) (string, string) { ns, po := path.Split(n) diff --git a/internal/resource/mock_clustermeta_test.go b/internal/resource/mock_clustermeta_test.go index 4d52a42f..7e85d20e 100644 --- a/internal/resource/mock_clustermeta_test.go +++ b/internal/resource/mock_clustermeta_test.go @@ -253,6 +253,25 @@ func (mock *MockClusterMeta) ValidNamespaces() ([]v1.Namespace, error) { return ret0, ret1 } +func (mock *MockClusterMeta) ValidPods(_param0 string) ([]v1.Pod, error) { + if mock == nil { + panic("mock must not be nil. Use myMock := NewMockClusterMeta().") + } + params := []pegomock.Param{_param0} + result := pegomock.GetGenericMockFrom(mock).Invoke("ValidPods", params, []reflect.Type{reflect.TypeOf((*[]v1.Pod)(nil)).Elem(), reflect.TypeOf((*error)(nil)).Elem()}) + var ret0 []v1.Pod + var ret1 error + if len(result) != 0 { + if result[0] != nil { + ret0 = result[0].([]v1.Pod) + } + if result[1] != nil { + ret1 = result[1].(error) + } + } + return ret0, ret1 +} + func (mock *MockClusterMeta) Version() (string, error) { if mock == nil { panic("mock must not be nil. Use myMock := NewMockClusterMeta().") @@ -594,6 +613,33 @@ func (c *ClusterMeta_ValidNamespaces_OngoingVerification) GetCapturedArguments() func (c *ClusterMeta_ValidNamespaces_OngoingVerification) GetAllCapturedArguments() { } +func (verifier *VerifierClusterMeta) ValidPods(_param0 string) *ClusterMeta_ValidPods_OngoingVerification { + params := []pegomock.Param{_param0} + methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "ValidPods", params, verifier.timeout) + return &ClusterMeta_ValidPods_OngoingVerification{mock: verifier.mock, methodInvocations: methodInvocations} +} + +type ClusterMeta_ValidPods_OngoingVerification struct { + mock *MockClusterMeta + methodInvocations []pegomock.MethodInvocation +} + +func (c *ClusterMeta_ValidPods_OngoingVerification) GetCapturedArguments() string { + _param0 := c.GetAllCapturedArguments() + return _param0[len(_param0)-1] +} + +func (c *ClusterMeta_ValidPods_OngoingVerification) GetAllCapturedArguments() (_param0 []string) { + params := pegomock.GetGenericMockFrom(c.mock).GetInvocationParams(c.methodInvocations) + if len(params) > 0 { + _param0 = make([]string, len(params[0])) + for u, param := range params[0] { + _param0[u] = param.(string) + } + } + return +} + func (verifier *VerifierClusterMeta) Version() *ClusterMeta_Version_OngoingVerification { params := []pegomock.Param{} methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "Version", params, verifier.timeout) diff --git a/internal/resource/mock_connection_test.go b/internal/resource/mock_connection_test.go index 381cfe9b..25390175 100644 --- a/internal/resource/mock_connection_test.go +++ b/internal/resource/mock_connection_test.go @@ -189,6 +189,25 @@ func (mock *MockConnection) ValidNamespaces() ([]v1.Namespace, error) { return ret0, ret1 } +func (mock *MockConnection) ValidPods(_param0 string) ([]v1.Pod, error) { + if mock == nil { + panic("mock must not be nil. Use myMock := NewMockConnection().") + } + params := []pegomock.Param{_param0} + result := pegomock.GetGenericMockFrom(mock).Invoke("ValidPods", params, []reflect.Type{reflect.TypeOf((*[]v1.Pod)(nil)).Elem(), reflect.TypeOf((*error)(nil)).Elem()}) + var ret0 []v1.Pod + var ret1 error + if len(result) != 0 { + if result[0] != nil { + ret0 = result[0].([]v1.Pod) + } + if result[1] != nil { + ret1 = result[1].(error) + } + } + return ret0, ret1 +} + func (mock *MockConnection) VerifyWasCalledOnce() *VerifierConnection { return &VerifierConnection{ mock: mock, @@ -442,3 +461,30 @@ func (c *Connection_ValidNamespaces_OngoingVerification) GetCapturedArguments() func (c *Connection_ValidNamespaces_OngoingVerification) GetAllCapturedArguments() { } + +func (verifier *VerifierConnection) ValidPods(_param0 string) *Connection_ValidPods_OngoingVerification { + params := []pegomock.Param{_param0} + methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "ValidPods", params, verifier.timeout) + return &Connection_ValidPods_OngoingVerification{mock: verifier.mock, methodInvocations: methodInvocations} +} + +type Connection_ValidPods_OngoingVerification struct { + mock *MockConnection + methodInvocations []pegomock.MethodInvocation +} + +func (c *Connection_ValidPods_OngoingVerification) GetCapturedArguments() string { + _param0 := c.GetAllCapturedArguments() + return _param0[len(_param0)-1] +} + +func (c *Connection_ValidPods_OngoingVerification) GetAllCapturedArguments() (_param0 []string) { + params := pegomock.GetGenericMockFrom(c.mock).GetInvocationParams(c.methodInvocations) + if len(params) > 0 { + _param0 = make([]string, len(params[0])) + for u, param := range params[0] { + _param0[u] = param.(string) + } + } + return +} diff --git a/internal/resource/mock_metricsservice_test.go b/internal/resource/mock_metricsservice_test.go deleted file mode 100644 index 3b00dd98..00000000 --- a/internal/resource/mock_metricsservice_test.go +++ /dev/null @@ -1,170 +0,0 @@ -// Code generated by pegomock. DO NOT EDIT. -// Source: github.com/derailed/k9s/internal/resource (interfaces: MetricsService) - -package resource_test - -import ( - pegomock "github.com/petergtz/pegomock" - v1beta1 "k8s.io/metrics/pkg/apis/metrics/v1beta1" - "reflect" - "time" -) - -type MockMetricsService struct { - fail func(message string, callerSkip ...int) -} - -func NewMockMetricsService() *MockMetricsService { - return &MockMetricsService{fail: pegomock.GlobalFailHandler} -} - -func (mock *MockMetricsService) FetchNodesMetrics() ([]v1beta1.NodeMetrics, error) { - if mock == nil { - panic("mock must not be nil. Use myMock := NewMockMetricsService().") - } - params := []pegomock.Param{} - result := pegomock.GetGenericMockFrom(mock).Invoke("FetchNodesMetrics", params, []reflect.Type{reflect.TypeOf((*[]v1beta1.NodeMetrics)(nil)).Elem(), reflect.TypeOf((*error)(nil)).Elem()}) - var ret0 []v1beta1.NodeMetrics - var ret1 error - if len(result) != 0 { - if result[0] != nil { - ret0 = result[0].([]v1beta1.NodeMetrics) - } - if result[1] != nil { - ret1 = result[1].(error) - } - } - return ret0, ret1 -} - -func (mock *MockMetricsService) FetchPodsMetrics(_param0 string) ([]v1beta1.PodMetrics, error) { - if mock == nil { - panic("mock must not be nil. Use myMock := NewMockMetricsService().") - } - params := []pegomock.Param{_param0} - result := pegomock.GetGenericMockFrom(mock).Invoke("FetchPodsMetrics", params, []reflect.Type{reflect.TypeOf((*[]v1beta1.PodMetrics)(nil)).Elem(), reflect.TypeOf((*error)(nil)).Elem()}) - var ret0 []v1beta1.PodMetrics - var ret1 error - if len(result) != 0 { - if result[0] != nil { - ret0 = result[0].([]v1beta1.PodMetrics) - } - if result[1] != nil { - ret1 = result[1].(error) - } - } - return ret0, ret1 -} - -func (mock *MockMetricsService) HasMetrics() bool { - if mock == nil { - panic("mock must not be nil. Use myMock := NewMockMetricsService().") - } - params := []pegomock.Param{} - result := pegomock.GetGenericMockFrom(mock).Invoke("HasMetrics", params, []reflect.Type{reflect.TypeOf((*bool)(nil)).Elem()}) - var ret0 bool - if len(result) != 0 { - if result[0] != nil { - ret0 = result[0].(bool) - } - } - return ret0 -} - -func (mock *MockMetricsService) VerifyWasCalledOnce() *VerifierMetricsService { - return &VerifierMetricsService{ - mock: mock, - invocationCountMatcher: pegomock.Times(1), - } -} - -func (mock *MockMetricsService) VerifyWasCalled(invocationCountMatcher pegomock.Matcher) *VerifierMetricsService { - return &VerifierMetricsService{ - mock: mock, - invocationCountMatcher: invocationCountMatcher, - } -} - -func (mock *MockMetricsService) VerifyWasCalledInOrder(invocationCountMatcher pegomock.Matcher, inOrderContext *pegomock.InOrderContext) *VerifierMetricsService { - return &VerifierMetricsService{ - mock: mock, - invocationCountMatcher: invocationCountMatcher, - inOrderContext: inOrderContext, - } -} - -func (mock *MockMetricsService) VerifyWasCalledEventually(invocationCountMatcher pegomock.Matcher, timeout time.Duration) *VerifierMetricsService { - return &VerifierMetricsService{ - mock: mock, - invocationCountMatcher: invocationCountMatcher, - timeout: timeout, - } -} - -type VerifierMetricsService struct { - mock *MockMetricsService - invocationCountMatcher pegomock.Matcher - inOrderContext *pegomock.InOrderContext - timeout time.Duration -} - -func (verifier *VerifierMetricsService) FetchNodesMetrics() *MetricsService_FetchNodesMetrics_OngoingVerification { - params := []pegomock.Param{} - methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "FetchNodesMetrics", params, verifier.timeout) - return &MetricsService_FetchNodesMetrics_OngoingVerification{mock: verifier.mock, methodInvocations: methodInvocations} -} - -type MetricsService_FetchNodesMetrics_OngoingVerification struct { - mock *MockMetricsService - methodInvocations []pegomock.MethodInvocation -} - -func (c *MetricsService_FetchNodesMetrics_OngoingVerification) GetCapturedArguments() { -} - -func (c *MetricsService_FetchNodesMetrics_OngoingVerification) GetAllCapturedArguments() { -} - -func (verifier *VerifierMetricsService) FetchPodsMetrics(_param0 string) *MetricsService_FetchPodsMetrics_OngoingVerification { - params := []pegomock.Param{_param0} - methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "FetchPodsMetrics", params, verifier.timeout) - return &MetricsService_FetchPodsMetrics_OngoingVerification{mock: verifier.mock, methodInvocations: methodInvocations} -} - -type MetricsService_FetchPodsMetrics_OngoingVerification struct { - mock *MockMetricsService - methodInvocations []pegomock.MethodInvocation -} - -func (c *MetricsService_FetchPodsMetrics_OngoingVerification) GetCapturedArguments() string { - _param0 := c.GetAllCapturedArguments() - return _param0[len(_param0)-1] -} - -func (c *MetricsService_FetchPodsMetrics_OngoingVerification) GetAllCapturedArguments() (_param0 []string) { - params := pegomock.GetGenericMockFrom(c.mock).GetInvocationParams(c.methodInvocations) - if len(params) > 0 { - _param0 = make([]string, len(params[0])) - for u, param := range params[0] { - _param0[u] = param.(string) - } - } - return -} - -func (verifier *VerifierMetricsService) HasMetrics() *MetricsService_HasMetrics_OngoingVerification { - params := []pegomock.Param{} - methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "HasMetrics", params, verifier.timeout) - return &MetricsService_HasMetrics_OngoingVerification{mock: verifier.mock, methodInvocations: methodInvocations} -} - -type MetricsService_HasMetrics_OngoingVerification struct { - mock *MockMetricsService - methodInvocations []pegomock.MethodInvocation -} - -func (c *MetricsService_HasMetrics_OngoingVerification) GetCapturedArguments() { -} - -func (c *MetricsService_HasMetrics_OngoingVerification) GetAllCapturedArguments() { -} diff --git a/internal/resource/mock_resource_test.go b/internal/resource/mock_resource_test.go deleted file mode 100644 index 9ba80bae..00000000 --- a/internal/resource/mock_resource_test.go +++ /dev/null @@ -1,375 +0,0 @@ -// Code generated by pegomock. DO NOT EDIT. -// Source: github.com/derailed/k9s/internal/resource (interfaces: Resource) - -package resource_test - -import ( - resource "github.com/derailed/k9s/internal/resource" - pegomock "github.com/petergtz/pegomock" - genericclioptions "k8s.io/cli-runtime/pkg/genericclioptions" - "reflect" - "time" -) - -type MockResource struct { - fail func(message string, callerSkip ...int) -} - -func NewMockResource() *MockResource { - return &MockResource{fail: pegomock.GlobalFailHandler} -} - -func (mock *MockResource) Delete(_param0 string) error { - if mock == nil { - panic("mock must not be nil. Use myMock := NewMockResource().") - } - params := []pegomock.Param{_param0} - result := pegomock.GetGenericMockFrom(mock).Invoke("Delete", params, []reflect.Type{reflect.TypeOf((*error)(nil)).Elem()}) - var ret0 error - if len(result) != 0 { - if result[0] != nil { - ret0 = result[0].(error) - } - } - return ret0 -} - -func (mock *MockResource) Describe(_param0 string, _param1 string, _param2 *genericclioptions.ConfigFlags) (string, error) { - if mock == nil { - panic("mock must not be nil. Use myMock := NewMockResource().") - } - params := []pegomock.Param{_param0, _param1, _param2} - result := pegomock.GetGenericMockFrom(mock).Invoke("Describe", params, []reflect.Type{reflect.TypeOf((*string)(nil)).Elem(), reflect.TypeOf((*error)(nil)).Elem()}) - var ret0 string - var ret1 error - if len(result) != 0 { - if result[0] != nil { - ret0 = result[0].(string) - } - if result[1] != nil { - ret1 = result[1].(error) - } - } - return ret0, ret1 -} - -func (mock *MockResource) Get(_param0 string) (resource.Columnar, error) { - if mock == nil { - panic("mock must not be nil. Use myMock := NewMockResource().") - } - params := []pegomock.Param{_param0} - result := pegomock.GetGenericMockFrom(mock).Invoke("Get", params, []reflect.Type{reflect.TypeOf((*resource.Columnar)(nil)).Elem(), reflect.TypeOf((*error)(nil)).Elem()}) - var ret0 resource.Columnar - var ret1 error - if len(result) != 0 { - if result[0] != nil { - ret0 = result[0].(resource.Columnar) - } - if result[1] != nil { - ret1 = result[1].(error) - } - } - return ret0, ret1 -} - -func (mock *MockResource) Header(_param0 string) resource.Row { - if mock == nil { - panic("mock must not be nil. Use myMock := NewMockResource().") - } - params := []pegomock.Param{_param0} - result := pegomock.GetGenericMockFrom(mock).Invoke("Header", params, []reflect.Type{reflect.TypeOf((*resource.Row)(nil)).Elem()}) - var ret0 resource.Row - if len(result) != 0 { - if result[0] != nil { - ret0 = result[0].(resource.Row) - } - } - return ret0 -} - -func (mock *MockResource) List(_param0 string) (resource.Columnars, error) { - if mock == nil { - panic("mock must not be nil. Use myMock := NewMockResource().") - } - params := []pegomock.Param{_param0} - result := pegomock.GetGenericMockFrom(mock).Invoke("List", params, []reflect.Type{reflect.TypeOf((*resource.Columnars)(nil)).Elem(), reflect.TypeOf((*error)(nil)).Elem()}) - var ret0 resource.Columnars - var ret1 error - if len(result) != 0 { - if result[0] != nil { - ret0 = result[0].(resource.Columnars) - } - if result[1] != nil { - ret1 = result[1].(error) - } - } - return ret0, ret1 -} - -func (mock *MockResource) Marshal(_param0 string) (string, error) { - if mock == nil { - panic("mock must not be nil. Use myMock := NewMockResource().") - } - params := []pegomock.Param{_param0} - result := pegomock.GetGenericMockFrom(mock).Invoke("Marshal", params, []reflect.Type{reflect.TypeOf((*string)(nil)).Elem(), reflect.TypeOf((*error)(nil)).Elem()}) - var ret0 string - var ret1 error - if len(result) != 0 { - if result[0] != nil { - ret0 = result[0].(string) - } - if result[1] != nil { - ret1 = result[1].(error) - } - } - return ret0, ret1 -} - -func (mock *MockResource) New(_param0 interface{}) resource.Columnar { - if mock == nil { - panic("mock must not be nil. Use myMock := NewMockResource().") - } - params := []pegomock.Param{_param0} - result := pegomock.GetGenericMockFrom(mock).Invoke("New", params, []reflect.Type{reflect.TypeOf((*resource.Columnar)(nil)).Elem()}) - var ret0 resource.Columnar - if len(result) != 0 { - if result[0] != nil { - ret0 = result[0].(resource.Columnar) - } - } - return ret0 -} - -func (mock *MockResource) VerifyWasCalledOnce() *VerifierResource { - return &VerifierResource{ - mock: mock, - invocationCountMatcher: pegomock.Times(1), - } -} - -func (mock *MockResource) VerifyWasCalled(invocationCountMatcher pegomock.Matcher) *VerifierResource { - return &VerifierResource{ - mock: mock, - invocationCountMatcher: invocationCountMatcher, - } -} - -func (mock *MockResource) VerifyWasCalledInOrder(invocationCountMatcher pegomock.Matcher, inOrderContext *pegomock.InOrderContext) *VerifierResource { - return &VerifierResource{ - mock: mock, - invocationCountMatcher: invocationCountMatcher, - inOrderContext: inOrderContext, - } -} - -func (mock *MockResource) VerifyWasCalledEventually(invocationCountMatcher pegomock.Matcher, timeout time.Duration) *VerifierResource { - return &VerifierResource{ - mock: mock, - invocationCountMatcher: invocationCountMatcher, - timeout: timeout, - } -} - -type VerifierResource struct { - mock *MockResource - invocationCountMatcher pegomock.Matcher - inOrderContext *pegomock.InOrderContext - timeout time.Duration -} - -func (verifier *VerifierResource) Delete(_param0 string) *Resource_Delete_OngoingVerification { - params := []pegomock.Param{_param0} - methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "Delete", params, verifier.timeout) - return &Resource_Delete_OngoingVerification{mock: verifier.mock, methodInvocations: methodInvocations} -} - -type Resource_Delete_OngoingVerification struct { - mock *MockResource - methodInvocations []pegomock.MethodInvocation -} - -func (c *Resource_Delete_OngoingVerification) GetCapturedArguments() string { - _param0 := c.GetAllCapturedArguments() - return _param0[len(_param0)-1] -} - -func (c *Resource_Delete_OngoingVerification) GetAllCapturedArguments() (_param0 []string) { - params := pegomock.GetGenericMockFrom(c.mock).GetInvocationParams(c.methodInvocations) - if len(params) > 0 { - _param0 = make([]string, len(params[0])) - for u, param := range params[0] { - _param0[u] = param.(string) - } - } - return -} - -func (verifier *VerifierResource) Describe(_param0 string, _param1 string, _param2 *genericclioptions.ConfigFlags) *Resource_Describe_OngoingVerification { - params := []pegomock.Param{_param0, _param1, _param2} - methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "Describe", params, verifier.timeout) - return &Resource_Describe_OngoingVerification{mock: verifier.mock, methodInvocations: methodInvocations} -} - -type Resource_Describe_OngoingVerification struct { - mock *MockResource - methodInvocations []pegomock.MethodInvocation -} - -func (c *Resource_Describe_OngoingVerification) GetCapturedArguments() (string, string, *genericclioptions.ConfigFlags) { - _param0, _param1, _param2 := c.GetAllCapturedArguments() - return _param0[len(_param0)-1], _param1[len(_param1)-1], _param2[len(_param2)-1] -} - -func (c *Resource_Describe_OngoingVerification) GetAllCapturedArguments() (_param0 []string, _param1 []string, _param2 []*genericclioptions.ConfigFlags) { - params := pegomock.GetGenericMockFrom(c.mock).GetInvocationParams(c.methodInvocations) - if len(params) > 0 { - _param0 = make([]string, len(params[0])) - for u, param := range params[0] { - _param0[u] = param.(string) - } - _param1 = make([]string, len(params[1])) - for u, param := range params[1] { - _param1[u] = param.(string) - } - _param2 = make([]*genericclioptions.ConfigFlags, len(params[2])) - for u, param := range params[2] { - _param2[u] = param.(*genericclioptions.ConfigFlags) - } - } - return -} - -func (verifier *VerifierResource) Get(_param0 string) *Resource_Get_OngoingVerification { - params := []pegomock.Param{_param0} - methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "Get", params, verifier.timeout) - return &Resource_Get_OngoingVerification{mock: verifier.mock, methodInvocations: methodInvocations} -} - -type Resource_Get_OngoingVerification struct { - mock *MockResource - methodInvocations []pegomock.MethodInvocation -} - -func (c *Resource_Get_OngoingVerification) GetCapturedArguments() string { - _param0 := c.GetAllCapturedArguments() - return _param0[len(_param0)-1] -} - -func (c *Resource_Get_OngoingVerification) GetAllCapturedArguments() (_param0 []string) { - params := pegomock.GetGenericMockFrom(c.mock).GetInvocationParams(c.methodInvocations) - if len(params) > 0 { - _param0 = make([]string, len(params[0])) - for u, param := range params[0] { - _param0[u] = param.(string) - } - } - return -} - -func (verifier *VerifierResource) Header(_param0 string) *Resource_Header_OngoingVerification { - params := []pegomock.Param{_param0} - methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "Header", params, verifier.timeout) - return &Resource_Header_OngoingVerification{mock: verifier.mock, methodInvocations: methodInvocations} -} - -type Resource_Header_OngoingVerification struct { - mock *MockResource - methodInvocations []pegomock.MethodInvocation -} - -func (c *Resource_Header_OngoingVerification) GetCapturedArguments() string { - _param0 := c.GetAllCapturedArguments() - return _param0[len(_param0)-1] -} - -func (c *Resource_Header_OngoingVerification) GetAllCapturedArguments() (_param0 []string) { - params := pegomock.GetGenericMockFrom(c.mock).GetInvocationParams(c.methodInvocations) - if len(params) > 0 { - _param0 = make([]string, len(params[0])) - for u, param := range params[0] { - _param0[u] = param.(string) - } - } - return -} - -func (verifier *VerifierResource) List(_param0 string) *Resource_List_OngoingVerification { - params := []pegomock.Param{_param0} - methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "List", params, verifier.timeout) - return &Resource_List_OngoingVerification{mock: verifier.mock, methodInvocations: methodInvocations} -} - -type Resource_List_OngoingVerification struct { - mock *MockResource - methodInvocations []pegomock.MethodInvocation -} - -func (c *Resource_List_OngoingVerification) GetCapturedArguments() string { - _param0 := c.GetAllCapturedArguments() - return _param0[len(_param0)-1] -} - -func (c *Resource_List_OngoingVerification) GetAllCapturedArguments() (_param0 []string) { - params := pegomock.GetGenericMockFrom(c.mock).GetInvocationParams(c.methodInvocations) - if len(params) > 0 { - _param0 = make([]string, len(params[0])) - for u, param := range params[0] { - _param0[u] = param.(string) - } - } - return -} - -func (verifier *VerifierResource) Marshal(_param0 string) *Resource_Marshal_OngoingVerification { - params := []pegomock.Param{_param0} - methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "Marshal", params, verifier.timeout) - return &Resource_Marshal_OngoingVerification{mock: verifier.mock, methodInvocations: methodInvocations} -} - -type Resource_Marshal_OngoingVerification struct { - mock *MockResource - methodInvocations []pegomock.MethodInvocation -} - -func (c *Resource_Marshal_OngoingVerification) GetCapturedArguments() string { - _param0 := c.GetAllCapturedArguments() - return _param0[len(_param0)-1] -} - -func (c *Resource_Marshal_OngoingVerification) GetAllCapturedArguments() (_param0 []string) { - params := pegomock.GetGenericMockFrom(c.mock).GetInvocationParams(c.methodInvocations) - if len(params) > 0 { - _param0 = make([]string, len(params[0])) - for u, param := range params[0] { - _param0[u] = param.(string) - } - } - return -} - -func (verifier *VerifierResource) New(_param0 interface{}) *Resource_New_OngoingVerification { - params := []pegomock.Param{_param0} - methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "New", params, verifier.timeout) - return &Resource_New_OngoingVerification{mock: verifier.mock, methodInvocations: methodInvocations} -} - -type Resource_New_OngoingVerification struct { - mock *MockResource - methodInvocations []pegomock.MethodInvocation -} - -func (c *Resource_New_OngoingVerification) GetCapturedArguments() interface{} { - _param0 := c.GetAllCapturedArguments() - return _param0[len(_param0)-1] -} - -func (c *Resource_New_OngoingVerification) GetAllCapturedArguments() (_param0 []interface{}) { - params := pegomock.GetGenericMockFrom(c.mock).GetInvocationParams(c.methodInvocations) - if len(params) > 0 { - _param0 = make([]interface{}, len(params[0])) - for u, param := range params[0] { - _param0[u] = param.(interface{}) - } - } - return -} diff --git a/internal/resource/mock_switchableresource_test.go b/internal/resource/mock_switchablecruder_test.go similarity index 56% rename from internal/resource/mock_switchableresource_test.go rename to internal/resource/mock_switchablecruder_test.go index f0dc7bc8..e49e245e 100644 --- a/internal/resource/mock_switchableresource_test.go +++ b/internal/resource/mock_switchablecruder_test.go @@ -1,5 +1,5 @@ // Code generated by pegomock. DO NOT EDIT. -// Source: github.com/derailed/k9s/internal/resource (interfaces: SwitchableResource) +// Source: github.com/derailed/k9s/internal/resource (interfaces: SwitchableCruder) package resource_test @@ -10,17 +10,17 @@ import ( "time" ) -type MockSwitchableResource struct { +type MockSwitchableCruder struct { fail func(message string, callerSkip ...int) } -func NewMockSwitchableResource() *MockSwitchableResource { - return &MockSwitchableResource{fail: pegomock.GlobalFailHandler} +func NewMockSwitchableCruder() *MockSwitchableCruder { + return &MockSwitchableCruder{fail: pegomock.GlobalFailHandler} } -func (mock *MockSwitchableResource) Delete(_param0 string, _param1 string) error { +func (mock *MockSwitchableCruder) Delete(_param0 string, _param1 string) error { if mock == nil { - panic("mock must not be nil. Use myMock := NewMockSwitchableResource().") + panic("mock must not be nil. Use myMock := NewMockSwitchableCruder().") } params := []pegomock.Param{_param0, _param1} result := pegomock.GetGenericMockFrom(mock).Invoke("Delete", params, []reflect.Type{reflect.TypeOf((*error)(nil)).Elem()}) @@ -33,9 +33,9 @@ func (mock *MockSwitchableResource) Delete(_param0 string, _param1 string) error return ret0 } -func (mock *MockSwitchableResource) Get(_param0 string, _param1 string) (interface{}, error) { +func (mock *MockSwitchableCruder) Get(_param0 string, _param1 string) (interface{}, error) { if mock == nil { - panic("mock must not be nil. Use myMock := NewMockSwitchableResource().") + panic("mock must not be nil. Use myMock := NewMockSwitchableCruder().") } params := []pegomock.Param{_param0, _param1} result := pegomock.GetGenericMockFrom(mock).Invoke("Get", params, []reflect.Type{reflect.TypeOf((*interface{})(nil)).Elem(), reflect.TypeOf((*error)(nil)).Elem()}) @@ -52,9 +52,9 @@ func (mock *MockSwitchableResource) Get(_param0 string, _param1 string) (interfa return ret0, ret1 } -func (mock *MockSwitchableResource) List(_param0 string) (k8s.Collection, error) { +func (mock *MockSwitchableCruder) List(_param0 string) (k8s.Collection, error) { if mock == nil { - panic("mock must not be nil. Use myMock := NewMockSwitchableResource().") + panic("mock must not be nil. Use myMock := NewMockSwitchableCruder().") } params := []pegomock.Param{_param0} result := pegomock.GetGenericMockFrom(mock).Invoke("List", params, []reflect.Type{reflect.TypeOf((*k8s.Collection)(nil)).Elem(), reflect.TypeOf((*error)(nil)).Elem()}) @@ -71,9 +71,9 @@ func (mock *MockSwitchableResource) List(_param0 string) (k8s.Collection, error) return ret0, ret1 } -func (mock *MockSwitchableResource) MustCurrentContextName() string { +func (mock *MockSwitchableCruder) MustCurrentContextName() string { if mock == nil { - panic("mock must not be nil. Use myMock := NewMockSwitchableResource().") + panic("mock must not be nil. Use myMock := NewMockSwitchableCruder().") } params := []pegomock.Param{} result := pegomock.GetGenericMockFrom(mock).Invoke("MustCurrentContextName", params, []reflect.Type{reflect.TypeOf((*string)(nil)).Elem()}) @@ -86,9 +86,9 @@ func (mock *MockSwitchableResource) MustCurrentContextName() string { return ret0 } -func (mock *MockSwitchableResource) Switch(_param0 string) error { +func (mock *MockSwitchableCruder) Switch(_param0 string) error { if mock == nil { - panic("mock must not be nil. Use myMock := NewMockSwitchableResource().") + panic("mock must not be nil. Use myMock := NewMockSwitchableCruder().") } params := []pegomock.Param{_param0} result := pegomock.GetGenericMockFrom(mock).Invoke("Switch", params, []reflect.Type{reflect.TypeOf((*error)(nil)).Elem()}) @@ -101,60 +101,60 @@ func (mock *MockSwitchableResource) Switch(_param0 string) error { return ret0 } -func (mock *MockSwitchableResource) VerifyWasCalledOnce() *VerifierSwitchableResource { - return &VerifierSwitchableResource{ +func (mock *MockSwitchableCruder) VerifyWasCalledOnce() *VerifierSwitchableCruder { + return &VerifierSwitchableCruder{ mock: mock, invocationCountMatcher: pegomock.Times(1), } } -func (mock *MockSwitchableResource) VerifyWasCalled(invocationCountMatcher pegomock.Matcher) *VerifierSwitchableResource { - return &VerifierSwitchableResource{ +func (mock *MockSwitchableCruder) VerifyWasCalled(invocationCountMatcher pegomock.Matcher) *VerifierSwitchableCruder { + return &VerifierSwitchableCruder{ mock: mock, invocationCountMatcher: invocationCountMatcher, } } -func (mock *MockSwitchableResource) VerifyWasCalledInOrder(invocationCountMatcher pegomock.Matcher, inOrderContext *pegomock.InOrderContext) *VerifierSwitchableResource { - return &VerifierSwitchableResource{ +func (mock *MockSwitchableCruder) VerifyWasCalledInOrder(invocationCountMatcher pegomock.Matcher, inOrderContext *pegomock.InOrderContext) *VerifierSwitchableCruder { + return &VerifierSwitchableCruder{ mock: mock, invocationCountMatcher: invocationCountMatcher, inOrderContext: inOrderContext, } } -func (mock *MockSwitchableResource) VerifyWasCalledEventually(invocationCountMatcher pegomock.Matcher, timeout time.Duration) *VerifierSwitchableResource { - return &VerifierSwitchableResource{ +func (mock *MockSwitchableCruder) VerifyWasCalledEventually(invocationCountMatcher pegomock.Matcher, timeout time.Duration) *VerifierSwitchableCruder { + return &VerifierSwitchableCruder{ mock: mock, invocationCountMatcher: invocationCountMatcher, timeout: timeout, } } -type VerifierSwitchableResource struct { - mock *MockSwitchableResource +type VerifierSwitchableCruder struct { + mock *MockSwitchableCruder invocationCountMatcher pegomock.Matcher inOrderContext *pegomock.InOrderContext timeout time.Duration } -func (verifier *VerifierSwitchableResource) Delete(_param0 string, _param1 string) *SwitchableResource_Delete_OngoingVerification { +func (verifier *VerifierSwitchableCruder) Delete(_param0 string, _param1 string) *SwitchableCruder_Delete_OngoingVerification { params := []pegomock.Param{_param0, _param1} methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "Delete", params, verifier.timeout) - return &SwitchableResource_Delete_OngoingVerification{mock: verifier.mock, methodInvocations: methodInvocations} + return &SwitchableCruder_Delete_OngoingVerification{mock: verifier.mock, methodInvocations: methodInvocations} } -type SwitchableResource_Delete_OngoingVerification struct { - mock *MockSwitchableResource +type SwitchableCruder_Delete_OngoingVerification struct { + mock *MockSwitchableCruder methodInvocations []pegomock.MethodInvocation } -func (c *SwitchableResource_Delete_OngoingVerification) GetCapturedArguments() (string, string) { +func (c *SwitchableCruder_Delete_OngoingVerification) GetCapturedArguments() (string, string) { _param0, _param1 := c.GetAllCapturedArguments() return _param0[len(_param0)-1], _param1[len(_param1)-1] } -func (c *SwitchableResource_Delete_OngoingVerification) GetAllCapturedArguments() (_param0 []string, _param1 []string) { +func (c *SwitchableCruder_Delete_OngoingVerification) GetAllCapturedArguments() (_param0 []string, _param1 []string) { params := pegomock.GetGenericMockFrom(c.mock).GetInvocationParams(c.methodInvocations) if len(params) > 0 { _param0 = make([]string, len(params[0])) @@ -169,23 +169,23 @@ func (c *SwitchableResource_Delete_OngoingVerification) GetAllCapturedArguments( return } -func (verifier *VerifierSwitchableResource) Get(_param0 string, _param1 string) *SwitchableResource_Get_OngoingVerification { +func (verifier *VerifierSwitchableCruder) Get(_param0 string, _param1 string) *SwitchableCruder_Get_OngoingVerification { params := []pegomock.Param{_param0, _param1} methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "Get", params, verifier.timeout) - return &SwitchableResource_Get_OngoingVerification{mock: verifier.mock, methodInvocations: methodInvocations} + return &SwitchableCruder_Get_OngoingVerification{mock: verifier.mock, methodInvocations: methodInvocations} } -type SwitchableResource_Get_OngoingVerification struct { - mock *MockSwitchableResource +type SwitchableCruder_Get_OngoingVerification struct { + mock *MockSwitchableCruder methodInvocations []pegomock.MethodInvocation } -func (c *SwitchableResource_Get_OngoingVerification) GetCapturedArguments() (string, string) { +func (c *SwitchableCruder_Get_OngoingVerification) GetCapturedArguments() (string, string) { _param0, _param1 := c.GetAllCapturedArguments() return _param0[len(_param0)-1], _param1[len(_param1)-1] } -func (c *SwitchableResource_Get_OngoingVerification) GetAllCapturedArguments() (_param0 []string, _param1 []string) { +func (c *SwitchableCruder_Get_OngoingVerification) GetAllCapturedArguments() (_param0 []string, _param1 []string) { params := pegomock.GetGenericMockFrom(c.mock).GetInvocationParams(c.methodInvocations) if len(params) > 0 { _param0 = make([]string, len(params[0])) @@ -200,23 +200,23 @@ func (c *SwitchableResource_Get_OngoingVerification) GetAllCapturedArguments() ( return } -func (verifier *VerifierSwitchableResource) List(_param0 string) *SwitchableResource_List_OngoingVerification { +func (verifier *VerifierSwitchableCruder) List(_param0 string) *SwitchableCruder_List_OngoingVerification { params := []pegomock.Param{_param0} methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "List", params, verifier.timeout) - return &SwitchableResource_List_OngoingVerification{mock: verifier.mock, methodInvocations: methodInvocations} + return &SwitchableCruder_List_OngoingVerification{mock: verifier.mock, methodInvocations: methodInvocations} } -type SwitchableResource_List_OngoingVerification struct { - mock *MockSwitchableResource +type SwitchableCruder_List_OngoingVerification struct { + mock *MockSwitchableCruder methodInvocations []pegomock.MethodInvocation } -func (c *SwitchableResource_List_OngoingVerification) GetCapturedArguments() string { +func (c *SwitchableCruder_List_OngoingVerification) GetCapturedArguments() string { _param0 := c.GetAllCapturedArguments() return _param0[len(_param0)-1] } -func (c *SwitchableResource_List_OngoingVerification) GetAllCapturedArguments() (_param0 []string) { +func (c *SwitchableCruder_List_OngoingVerification) GetAllCapturedArguments() (_param0 []string) { params := pegomock.GetGenericMockFrom(c.mock).GetInvocationParams(c.methodInvocations) if len(params) > 0 { _param0 = make([]string, len(params[0])) @@ -227,40 +227,40 @@ func (c *SwitchableResource_List_OngoingVerification) GetAllCapturedArguments() return } -func (verifier *VerifierSwitchableResource) MustCurrentContextName() *SwitchableResource_MustCurrentContextName_OngoingVerification { +func (verifier *VerifierSwitchableCruder) MustCurrentContextName() *SwitchableCruder_MustCurrentContextName_OngoingVerification { params := []pegomock.Param{} methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "MustCurrentContextName", params, verifier.timeout) - return &SwitchableResource_MustCurrentContextName_OngoingVerification{mock: verifier.mock, methodInvocations: methodInvocations} + return &SwitchableCruder_MustCurrentContextName_OngoingVerification{mock: verifier.mock, methodInvocations: methodInvocations} } -type SwitchableResource_MustCurrentContextName_OngoingVerification struct { - mock *MockSwitchableResource +type SwitchableCruder_MustCurrentContextName_OngoingVerification struct { + mock *MockSwitchableCruder methodInvocations []pegomock.MethodInvocation } -func (c *SwitchableResource_MustCurrentContextName_OngoingVerification) GetCapturedArguments() { +func (c *SwitchableCruder_MustCurrentContextName_OngoingVerification) GetCapturedArguments() { } -func (c *SwitchableResource_MustCurrentContextName_OngoingVerification) GetAllCapturedArguments() { +func (c *SwitchableCruder_MustCurrentContextName_OngoingVerification) GetAllCapturedArguments() { } -func (verifier *VerifierSwitchableResource) Switch(_param0 string) *SwitchableResource_Switch_OngoingVerification { +func (verifier *VerifierSwitchableCruder) Switch(_param0 string) *SwitchableCruder_Switch_OngoingVerification { params := []pegomock.Param{_param0} methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "Switch", params, verifier.timeout) - return &SwitchableResource_Switch_OngoingVerification{mock: verifier.mock, methodInvocations: methodInvocations} + return &SwitchableCruder_Switch_OngoingVerification{mock: verifier.mock, methodInvocations: methodInvocations} } -type SwitchableResource_Switch_OngoingVerification struct { - mock *MockSwitchableResource +type SwitchableCruder_Switch_OngoingVerification struct { + mock *MockSwitchableCruder methodInvocations []pegomock.MethodInvocation } -func (c *SwitchableResource_Switch_OngoingVerification) GetCapturedArguments() string { +func (c *SwitchableCruder_Switch_OngoingVerification) GetCapturedArguments() string { _param0 := c.GetAllCapturedArguments() return _param0[len(_param0)-1] } -func (c *SwitchableResource_Switch_OngoingVerification) GetAllCapturedArguments() (_param0 []string) { +func (c *SwitchableCruder_Switch_OngoingVerification) GetAllCapturedArguments() (_param0 []string) { params := pegomock.GetGenericMockFrom(c.mock).GetInvocationParams(c.methodInvocations) if len(params) > 0 { _param0 = make([]string, len(params[0])) diff --git a/internal/resource/no.go b/internal/resource/no.go index f02b9e00..89fb9ec4 100644 --- a/internal/resource/no.go +++ b/internal/resource/no.go @@ -3,11 +3,12 @@ package resource import ( "strings" - "k8s.io/apimachinery/pkg/util/sets" - "github.com/derailed/k9s/internal/k8s" "github.com/rs/zerolog/log" v1 "k8s.io/api/core/v1" + "k8s.io/apimachinery/pkg/api/errors" + "k8s.io/apimachinery/pkg/api/resource" + "k8s.io/apimachinery/pkg/util/sets" ) const ( @@ -106,17 +107,20 @@ func (*Node) Header(ns string) Row { return Row{ "NAME", "STATUS", - "ROLES", "VERSION", "KERNEL", "INTERNAL-IP", "EXTERNAL-IP", + "CPU%", + "MEM%", + "RCPU%", + "RMEM%", "CPU", "MEM", - "AVA CPU", - "AVA MEM", - "CAP CPU", - "CAP MEM", + "RMEM", + "RCPU", + "ACPU", + "AMEM", "AGE", } } @@ -124,25 +128,48 @@ func (*Node) Header(ns string) Row { // Fields returns displayable fields. func (r *Node) Fields(ns string) Row { ff := make(Row, 0, len(r.Header(ns))) - i := r.instance + i := r.instance iIP, eIP := r.getIPs(i.Status.Addresses) iIP, eIP = missing(iIP), missing(eIP) + reqs, _, err := r.fetchReqLimit(i.Name) + if err != nil { + if !errors.IsForbidden(err) { + log.Warn().Msgf("User is not authorized to list pods on nodes: %v", err) + } + log.Error().Msgf("%#v", err) + } + + rcpu, rmem := reqs["cpu"], reqs["memory"] + + var pcpur float64 + if r.metrics.AvailCPU > 0 { + pcpur = toPerc(float64(rcpu.MilliValue()), float64(r.metrics.AvailCPU)) + } + + var pmemr float64 + if r.metrics.AvailMEM > 0 { + pmemr = toPerc(float64(rmem.Value()/(1024*1024)), float64(r.metrics.AvailMEM)) + } + return append(ff, i.Name, r.status(i), - missing(strings.Join(findNodeRoles(i), ",")), i.Status.NodeInfo.KubeletVersion, i.Status.NodeInfo.KernelVersion, iIP, eIP, + asPerc(toPerc(float64(r.metrics.CurrentCPU), float64(r.metrics.AvailCPU))), + asPerc(toPerc(r.metrics.CurrentMEM, r.metrics.AvailMEM)), + asPerc(pcpur), + asPerc(pmemr), ToMillicore(r.metrics.CurrentCPU), ToMi(r.metrics.CurrentMEM), ToMillicore(r.metrics.AvailCPU), ToMi(r.metrics.AvailMEM), - ToMillicore(r.metrics.TotalCPU), - ToMi(r.metrics.TotalMEM), + rcpu.String(), + rmem.String(), toAge(i.ObjectMeta.CreationTimestamp), ) } @@ -205,3 +232,72 @@ func findNodeRoles(i *v1.Node) []string { return roles.List() } + +func (r *Node) fetchReqLimit(name string) (req, lim v1.ResourceList, err error) { + reqs, limits := map[v1.ResourceName]resource.Quantity{}, map[v1.ResourceName]resource.Quantity{} + + pods, err := r.Connection.ValidPods(name) + for _, p := range pods { + preq, plim := podRequestsAndLimits(&p) + for k, v := range preq { + if value, ok := reqs[k]; !ok { + reqs[k] = *v.Copy() + } else { + value.Add(v) + reqs[k] = value + } + } + for k, v := range plim { + if value, ok := limits[k]; !ok { + limits[k] = *v.Copy() + } else { + value.Add(v) + limits[k] = value + } + } + } + + return reqs, limits, nil +} + +func podRequestsAndLimits(pod *v1.Pod) (reqs, limits v1.ResourceList) { + reqs, limits = map[v1.ResourceName]resource.Quantity{}, map[v1.ResourceName]resource.Quantity{} + + for _, container := range pod.Spec.Containers { + addResourceList(reqs, container.Resources.Requests) + addResourceList(limits, container.Resources.Limits) + } + // init containers define the minimum of any resource + for _, container := range pod.Spec.InitContainers { + maxResourceList(reqs, container.Resources.Requests) + maxResourceList(limits, container.Resources.Limits) + } + return +} + +// addResourceList adds the resources in newList to list +func addResourceList(list, new v1.ResourceList) { + for name, quantity := range new { + if value, ok := list[name]; !ok { + list[name] = *quantity.Copy() + } else { + value.Add(quantity) + list[name] = value + } + } +} + +// maxResourceList sets list to the greater of list/newList for every resource +// either list +func maxResourceList(list, new v1.ResourceList) { + for name, quantity := range new { + if value, ok := list[name]; !ok { + list[name] = *quantity.Copy() + continue + } else { + if quantity.Cmp(value) > 0 { + list[name] = *quantity.Copy() + } + } + } +} diff --git a/internal/resource/no_test.go b/internal/resource/no_test.go index fe19330b..f4fabb1d 100644 --- a/internal/resource/no_test.go +++ b/internal/resource/no_test.go @@ -81,7 +81,7 @@ func TestNodeListData(t *testing.T) { assert.Equal(t, resource.NotNamespaced, l.GetNamespace()) row, ok := td.Rows["fred"] assert.True(t, ok) - assert.Equal(t, 14, len(row.Deltas)) + assert.Equal(t, 17, len(row.Deltas)) for _, d := range row.Deltas { assert.Equal(t, "", d) } diff --git a/internal/views/no.go b/internal/views/no.go index b339057d..0be37178 100644 --- a/internal/views/no.go +++ b/internal/views/no.go @@ -20,8 +20,12 @@ func newNodeView(t string, app *appView, list resource.List, c colorerFn) resour } func (v *nodeView) extraActions(aa keyActions) { - aa[KeyShiftC] = newKeyAction("Sort CPU", v.sortColCmd(7, false), true) - aa[KeyShiftM] = newKeyAction("Sort MEM", v.sortColCmd(8, false), true) + aa[KeyShiftQ] = newKeyAction("Sort CPU%", v.sortColCmd(6, false), true) + aa[KeyShiftW] = newKeyAction("Sort MEM%", v.sortColCmd(7, false), true) + aa[KeyShiftA] = newKeyAction("Sort RCPU%", v.sortColCmd(8, false), true) + aa[KeyShiftS] = newKeyAction("Sort RMEM%", v.sortColCmd(9, false), true) + aa[KeyShiftC] = newKeyAction("Sort CPU", v.sortColCmd(10, false), true) + aa[KeyShiftM] = newKeyAction("Sort MEM", v.sortColCmd(11, false), true) } func (v *nodeView) sortColCmd(col int, asc bool) func(evt *tcell.EventKey) *tcell.EventKey {