diff --git a/README.md b/README.md index 8a1de3f6..57797a3c 100644 --- a/README.md +++ b/README.md @@ -217,8 +217,7 @@ K9s uses aliases to navigate most K8s resources. ## K9s RBAC FU -On RBAC enabled clusters, you would need to give your users/groups capabilities so that they can use K9s to explore Kubernetes cluster. -K9s needs minimaly read privileges at both the cluster and namespace level to display resources and metrics. +On RBAC enabled clusters, you would need to give your users/groups capabilities so that they can use K9s to explore their Kubernetes cluster. K9s needs minimaly read privileges at both the cluster and namespace level to display resources and metrics. These rules below are just suggestions. You will need to customize them based on your environment policies. If you need to edit/delete resources extra Fu will be necessary. @@ -248,10 +247,10 @@ rules: - apiGroups: ["apiextensions.k8s.io"] resources: ["customresourcedefinitions"] verbs: ["get", "list", "watch"] - # Grants RO access to netric server + # Grants RO access to metric server - apiGroups: ["metrics.k8s.io"] resources: ["nodes", "pods"] - verbs: ["list"] + verbs: ["get", "list", "watch"] --- # Sample K9s user ClusterRoleBinding @@ -286,6 +285,13 @@ rules: - apiGroups: ["", "apps", "autoscaling", "batch", "extensions"] resources: ["*"] verbs: ["get", "list", "watch"] + # Grants RO access to metric server + - apiGroups: ["metrics.k8s.io"] + resources: ["pods"] + verbs: + - get + - list + - watch --- # Sample K9s user RoleBinding diff --git a/internal/config/mock_connection_test.go b/internal/config/mock_connection_test.go index 71c22759..05f5ae5b 100644 --- a/internal/config/mock_connection_test.go +++ b/internal/config/mock_connection_test.go @@ -24,23 +24,34 @@ func NewMockConnection() *MockConnection { return &MockConnection{fail: pegomock.GlobalFailHandler} } -func (mock *MockConnection) CanIAccess(_param0 string, _param1 string, _param2 string, _param3 []string) (bool, error) { +func (mock *MockConnection) CheckListNSAccess() error { if mock == nil { panic("mock must not be nil. Use myMock := NewMockConnection().") } - params := []pegomock.Param{_param0, _param1, _param2, _param3} - result := pegomock.GetGenericMockFrom(mock).Invoke("CanIAccess", params, []reflect.Type{reflect.TypeOf((*bool)(nil)).Elem(), reflect.TypeOf((*error)(nil)).Elem()}) - var ret0 bool - var ret1 error + params := []pegomock.Param{} + result := pegomock.GetGenericMockFrom(mock).Invoke("CheckListNSAccess", params, []reflect.Type{reflect.TypeOf((*error)(nil)).Elem()}) + var ret0 error if len(result) != 0 { if result[0] != nil { - ret0 = result[0].(bool) - } - if result[1] != nil { - ret1 = result[1].(error) + ret0 = result[0].(error) } } - return ret0, ret1 + return ret0 +} + +func (mock *MockConnection) CheckNSAccess(_param0 string) error { + if mock == nil { + panic("mock must not be nil. Use myMock := NewMockConnection().") + } + params := []pegomock.Param{_param0} + result := pegomock.GetGenericMockFrom(mock).Invoke("CheckNSAccess", 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 *MockConnection) Config() *k8s.Config { @@ -345,41 +356,46 @@ type VerifierConnection struct { timeout time.Duration } -func (verifier *VerifierConnection) CanIAccess(_param0 string, _param1 string, _param2 string, _param3 []string) *Connection_CanIAccess_OngoingVerification { - params := []pegomock.Param{_param0, _param1, _param2, _param3} - methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "CanIAccess", params, verifier.timeout) - return &Connection_CanIAccess_OngoingVerification{mock: verifier.mock, methodInvocations: methodInvocations} +func (verifier *VerifierConnection) CheckListNSAccess() *Connection_CheckListNSAccess_OngoingVerification { + params := []pegomock.Param{} + methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "CheckListNSAccess", params, verifier.timeout) + return &Connection_CheckListNSAccess_OngoingVerification{mock: verifier.mock, methodInvocations: methodInvocations} } -type Connection_CanIAccess_OngoingVerification struct { +type Connection_CheckListNSAccess_OngoingVerification struct { mock *MockConnection methodInvocations []pegomock.MethodInvocation } -func (c *Connection_CanIAccess_OngoingVerification) GetCapturedArguments() (string, string, string, []string) { - _param0, _param1, _param2, _param3 := c.GetAllCapturedArguments() - return _param0[len(_param0)-1], _param1[len(_param1)-1], _param2[len(_param2)-1], _param3[len(_param3)-1] +func (c *Connection_CheckListNSAccess_OngoingVerification) GetCapturedArguments() { } -func (c *Connection_CanIAccess_OngoingVerification) GetAllCapturedArguments() (_param0 []string, _param1 []string, _param2 []string, _param3 [][]string) { +func (c *Connection_CheckListNSAccess_OngoingVerification) GetAllCapturedArguments() { +} + +func (verifier *VerifierConnection) CheckNSAccess(_param0 string) *Connection_CheckNSAccess_OngoingVerification { + params := []pegomock.Param{_param0} + methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "CheckNSAccess", params, verifier.timeout) + return &Connection_CheckNSAccess_OngoingVerification{mock: verifier.mock, methodInvocations: methodInvocations} +} + +type Connection_CheckNSAccess_OngoingVerification struct { + mock *MockConnection + methodInvocations []pegomock.MethodInvocation +} + +func (c *Connection_CheckNSAccess_OngoingVerification) GetCapturedArguments() string { + _param0 := c.GetAllCapturedArguments() + return _param0[len(_param0)-1] +} + +func (c *Connection_CheckNSAccess_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) } - _param1 = make([]string, len(params[1])) - for u, param := range params[1] { - _param1[u] = param.(string) - } - _param2 = make([]string, len(params[2])) - for u, param := range params[2] { - _param2[u] = param.(string) - } - _param3 = make([][]string, len(params[3])) - for u, param := range params[3] { - _param3[u] = param.([]string) - } } return } diff --git a/internal/k8s/api.go b/internal/k8s/api.go index 0c2fdd84..d9d919e1 100644 --- a/internal/k8s/api.go +++ b/internal/k8s/api.go @@ -64,7 +64,8 @@ type ( ServerVersion() (*version.Info, error) FetchNodes() (*v1.NodeList, error) CurrentNamespaceName() (string, error) - CanIAccess(ns, name, resURL string, verbs []string) (bool, error) + CheckNSAccess(ns string) error + CheckListNSAccess() error } // APIClient represents a Kubernetes api client. @@ -89,8 +90,27 @@ func InitConnectionOrDie(config *Config, logger zerolog.Logger) *APIClient { return &conn } +// CheckListNSAccess check if current user can list namespaces. +func (a *APIClient) CheckListNSAccess() error { + ns := NewNamespace(a) + _, err := ns.List("") + return err +} + +// CheckNSAccess asserts if user can access a namespace. +func (a *APIClient) CheckNSAccess(n string) error { + ns := NewNamespace(a) + if n == "" { + _, err := ns.List(n) + return err + } + + _, err := ns.Get("", n) + return err +} + // CanIAccess checks if user has access to a certain resource. -func (a *APIClient) CanIAccess(ns, name, resURL string, verbs []string) (bool, error) { +func (a *APIClient) canIAccess(ns, name, resURL string, verbs []string) (bool, error) { _, gr := schema.ParseResourceArg(strings.ToLower(resURL)) sar := &authorizationv1.SelfSubjectAccessReview{ Spec: authorizationv1.SelfSubjectAccessReviewSpec{ diff --git a/internal/resource/mock_clustermeta_test.go b/internal/resource/mock_clustermeta_test.go index 1ac19356..f314416f 100644 --- a/internal/resource/mock_clustermeta_test.go +++ b/internal/resource/mock_clustermeta_test.go @@ -24,23 +24,34 @@ func NewMockClusterMeta() *MockClusterMeta { return &MockClusterMeta{fail: pegomock.GlobalFailHandler} } -func (mock *MockClusterMeta) CanIAccess(_param0 string, _param1 string, _param2 string, _param3 []string) (bool, error) { +func (mock *MockClusterMeta) CheckListNSAccess() error { if mock == nil { panic("mock must not be nil. Use myMock := NewMockClusterMeta().") } - params := []pegomock.Param{_param0, _param1, _param2, _param3} - result := pegomock.GetGenericMockFrom(mock).Invoke("CanIAccess", params, []reflect.Type{reflect.TypeOf((*bool)(nil)).Elem(), reflect.TypeOf((*error)(nil)).Elem()}) - var ret0 bool - var ret1 error + params := []pegomock.Param{} + result := pegomock.GetGenericMockFrom(mock).Invoke("CheckListNSAccess", params, []reflect.Type{reflect.TypeOf((*error)(nil)).Elem()}) + var ret0 error if len(result) != 0 { if result[0] != nil { - ret0 = result[0].(bool) - } - if result[1] != nil { - ret1 = result[1].(error) + ret0 = result[0].(error) } } - return ret0, ret1 + return ret0 +} + +func (mock *MockClusterMeta) CheckNSAccess(_param0 string) error { + if mock == nil { + panic("mock must not be nil. Use myMock := NewMockClusterMeta().") + } + params := []pegomock.Param{_param0} + result := pegomock.GetGenericMockFrom(mock).Invoke("CheckNSAccess", 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 *MockClusterMeta) ClusterName() string { @@ -428,41 +439,46 @@ type VerifierClusterMeta struct { timeout time.Duration } -func (verifier *VerifierClusterMeta) CanIAccess(_param0 string, _param1 string, _param2 string, _param3 []string) *ClusterMeta_CanIAccess_OngoingVerification { - params := []pegomock.Param{_param0, _param1, _param2, _param3} - methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "CanIAccess", params, verifier.timeout) - return &ClusterMeta_CanIAccess_OngoingVerification{mock: verifier.mock, methodInvocations: methodInvocations} +func (verifier *VerifierClusterMeta) CheckListNSAccess() *ClusterMeta_CheckListNSAccess_OngoingVerification { + params := []pegomock.Param{} + methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "CheckListNSAccess", params, verifier.timeout) + return &ClusterMeta_CheckListNSAccess_OngoingVerification{mock: verifier.mock, methodInvocations: methodInvocations} } -type ClusterMeta_CanIAccess_OngoingVerification struct { +type ClusterMeta_CheckListNSAccess_OngoingVerification struct { mock *MockClusterMeta methodInvocations []pegomock.MethodInvocation } -func (c *ClusterMeta_CanIAccess_OngoingVerification) GetCapturedArguments() (string, string, string, []string) { - _param0, _param1, _param2, _param3 := c.GetAllCapturedArguments() - return _param0[len(_param0)-1], _param1[len(_param1)-1], _param2[len(_param2)-1], _param3[len(_param3)-1] +func (c *ClusterMeta_CheckListNSAccess_OngoingVerification) GetCapturedArguments() { } -func (c *ClusterMeta_CanIAccess_OngoingVerification) GetAllCapturedArguments() (_param0 []string, _param1 []string, _param2 []string, _param3 [][]string) { +func (c *ClusterMeta_CheckListNSAccess_OngoingVerification) GetAllCapturedArguments() { +} + +func (verifier *VerifierClusterMeta) CheckNSAccess(_param0 string) *ClusterMeta_CheckNSAccess_OngoingVerification { + params := []pegomock.Param{_param0} + methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "CheckNSAccess", params, verifier.timeout) + return &ClusterMeta_CheckNSAccess_OngoingVerification{mock: verifier.mock, methodInvocations: methodInvocations} +} + +type ClusterMeta_CheckNSAccess_OngoingVerification struct { + mock *MockClusterMeta + methodInvocations []pegomock.MethodInvocation +} + +func (c *ClusterMeta_CheckNSAccess_OngoingVerification) GetCapturedArguments() string { + _param0 := c.GetAllCapturedArguments() + return _param0[len(_param0)-1] +} + +func (c *ClusterMeta_CheckNSAccess_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) } - _param1 = make([]string, len(params[1])) - for u, param := range params[1] { - _param1[u] = param.(string) - } - _param2 = make([]string, len(params[2])) - for u, param := range params[2] { - _param2[u] = param.(string) - } - _param3 = make([][]string, len(params[3])) - for u, param := range params[3] { - _param3[u] = param.([]string) - } } return } diff --git a/internal/resource/mock_connection_test.go b/internal/resource/mock_connection_test.go index 30650424..8dfb7e47 100644 --- a/internal/resource/mock_connection_test.go +++ b/internal/resource/mock_connection_test.go @@ -24,23 +24,34 @@ func NewMockConnection() *MockConnection { return &MockConnection{fail: pegomock.GlobalFailHandler} } -func (mock *MockConnection) CanIAccess(_param0 string, _param1 string, _param2 string, _param3 []string) (bool, error) { +func (mock *MockConnection) CheckListNSAccess() error { if mock == nil { panic("mock must not be nil. Use myMock := NewMockConnection().") } - params := []pegomock.Param{_param0, _param1, _param2, _param3} - result := pegomock.GetGenericMockFrom(mock).Invoke("CanIAccess", params, []reflect.Type{reflect.TypeOf((*bool)(nil)).Elem(), reflect.TypeOf((*error)(nil)).Elem()}) - var ret0 bool - var ret1 error + params := []pegomock.Param{} + result := pegomock.GetGenericMockFrom(mock).Invoke("CheckListNSAccess", params, []reflect.Type{reflect.TypeOf((*error)(nil)).Elem()}) + var ret0 error if len(result) != 0 { if result[0] != nil { - ret0 = result[0].(bool) - } - if result[1] != nil { - ret1 = result[1].(error) + ret0 = result[0].(error) } } - return ret0, ret1 + return ret0 +} + +func (mock *MockConnection) CheckNSAccess(_param0 string) error { + if mock == nil { + panic("mock must not be nil. Use myMock := NewMockConnection().") + } + params := []pegomock.Param{_param0} + result := pegomock.GetGenericMockFrom(mock).Invoke("CheckNSAccess", 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 *MockConnection) Config() *k8s.Config { @@ -345,41 +356,46 @@ type VerifierConnection struct { timeout time.Duration } -func (verifier *VerifierConnection) CanIAccess(_param0 string, _param1 string, _param2 string, _param3 []string) *Connection_CanIAccess_OngoingVerification { - params := []pegomock.Param{_param0, _param1, _param2, _param3} - methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "CanIAccess", params, verifier.timeout) - return &Connection_CanIAccess_OngoingVerification{mock: verifier.mock, methodInvocations: methodInvocations} +func (verifier *VerifierConnection) CheckListNSAccess() *Connection_CheckListNSAccess_OngoingVerification { + params := []pegomock.Param{} + methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "CheckListNSAccess", params, verifier.timeout) + return &Connection_CheckListNSAccess_OngoingVerification{mock: verifier.mock, methodInvocations: methodInvocations} } -type Connection_CanIAccess_OngoingVerification struct { +type Connection_CheckListNSAccess_OngoingVerification struct { mock *MockConnection methodInvocations []pegomock.MethodInvocation } -func (c *Connection_CanIAccess_OngoingVerification) GetCapturedArguments() (string, string, string, []string) { - _param0, _param1, _param2, _param3 := c.GetAllCapturedArguments() - return _param0[len(_param0)-1], _param1[len(_param1)-1], _param2[len(_param2)-1], _param3[len(_param3)-1] +func (c *Connection_CheckListNSAccess_OngoingVerification) GetCapturedArguments() { } -func (c *Connection_CanIAccess_OngoingVerification) GetAllCapturedArguments() (_param0 []string, _param1 []string, _param2 []string, _param3 [][]string) { +func (c *Connection_CheckListNSAccess_OngoingVerification) GetAllCapturedArguments() { +} + +func (verifier *VerifierConnection) CheckNSAccess(_param0 string) *Connection_CheckNSAccess_OngoingVerification { + params := []pegomock.Param{_param0} + methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "CheckNSAccess", params, verifier.timeout) + return &Connection_CheckNSAccess_OngoingVerification{mock: verifier.mock, methodInvocations: methodInvocations} +} + +type Connection_CheckNSAccess_OngoingVerification struct { + mock *MockConnection + methodInvocations []pegomock.MethodInvocation +} + +func (c *Connection_CheckNSAccess_OngoingVerification) GetCapturedArguments() string { + _param0 := c.GetAllCapturedArguments() + return _param0[len(_param0)-1] +} + +func (c *Connection_CheckNSAccess_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) } - _param1 = make([]string, len(params[1])) - for u, param := range params[1] { - _param1[u] = param.(string) - } - _param2 = make([]string, len(params[2])) - for u, param := range params[2] { - _param2[u] = param.(string) - } - _param3 = make([][]string, len(params[3])) - for u, param := range params[3] { - _param3[u] = param.([]string) - } } return } diff --git a/internal/views/app.go b/internal/views/app.go index 18c28e5f..2935c179 100644 --- a/internal/views/app.go +++ b/internal/views/app.go @@ -35,7 +35,6 @@ type ( igniter interface { tview.Primitive - getTitle() string init(ctx context.Context, ns string) } @@ -100,7 +99,11 @@ func (a *appView) registerActions() { func (a *appView) Init(version string, rate int) { if a.conn() != nil { - a.startInformer() + ns, err := a.conn().Config().CurrentNamespaceName() + if err != nil { + log.Info().Err(err).Msg("No namespace specified using all namespaces") + } + a.startInformer(ns) a.clusterInfo().init(version) } a.cmdBuff.addListener(a.cmd()) @@ -142,17 +145,17 @@ func (a *appView) clusterUpdater(ctx context.Context) { } } -func (a *appView) startInformer() { +func (a *appView) startInformer(ns string) { if a.stopCh != nil { close(a.stopCh) } + var err error a.stopCh = make(chan struct{}) - ns, err := a.conn().Config().CurrentNamespaceName() + a.informer, err = watch.NewInformer(a.conn(), ns) if err != nil { - log.Warn().Err(err).Msg("No namespace specified using all namespaces") + log.Panic().Err(err).Msgf("%v", err) } - a.informer = watch.NewInformer(a.conn(), ns) a.informer.Run(a.stopCh) } diff --git a/internal/views/bench.go b/internal/views/bench.go index 2917445e..21dc3282 100644 --- a/internal/views/bench.go +++ b/internal/views/bench.go @@ -50,13 +50,11 @@ func newBenchView(_ string, app *appView, _ resource.List) resourceViewer { } tv := newTableView(app, benchTitle) - { - tv.SetSelectionChangedFunc(v.selChanged) - tv.SetBorderFocusColor(tcell.ColorSeaGreen) - tv.SetSelectedStyle(tcell.ColorWhite, tcell.ColorSeaGreen, tcell.AttrNone) - tv.colorerFn = benchColorer - tv.currentNS = "" - } + tv.SetSelectionChangedFunc(v.selChanged) + tv.SetBorderFocusColor(tcell.ColorSeaGreen) + tv.SetSelectedStyle(tcell.ColorWhite, tcell.ColorSeaGreen, tcell.AttrNone) + tv.colorerFn = benchColorer + tv.currentNS = "" v.AddPage("table", tv, true, true) details := newDetailsView(app, v.backCmd) @@ -77,7 +75,6 @@ func (v *benchView) setExtraActionsFn(actionsFn) {} // Init the view. func (v *benchView) init(ctx context.Context, _ string) { if err := v.watchBenchDir(ctx); err != nil { - log.Error().Err(err).Msg("Benchdir watch failed!") v.app.flash().errf("Unable to watch benchmarks directory %s", err) } @@ -141,7 +138,6 @@ func (v *benchView) enterCmd(evt *tcell.EventKey) *tcell.EventKey { data, err := v.loadBenchFile(v.selectedItem) if err != nil { - log.Error().Err(err).Msg("Read failed") v.app.flash().errf("Unable to load bench file %s", err) return nil } @@ -163,7 +159,6 @@ func (v *benchView) deleteCmd(evt *tcell.EventKey) *tcell.EventKey { showModal(v.Pages, fmt.Sprintf("Deleting `%s are you sure?", sel), "table", func() { if err := os.Remove(filepath.Join(dir, sel)); err != nil { v.app.flash().errf("Unable to delete file %s", err) - log.Error().Err(err).Msg("Delete failed") return } v.refresh() @@ -205,7 +200,6 @@ func (v *benchView) loadBenchFile(n string) (string, error) { func (v *benchView) hydrate() resource.TableData { ff, err := v.loadBenchDir() if err != nil { - log.Error().Err(err).Msg("Reading bench dir") v.app.flash().errf("Unable to read bench directory %s", err) } diff --git a/internal/views/config.go b/internal/views/config.go index 14815ed7..1ae047d0 100644 --- a/internal/views/config.go +++ b/internal/views/config.go @@ -51,14 +51,14 @@ func (c *configurator) stylesUpdater(ctx context.Context, s synchronizer) error func (c *configurator) initBench(cluster string) { var err error if c.bench, err = config.NewBench(benchConfig(cluster)); err != nil { - log.Warn().Err(err).Msg("No benchmark config file found, using defaults.") + log.Info().Err(err).Msg("No benchmark config file found, using defaults.") } } func (c *configurator) refreshStyles() { var err error if c.styles, err = config.NewStyles(config.K9sStylesFile); err != nil { - log.Warn().Err(err).Msg("No skin file found. Loading defaults.") + log.Info().Msg("No skin file found. Loading stock skins.") } if err == nil { c.hasSkins = true diff --git a/internal/views/container.go b/internal/views/container.go index 44d893f8..0e4aea8b 100644 --- a/internal/views/container.go +++ b/internal/views/container.go @@ -55,7 +55,7 @@ func (v *containerView) selectedContainer() string { } func (v *containerView) viewLogs(app *appView, _, res, sel string) { - status := strings.TrimSpace(v.getTV().GetCell(v.selectedRow, 3).Text) + status := strings.TrimSpace(v.masterPage().GetCell(v.selectedRow, 3).Text) if status == "Running" || status == "Completed" { v.showLogs(false) return @@ -81,7 +81,7 @@ func (v *containerView) portFwdCmd(evt *tcell.EventKey) *tcell.EventKey { return evt } - portC := v.getTV().GetCell(v.selectedRow, 10) + portC := v.masterPage().GetCell(v.selectedRow, 10) ports := strings.Split(portC.Text, ",") if len(ports) == 0 { v.app.flash().err(errors.New("Container exposes no ports")) @@ -102,7 +102,7 @@ func (v *containerView) portFwdCmd(evt *tcell.EventKey) *tcell.EventKey { port = "MY_TCP_PORT!" } - co := strings.TrimSpace(v.getTV().GetCell(v.selectedRow, 0).Text) + co := strings.TrimSpace(v.masterPage().GetCell(v.selectedRow, 0).Text) v.showPortFwdDialog(port, func(lport, cport string) { pf := k8s.NewPortForward(v.app.conn(), &log.Logger) @@ -137,8 +137,8 @@ func (v *containerView) portFwdCmd(evt *tcell.EventKey) *tcell.EventKey { } func (v *containerView) dismissModal() { - v.RemovePage("dialog") - v.switchPage(v.list.GetName()) + v.RemovePage("forward") + v.switchPage("master") } func (v *containerView) backCmd(evt *tcell.EventKey) *tcell.EventKey { @@ -175,6 +175,6 @@ func (v *containerView) showPortFwdDialog(port string, okFn func(lport, cport st modal.SetDoneFunc(func(_ int, b string) { v.dismissModal() }) - v.AddPage("dialog", modal, false, false) - v.ShowPage("dialog") + v.AddPage("forward", modal, false, false) + v.ShowPage("forward") } diff --git a/internal/views/context.go b/internal/views/context.go index 91b108c4..7347f5d7 100644 --- a/internal/views/context.go +++ b/internal/views/context.go @@ -4,6 +4,7 @@ import ( "strings" "github.com/derailed/k9s/internal/resource" + "github.com/rs/zerolog/log" ) type contextView struct { @@ -14,13 +15,13 @@ func newContextView(title string, app *appView, list resource.List) resourceView v := contextView{newResourceView(title, app, list).(*resourceView)} v.extraActionsFn = v.extraActions v.enterFn = v.useCtx - v.getTV().cleanseFn = v.cleanser + v.masterPage().cleanseFn = v.cleanser return &v } func (v *contextView) extraActions(aa keyActions) { - delete(v.getTV().actions, KeyShiftA) + delete(v.masterPage().actions, KeyShiftA) } func (v *contextView) useCtx(app *appView, _, res, sel string) { @@ -48,10 +49,14 @@ func (v *contextView) useContext(name string) error { return err } - v.app.startInformer() + v.app.stopForwarders() + ns, err := v.app.conn().Config().CurrentNamespaceName() + if err != nil { + log.Info().Err(err).Msg("No namespace specified using all namespaces") + } + v.app.startInformer(ns) v.app.config.Reset() v.app.config.Save() - v.app.stopForwarders() v.app.flash().infof("Switching context to %s", ctx) v.refresh() if tv, ok := v.GetPrimitive("ctx").(*tableView); ok { diff --git a/internal/views/context_test.go b/internal/views/context_test.go index 5d2a8c34..bafc4520 100644 --- a/internal/views/context_test.go +++ b/internal/views/context_test.go @@ -10,9 +10,9 @@ import ( func TestContextView(t *testing.T) { l := resource.NewContextList(nil, "fred") - v := newContextView("blee", NewApp(config.NewConfig(ks{})), l) + v := newContextView("blee", NewApp(config.NewConfig(ks{})), l).(*contextView) - assert.Equal(t, "blee", v.getTitle()) + assert.Equal(t, 3, len(v.hints())) } func TestCleaner(t *testing.T) { diff --git a/internal/views/dialog.go b/internal/views/dialog.go new file mode 100644 index 00000000..48791535 --- /dev/null +++ b/internal/views/dialog.go @@ -0,0 +1,52 @@ +package views + +import ( + "github.com/derailed/tview" + "github.com/gdamore/tcell" +) + +const deleteDialogKey = "delete" + +type ( + doneFn func(cascade, force bool) + cancelFn func() +) + +func showDeleteDialog(pages *tview.Pages, msg string, done doneFn, cancel cancelFn) { + cascade, force := true, false + f := tview.NewForm() + f.SetItemPadding(0) + f.SetButtonsAlign(tview.AlignCenter). + SetButtonBackgroundColor(tview.Styles.PrimitiveBackgroundColor). + SetButtonTextColor(tview.Styles.PrimaryTextColor). + SetLabelColor(tcell.ColorAqua). + SetFieldTextColor(tcell.ColorOrange) + f.AddCheckbox("Cascade:", cascade, func(checked bool) { + cascade = checked + }) + f.AddCheckbox("Force:", force, func(checked bool) { + force = checked + }) + f.AddButton("Cancel", func() { + dismissDeleteDialog(pages) + cancel() + }) + f.AddButton("OK", func() { + done(cascade, force) + dismissDeleteDialog(pages) + cancel() + }) + + confirm := tview.NewModalForm("", f) + confirm.SetText(msg) + confirm.SetDoneFunc(func(int, string) { + dismissDeleteDialog(pages) + cancel() + }) + pages.AddPage(deleteDialogKey, confirm, false, false) + pages.ShowPage(deleteDialogKey) +} + +func dismissDeleteDialog(pages *tview.Pages) { + pages.RemovePage(deleteDialogKey) +} diff --git a/internal/views/dp.go b/internal/views/dp.go index b8ee7dc2..996001c8 100644 --- a/internal/views/dp.go +++ b/internal/views/dp.go @@ -3,7 +3,6 @@ package views import ( "github.com/derailed/k9s/internal/k8s" "github.com/derailed/k9s/internal/resource" - "github.com/rs/zerolog/log" v1 "k8s.io/api/apps/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) @@ -31,7 +30,6 @@ func (v *deployView) showPods(app *appView, _, res, sel string) { d := k8s.NewDeployment(app.conn()) dep, err := d.Get(ns, n) if err != nil { - log.Error().Err(err).Msgf("Fetching Deployment %s", sel) app.flash().err(err) return } @@ -39,7 +37,6 @@ func (v *deployView) showPods(app *appView, _, res, sel string) { dp := dep.(*v1.Deployment) l, err := metav1.LabelSelectorAsSelector(dp.Spec.Selector) if err != nil { - log.Error().Err(err).Msgf("Converting selector for Deployment %s", sel) app.flash().err(err) return } diff --git a/internal/views/dp_test.go b/internal/views/dp_test.go index 0dcdb94c..3586d521 100644 --- a/internal/views/dp_test.go +++ b/internal/views/dp_test.go @@ -10,7 +10,7 @@ import ( func TestDeployView(t *testing.T) { l := resource.NewDeploymentList(nil, "fred") - v := newDeployView("blee", NewApp(config.NewConfig(ks{})), l) + v := newDeployView("blee", NewApp(config.NewConfig(ks{})), l).(*deployView) - assert.Equal(t, "blee", v.getTitle()) + assert.Equal(t, 3, len(v.hints())) } diff --git a/internal/views/ds.go b/internal/views/ds.go index 1081aa10..8b77fd4a 100644 --- a/internal/views/ds.go +++ b/internal/views/ds.go @@ -3,7 +3,6 @@ package views import ( "github.com/derailed/k9s/internal/k8s" "github.com/derailed/k9s/internal/resource" - "github.com/rs/zerolog/log" extv1beta1 "k8s.io/api/extensions/v1beta1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) @@ -31,7 +30,6 @@ func (v *daemonSetView) showPods(app *appView, _, res, sel string) { d := k8s.NewDaemonSet(app.conn()) dset, err := d.Get(ns, n) if err != nil { - log.Error().Err(err).Msgf("Fetching DeaemonSet %s", sel) v.app.flash().err(err) return } @@ -39,7 +37,6 @@ func (v *daemonSetView) showPods(app *appView, _, res, sel string) { ds := dset.(*extv1beta1.DaemonSet) l, err := metav1.LabelSelectorAsSelector(ds.Spec.Selector) if err != nil { - log.Error().Err(err).Msgf("Converting selector for DaemonSet %s", sel) app.flash().err(err) return } diff --git a/internal/views/ds_test.go b/internal/views/ds_test.go index 32665e52..c03e1f91 100644 --- a/internal/views/ds_test.go +++ b/internal/views/ds_test.go @@ -10,7 +10,7 @@ import ( func TestDaemonSetView(t *testing.T) { l := resource.NewDaemonSetList(nil, "fred") - v := newDaemonSetView("blee", NewApp(config.NewConfig(ks{})), l) + v := newDaemonSetView("blee", NewApp(config.NewConfig(ks{})), l).(*daemonSetView) - assert.Equal(t, "blee", v.getTitle()) + assert.Equal(t, 3, len(v.hints())) } diff --git a/internal/views/dump.go b/internal/views/dump.go index 7eb3e33a..0ea03190 100644 --- a/internal/views/dump.go +++ b/internal/views/dump.go @@ -69,7 +69,6 @@ func (v *dumpView) setExtraActionsFn(actionsFn) {} // Init the view. func (v *dumpView) init(ctx context.Context, _ string) { if err := v.watchDumpDir(ctx); err != nil { - log.Error().Err(err).Msg("Dumpdir watch failed!") v.app.flash().errf("Unable to watch dumpmarks directory %s", err) } @@ -134,8 +133,7 @@ func (v *dumpView) enterCmd(evt *tcell.EventKey) *tcell.EventKey { } dir := filepath.Join(config.K9sDumpDir, v.app.config.K9s.CurrentCluster) - if !run(true, v.app, filepath.Join(dir, sel)) { - log.Error().Msg("Failed to launch editor") + if !edit(true, v.app, filepath.Join(dir, sel)) { v.app.flash().err(errors.New("Failed to launch editor")) } @@ -152,7 +150,6 @@ func (v *dumpView) deleteCmd(evt *tcell.EventKey) *tcell.EventKey { showModal(v.Pages, fmt.Sprintf("Deleting `%s are you sure?", sel), "table", func() { if err := os.Remove(filepath.Join(dir, sel)); err != nil { v.app.flash().errf("Unable to delete file %s", err) - log.Error().Err(err).Msg("Delete failed") return } v.refresh() @@ -184,7 +181,6 @@ func (v *dumpView) hydrate() resource.TableData { dir := filepath.Join(config.K9sDumpDir, v.app.config.K9s.CurrentCluster) ff, err := ioutil.ReadDir(dir) if err != nil { - log.Error().Err(err).Msg("Reading dump dir") v.app.flash().errf("Unable to read dump directory %s", err) } diff --git a/internal/views/exec.go b/internal/views/exec.go index cf0756e9..51a09537 100644 --- a/internal/views/exec.go +++ b/internal/views/exec.go @@ -26,7 +26,6 @@ func runK(clear bool, app *appView, args ...string) bool { func run(clear bool, app *appView, bin string, args ...string) bool { return app.Suspend(func() { if err := execute(clear, bin, args...); err != nil { - log.Error().Msgf("Command exited: %T %v %v", err, err, args) app.flash().errf("Command exited: %v", err) } }) diff --git a/internal/views/flash.go b/internal/views/flash.go index ab62f73b..43884b06 100644 --- a/internal/views/flash.go +++ b/internal/views/flash.go @@ -63,12 +63,19 @@ func (v *flashView) warnf(fmat string, args ...interface{}) { } func (v *flashView) err(err error) { - log.Error().Err(err) + log.Error().Err(err).Msgf("%v", err) v.setMessage(flashErr, err.Error()) } func (v *flashView) errf(fmat string, args ...interface{}) { - log.Error().Msgf(fmat, args...) + var err error + for _, a := range args { + switch e := a.(type) { + case error: + err = e + } + } + log.Error().Err(err).Msgf(fmat, args...) v.setMessage(flashErr, fmt.Sprintf(fmat, args...)) } diff --git a/internal/views/forward.go b/internal/views/forward.go index 7ddc90f5..2de4bf32 100644 --- a/internal/views/forward.go +++ b/internal/views/forward.go @@ -58,7 +58,6 @@ func (v *forwardView) setExtraActionsFn(actionsFn) {} func (v *forwardView) init(ctx context.Context, _ string) { path := benchConfig(v.app.config.K9s.CurrentCluster) if err := watchFS(ctx, v.app, config.K9sHome, path, v.reload); err != nil { - log.Error().Err(err).Msg("Benchdir watch failed!") v.app.flash().errf("RuRoh! Unable to watch benchmarks directory %s : %s", config.K9sHome, err) } @@ -81,7 +80,6 @@ func (v *forwardView) reload() { path := benchConfig(v.app.config.K9s.CurrentCluster) log.Debug().Msgf("Reloading config %s", path) if err := v.app.bench.Reload(path); err != nil { - log.Error().Err(err).Msg("Bench config reload") v.app.flash().err(err) } v.refresh() @@ -155,12 +153,10 @@ func (v *forwardView) benchCmd(evt *tcell.EventKey) *tcell.EventKey { cfg = b } cfg.Name = sel - log.Debug().Msgf(">>>>> BENCHCONFIG %#v", cfg) base := strings.TrimSpace(tv.GetCell(r, 4).Text) var err error if v.bench, err = newBenchmark(base, cfg); err != nil { - log.Error().Err(err).Msg("Bench failed!") v.app.flash().errf("Bench failed %v", err) v.app.statusReset() v.bench = nil diff --git a/internal/views/job.go b/internal/views/job.go index dcb11f81..026a0aaf 100644 --- a/internal/views/job.go +++ b/internal/views/job.go @@ -3,7 +3,6 @@ package views import ( "github.com/derailed/k9s/internal/k8s" "github.com/derailed/k9s/internal/resource" - "github.com/rs/zerolog/log" batchv1 "k8s.io/api/batch/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) @@ -29,7 +28,6 @@ func (v *jobView) showPods(app *appView, ns, res, sel string) { j := k8s.NewJob(app.conn()) job, err := j.Get(ns, n) if err != nil { - log.Error().Err(err).Msgf("Fetching Job %s", sel) app.flash().err(err) return } @@ -37,7 +35,6 @@ func (v *jobView) showPods(app *appView, ns, res, sel string) { jo := job.(*batchv1.Job) l, err := metav1.LabelSelectorAsSelector(jo.Spec.Selector) if err != nil { - log.Error().Err(err).Msgf("Converting selector for Job %s", sel) app.flash().err(err) return } diff --git a/internal/views/log_resource.go b/internal/views/log_resource.go index f696302c..2dc42e96 100644 --- a/internal/views/log_resource.go +++ b/internal/views/log_resource.go @@ -31,7 +31,7 @@ func (v *logResourceView) extraActions(aa keyActions) { func (v *logResourceView) sortColCmd(col int, asc bool) func(evt *tcell.EventKey) *tcell.EventKey { return func(evt *tcell.EventKey) *tcell.EventKey { - t := v.getTV() + t := v.masterPage() t.sortCol.index, t.sortCol.asc = t.nameColIndex()+col, asc t.refresh() diff --git a/internal/views/logs.go b/internal/views/logs.go index b2c461d2..7f3e8b5c 100644 --- a/internal/views/logs.go +++ b/internal/views/logs.go @@ -171,7 +171,7 @@ func (v *logsView) doLoad(path, co string) error { func (v *logsView) backCmd(evt *tcell.EventKey) *tcell.EventKey { v.stop() - v.parent.switchPage(v.title) + v.parent.switchPage("master") return evt } diff --git a/internal/views/master_detail.go b/internal/views/master_detail.go new file mode 100644 index 00000000..501233e9 --- /dev/null +++ b/internal/views/master_detail.go @@ -0,0 +1,135 @@ +package views + +import ( + "path" + "strings" + + "github.com/derailed/k9s/internal/resource" + "github.com/derailed/tview" +) + +type masterDetail struct { + *tview.Pages + + app *appView + actions keyActions + currentNS string + selectedItem string + selectedRow int + selectedFn func() string + enterFn enterFn + colorerFn colorerFn + decorateFn decorateFn + extraActionsFn func(keyActions) +} + +func newMasterDetail(title string, app *appView, ns string) *masterDetail { + v := masterDetail{ + Pages: tview.NewPages(), + app: app, + actions: make(keyActions), + currentNS: ns, + } + + tv := newTableView(app, title) + tv.SetSelectionChangedFunc(v.selChanged) + v.AddPage("master", tv, true, true) + + return &v +} + +func (v *masterDetail) init(ns string, backCmd actionHandler) { + details := newDetailsView(v.app, backCmd) + v.AddPage("details", details, true, false) + + if v.currentNS != resource.NotNamespaced { + v.currentNS = ns + } + colorer := defaultColorer + if v.colorerFn != nil { + colorer = v.colorerFn + } + v.masterPage().setColorer(colorer) +} + +func (v *masterDetail) setExtraActionsFn(f actionsFn) { + f(v.actions) +} + +func (v *masterDetail) rowSelected() bool { + return v.selectedItem != "" +} + +func (v *masterDetail) selChanged(r, c int) { + v.selectedRow = r + v.selectItem(r, c) +} + +func (v *masterDetail) getSelectedItem() string { + if v.selectedFn != nil { + return v.selectedFn() + } + return v.selectedItem +} + +// Protocol... + +// Hints fetch menu hints +func (v *masterDetail) hints() hints { + return v.CurrentPage().Item.(hinter).hints() +} + +func (v *masterDetail) setColorerFn(f colorerFn) { + v.colorerFn = f + v.masterPage().setColorer(f) +} + +func (v *masterDetail) setEnterFn(f enterFn) { + v.enterFn = f +} + +func (v *masterDetail) setDecorateFn(f decorateFn) { + v.decorateFn = f +} + +func (v *masterDetail) masterPage() *tableView { + return v.GetPrimitive("master").(*tableView) +} + +func (v *masterDetail) detailsPage() *detailsView { + return v.GetPrimitive("details").(*detailsView) +} + +// ---------------------------------------------------------------------------- +// Actions... + +func (v *masterDetail) selectItem(r, c int) { + t := v.masterPage() + if r == 0 || t.GetCell(r, 0) == nil { + v.selectedItem = "" + return + } + + col0 := cleanCell(t, r, 0) + switch v.currentNS { + case resource.NotNamespaced: + v.selectedItem = col0 + case resource.AllNamespace, resource.AllNamespaces: + v.selectedItem = path.Join(col0, cleanCell(t, r, 1)) + default: + v.selectedItem = path.Join(v.currentNS, col0) + } +} + +func (v *masterDetail) defaultActions() { + v.actions[KeyHelp] = newKeyAction("Help", v.app.noopCmd, false) + v.actions[KeyP] = newKeyAction("Previous", v.app.prevCmd, false) + + if v.extraActionsFn != nil { + v.extraActionsFn(v.actions) + } +} + +func cleanCell(v *tableView, r, c int) string { + return strings.TrimSpace(v.GetCell(r, c).Text) +} diff --git a/internal/views/mock_clustermeta.go b/internal/views/mock_clustermeta.go deleted file mode 100644 index 8647f28e..00000000 --- a/internal/views/mock_clustermeta.go +++ /dev/null @@ -1,879 +0,0 @@ -// Code generated by pegomock. DO NOT EDIT. -// Source: github.com/derailed/k9s/internal/resource (interfaces: ClusterMeta) - -package views - -import ( - k8s "github.com/derailed/k9s/internal/k8s" - pegomock "github.com/petergtz/pegomock" - v1 "k8s.io/api/core/v1" - version "k8s.io/apimachinery/pkg/version" - dynamic "k8s.io/client-go/dynamic" - kubernetes "k8s.io/client-go/kubernetes" - rest "k8s.io/client-go/rest" - versioned "k8s.io/metrics/pkg/client/clientset/versioned" - "reflect" - "time" -) - -type MockClusterMeta struct { - fail func(message string, callerSkip ...int) -} - -func NewMockClusterMeta() *MockClusterMeta { - return &MockClusterMeta{fail: pegomock.GlobalFailHandler} -} - -func (mock *MockClusterMeta) CanIAccess(_param0 string, _param1 string, _param2 string, _param3 []string) (bool, error) { - if mock == nil { - panic("mock must not be nil. Use myMock := NewMockClusterMeta().") - } - params := []pegomock.Param{_param0, _param1, _param2, _param3} - result := pegomock.GetGenericMockFrom(mock).Invoke("CanIAccess", params, []reflect.Type{reflect.TypeOf((*bool)(nil)).Elem(), reflect.TypeOf((*error)(nil)).Elem()}) - var ret0 bool - var ret1 error - if len(result) != 0 { - if result[0] != nil { - ret0 = result[0].(bool) - } - if result[1] != nil { - ret1 = result[1].(error) - } - } - return ret0, ret1 -} - -func (mock *MockClusterMeta) ClusterName() string { - if mock == nil { - panic("mock must not be nil. Use myMock := NewMockClusterMeta().") - } - params := []pegomock.Param{} - result := pegomock.GetGenericMockFrom(mock).Invoke("ClusterName", params, []reflect.Type{reflect.TypeOf((*string)(nil)).Elem()}) - var ret0 string - if len(result) != 0 { - if result[0] != nil { - ret0 = result[0].(string) - } - } - return ret0 -} - -func (mock *MockClusterMeta) Config() *k8s.Config { - if mock == nil { - panic("mock must not be nil. Use myMock := NewMockClusterMeta().") - } - params := []pegomock.Param{} - result := pegomock.GetGenericMockFrom(mock).Invoke("Config", params, []reflect.Type{reflect.TypeOf((**k8s.Config)(nil)).Elem()}) - var ret0 *k8s.Config - if len(result) != 0 { - if result[0] != nil { - ret0 = result[0].(*k8s.Config) - } - } - return ret0 -} - -func (mock *MockClusterMeta) ContextName() string { - if mock == nil { - panic("mock must not be nil. Use myMock := NewMockClusterMeta().") - } - params := []pegomock.Param{} - result := pegomock.GetGenericMockFrom(mock).Invoke("ContextName", params, []reflect.Type{reflect.TypeOf((*string)(nil)).Elem()}) - var ret0 string - if len(result) != 0 { - if result[0] != nil { - ret0 = result[0].(string) - } - } - return ret0 -} - -func (mock *MockClusterMeta) CurrentNamespaceName() (string, error) { - if mock == nil { - panic("mock must not be nil. Use myMock := NewMockClusterMeta().") - } - params := []pegomock.Param{} - result := pegomock.GetGenericMockFrom(mock).Invoke("CurrentNamespaceName", 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 *MockClusterMeta) DialOrDie() kubernetes.Interface { - if mock == nil { - panic("mock must not be nil. Use myMock := NewMockClusterMeta().") - } - params := []pegomock.Param{} - result := pegomock.GetGenericMockFrom(mock).Invoke("DialOrDie", params, []reflect.Type{reflect.TypeOf((*kubernetes.Interface)(nil)).Elem()}) - var ret0 kubernetes.Interface - if len(result) != 0 { - if result[0] != nil { - ret0 = result[0].(kubernetes.Interface) - } - } - return ret0 -} - -func (mock *MockClusterMeta) DynDialOrDie() dynamic.Interface { - if mock == nil { - panic("mock must not be nil. Use myMock := NewMockClusterMeta().") - } - params := []pegomock.Param{} - result := pegomock.GetGenericMockFrom(mock).Invoke("DynDialOrDie", params, []reflect.Type{reflect.TypeOf((*dynamic.Interface)(nil)).Elem()}) - var ret0 dynamic.Interface - if len(result) != 0 { - if result[0] != nil { - ret0 = result[0].(dynamic.Interface) - } - } - return ret0 -} - -func (mock *MockClusterMeta) FetchNodes() (*v1.NodeList, error) { - if mock == nil { - panic("mock must not be nil. Use myMock := NewMockClusterMeta().") - } - params := []pegomock.Param{} - result := pegomock.GetGenericMockFrom(mock).Invoke("FetchNodes", params, []reflect.Type{reflect.TypeOf((**v1.NodeList)(nil)).Elem(), reflect.TypeOf((*error)(nil)).Elem()}) - var ret0 *v1.NodeList - var ret1 error - if len(result) != 0 { - if result[0] != nil { - ret0 = result[0].(*v1.NodeList) - } - if result[1] != nil { - ret1 = result[1].(error) - } - } - return ret0, ret1 -} - -func (mock *MockClusterMeta) GetNodes() (*v1.NodeList, error) { - if mock == nil { - panic("mock must not be nil. Use myMock := NewMockClusterMeta().") - } - params := []pegomock.Param{} - result := pegomock.GetGenericMockFrom(mock).Invoke("GetNodes", params, []reflect.Type{reflect.TypeOf((**v1.NodeList)(nil)).Elem(), reflect.TypeOf((*error)(nil)).Elem()}) - var ret0 *v1.NodeList - var ret1 error - if len(result) != 0 { - if result[0] != nil { - ret0 = result[0].(*v1.NodeList) - } - if result[1] != nil { - ret1 = result[1].(error) - } - } - return ret0, ret1 -} - -func (mock *MockClusterMeta) HasMetrics() bool { - if mock == nil { - panic("mock must not be nil. Use myMock := NewMockClusterMeta().") - } - 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 *MockClusterMeta) IsNamespaced(_param0 string) bool { - if mock == nil { - panic("mock must not be nil. Use myMock := NewMockClusterMeta().") - } - params := []pegomock.Param{_param0} - result := pegomock.GetGenericMockFrom(mock).Invoke("IsNamespaced", 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 *MockClusterMeta) MXDial() (*versioned.Clientset, error) { - if mock == nil { - panic("mock must not be nil. Use myMock := NewMockClusterMeta().") - } - params := []pegomock.Param{} - result := pegomock.GetGenericMockFrom(mock).Invoke("MXDial", params, []reflect.Type{reflect.TypeOf((**versioned.Clientset)(nil)).Elem(), reflect.TypeOf((*error)(nil)).Elem()}) - var ret0 *versioned.Clientset - var ret1 error - if len(result) != 0 { - if result[0] != nil { - ret0 = result[0].(*versioned.Clientset) - } - if result[1] != nil { - ret1 = result[1].(error) - } - } - return ret0, ret1 -} - -func (mock *MockClusterMeta) NSDialOrDie() dynamic.NamespaceableResourceInterface { - if mock == nil { - panic("mock must not be nil. Use myMock := NewMockClusterMeta().") - } - params := []pegomock.Param{} - result := pegomock.GetGenericMockFrom(mock).Invoke("NSDialOrDie", params, []reflect.Type{reflect.TypeOf((*dynamic.NamespaceableResourceInterface)(nil)).Elem()}) - var ret0 dynamic.NamespaceableResourceInterface - if len(result) != 0 { - if result[0] != nil { - ret0 = result[0].(dynamic.NamespaceableResourceInterface) - } - } - return ret0 -} - -func (mock *MockClusterMeta) NodePods(_param0 string) (*v1.PodList, error) { - if mock == nil { - panic("mock must not be nil. Use myMock := NewMockClusterMeta().") - } - params := []pegomock.Param{_param0} - result := pegomock.GetGenericMockFrom(mock).Invoke("NodePods", params, []reflect.Type{reflect.TypeOf((**v1.PodList)(nil)).Elem(), reflect.TypeOf((*error)(nil)).Elem()}) - var ret0 *v1.PodList - var ret1 error - if len(result) != 0 { - if result[0] != nil { - ret0 = result[0].(*v1.PodList) - } - if result[1] != nil { - ret1 = result[1].(error) - } - } - return ret0, ret1 -} - -func (mock *MockClusterMeta) RestConfigOrDie() *rest.Config { - if mock == nil { - panic("mock must not be nil. Use myMock := NewMockClusterMeta().") - } - params := []pegomock.Param{} - result := pegomock.GetGenericMockFrom(mock).Invoke("RestConfigOrDie", params, []reflect.Type{reflect.TypeOf((**rest.Config)(nil)).Elem()}) - var ret0 *rest.Config - if len(result) != 0 { - if result[0] != nil { - ret0 = result[0].(*rest.Config) - } - } - return ret0 -} - -func (mock *MockClusterMeta) ServerVersion() (*version.Info, error) { - if mock == nil { - panic("mock must not be nil. Use myMock := NewMockClusterMeta().") - } - params := []pegomock.Param{} - result := pegomock.GetGenericMockFrom(mock).Invoke("ServerVersion", params, []reflect.Type{reflect.TypeOf((**version.Info)(nil)).Elem(), reflect.TypeOf((*error)(nil)).Elem()}) - var ret0 *version.Info - var ret1 error - if len(result) != 0 { - if result[0] != nil { - ret0 = result[0].(*version.Info) - } - if result[1] != nil { - ret1 = result[1].(error) - } - } - return ret0, ret1 -} - -func (mock *MockClusterMeta) SupportsRes(_param0 string, _param1 []string) (string, bool, error) { - if mock == nil { - panic("mock must not be nil. Use myMock := NewMockClusterMeta().") - } - params := []pegomock.Param{_param0, _param1} - result := pegomock.GetGenericMockFrom(mock).Invoke("SupportsRes", params, []reflect.Type{reflect.TypeOf((*string)(nil)).Elem(), reflect.TypeOf((*bool)(nil)).Elem(), reflect.TypeOf((*error)(nil)).Elem()}) - var ret0 string - var ret1 bool - var ret2 error - if len(result) != 0 { - if result[0] != nil { - ret0 = result[0].(string) - } - if result[1] != nil { - ret1 = result[1].(bool) - } - if result[2] != nil { - ret2 = result[2].(error) - } - } - return ret0, ret1, ret2 -} - -func (mock *MockClusterMeta) SupportsResource(_param0 string) bool { - if mock == nil { - panic("mock must not be nil. Use myMock := NewMockClusterMeta().") - } - params := []pegomock.Param{_param0} - result := pegomock.GetGenericMockFrom(mock).Invoke("SupportsResource", 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 *MockClusterMeta) SwitchContextOrDie(_param0 string) { - if mock == nil { - panic("mock must not be nil. Use myMock := NewMockClusterMeta().") - } - params := []pegomock.Param{_param0} - pegomock.GetGenericMockFrom(mock).Invoke("SwitchContextOrDie", params, []reflect.Type{}) -} - -func (mock *MockClusterMeta) UserName() string { - if mock == nil { - panic("mock must not be nil. Use myMock := NewMockClusterMeta().") - } - params := []pegomock.Param{} - result := pegomock.GetGenericMockFrom(mock).Invoke("UserName", params, []reflect.Type{reflect.TypeOf((*string)(nil)).Elem()}) - var ret0 string - if len(result) != 0 { - if result[0] != nil { - ret0 = result[0].(string) - } - } - return ret0 -} - -func (mock *MockClusterMeta) ValidNamespaces() ([]v1.Namespace, error) { - if mock == nil { - panic("mock must not be nil. Use myMock := NewMockClusterMeta().") - } - params := []pegomock.Param{} - result := pegomock.GetGenericMockFrom(mock).Invoke("ValidNamespaces", params, []reflect.Type{reflect.TypeOf((*[]v1.Namespace)(nil)).Elem(), reflect.TypeOf((*error)(nil)).Elem()}) - var ret0 []v1.Namespace - var ret1 error - if len(result) != 0 { - if result[0] != nil { - ret0 = result[0].([]v1.Namespace) - } - 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().") - } - params := []pegomock.Param{} - result := pegomock.GetGenericMockFrom(mock).Invoke("Version", 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 *MockClusterMeta) VerifyWasCalledOnce() *VerifierClusterMeta { - return &VerifierClusterMeta{ - mock: mock, - invocationCountMatcher: pegomock.Times(1), - } -} - -func (mock *MockClusterMeta) VerifyWasCalled(invocationCountMatcher pegomock.Matcher) *VerifierClusterMeta { - return &VerifierClusterMeta{ - mock: mock, - invocationCountMatcher: invocationCountMatcher, - } -} - -func (mock *MockClusterMeta) VerifyWasCalledInOrder(invocationCountMatcher pegomock.Matcher, inOrderContext *pegomock.InOrderContext) *VerifierClusterMeta { - return &VerifierClusterMeta{ - mock: mock, - invocationCountMatcher: invocationCountMatcher, - inOrderContext: inOrderContext, - } -} - -func (mock *MockClusterMeta) VerifyWasCalledEventually(invocationCountMatcher pegomock.Matcher, timeout time.Duration) *VerifierClusterMeta { - return &VerifierClusterMeta{ - mock: mock, - invocationCountMatcher: invocationCountMatcher, - timeout: timeout, - } -} - -type VerifierClusterMeta struct { - mock *MockClusterMeta - invocationCountMatcher pegomock.Matcher - inOrderContext *pegomock.InOrderContext - timeout time.Duration -} - -func (verifier *VerifierClusterMeta) CanIAccess(_param0 string, _param1 string, _param2 string, _param3 []string) *ClusterMeta_CanIAccess_OngoingVerification { - params := []pegomock.Param{_param0, _param1, _param2, _param3} - methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "CanIAccess", params, verifier.timeout) - return &ClusterMeta_CanIAccess_OngoingVerification{mock: verifier.mock, methodInvocations: methodInvocations} -} - -type ClusterMeta_CanIAccess_OngoingVerification struct { - mock *MockClusterMeta - methodInvocations []pegomock.MethodInvocation -} - -func (c *ClusterMeta_CanIAccess_OngoingVerification) GetCapturedArguments() (string, string, string, []string) { - _param0, _param1, _param2, _param3 := c.GetAllCapturedArguments() - return _param0[len(_param0)-1], _param1[len(_param1)-1], _param2[len(_param2)-1], _param3[len(_param3)-1] -} - -func (c *ClusterMeta_CanIAccess_OngoingVerification) GetAllCapturedArguments() (_param0 []string, _param1 []string, _param2 []string, _param3 [][]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) - } - _param1 = make([]string, len(params[1])) - for u, param := range params[1] { - _param1[u] = param.(string) - } - _param2 = make([]string, len(params[2])) - for u, param := range params[2] { - _param2[u] = param.(string) - } - _param3 = make([][]string, len(params[3])) - for u, param := range params[3] { - _param3[u] = param.([]string) - } - } - return -} - -func (verifier *VerifierClusterMeta) ClusterName() *ClusterMeta_ClusterName_OngoingVerification { - params := []pegomock.Param{} - methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "ClusterName", params, verifier.timeout) - return &ClusterMeta_ClusterName_OngoingVerification{mock: verifier.mock, methodInvocations: methodInvocations} -} - -type ClusterMeta_ClusterName_OngoingVerification struct { - mock *MockClusterMeta - methodInvocations []pegomock.MethodInvocation -} - -func (c *ClusterMeta_ClusterName_OngoingVerification) GetCapturedArguments() { -} - -func (c *ClusterMeta_ClusterName_OngoingVerification) GetAllCapturedArguments() { -} - -func (verifier *VerifierClusterMeta) Config() *ClusterMeta_Config_OngoingVerification { - params := []pegomock.Param{} - methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "Config", params, verifier.timeout) - return &ClusterMeta_Config_OngoingVerification{mock: verifier.mock, methodInvocations: methodInvocations} -} - -type ClusterMeta_Config_OngoingVerification struct { - mock *MockClusterMeta - methodInvocations []pegomock.MethodInvocation -} - -func (c *ClusterMeta_Config_OngoingVerification) GetCapturedArguments() { -} - -func (c *ClusterMeta_Config_OngoingVerification) GetAllCapturedArguments() { -} - -func (verifier *VerifierClusterMeta) ContextName() *ClusterMeta_ContextName_OngoingVerification { - params := []pegomock.Param{} - methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "ContextName", params, verifier.timeout) - return &ClusterMeta_ContextName_OngoingVerification{mock: verifier.mock, methodInvocations: methodInvocations} -} - -type ClusterMeta_ContextName_OngoingVerification struct { - mock *MockClusterMeta - methodInvocations []pegomock.MethodInvocation -} - -func (c *ClusterMeta_ContextName_OngoingVerification) GetCapturedArguments() { -} - -func (c *ClusterMeta_ContextName_OngoingVerification) GetAllCapturedArguments() { -} - -func (verifier *VerifierClusterMeta) CurrentNamespaceName() *ClusterMeta_CurrentNamespaceName_OngoingVerification { - params := []pegomock.Param{} - methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "CurrentNamespaceName", params, verifier.timeout) - return &ClusterMeta_CurrentNamespaceName_OngoingVerification{mock: verifier.mock, methodInvocations: methodInvocations} -} - -type ClusterMeta_CurrentNamespaceName_OngoingVerification struct { - mock *MockClusterMeta - methodInvocations []pegomock.MethodInvocation -} - -func (c *ClusterMeta_CurrentNamespaceName_OngoingVerification) GetCapturedArguments() { -} - -func (c *ClusterMeta_CurrentNamespaceName_OngoingVerification) GetAllCapturedArguments() { -} - -func (verifier *VerifierClusterMeta) DialOrDie() *ClusterMeta_DialOrDie_OngoingVerification { - params := []pegomock.Param{} - methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "DialOrDie", params, verifier.timeout) - return &ClusterMeta_DialOrDie_OngoingVerification{mock: verifier.mock, methodInvocations: methodInvocations} -} - -type ClusterMeta_DialOrDie_OngoingVerification struct { - mock *MockClusterMeta - methodInvocations []pegomock.MethodInvocation -} - -func (c *ClusterMeta_DialOrDie_OngoingVerification) GetCapturedArguments() { -} - -func (c *ClusterMeta_DialOrDie_OngoingVerification) GetAllCapturedArguments() { -} - -func (verifier *VerifierClusterMeta) DynDialOrDie() *ClusterMeta_DynDialOrDie_OngoingVerification { - params := []pegomock.Param{} - methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "DynDialOrDie", params, verifier.timeout) - return &ClusterMeta_DynDialOrDie_OngoingVerification{mock: verifier.mock, methodInvocations: methodInvocations} -} - -type ClusterMeta_DynDialOrDie_OngoingVerification struct { - mock *MockClusterMeta - methodInvocations []pegomock.MethodInvocation -} - -func (c *ClusterMeta_DynDialOrDie_OngoingVerification) GetCapturedArguments() { -} - -func (c *ClusterMeta_DynDialOrDie_OngoingVerification) GetAllCapturedArguments() { -} - -func (verifier *VerifierClusterMeta) FetchNodes() *ClusterMeta_FetchNodes_OngoingVerification { - params := []pegomock.Param{} - methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "FetchNodes", params, verifier.timeout) - return &ClusterMeta_FetchNodes_OngoingVerification{mock: verifier.mock, methodInvocations: methodInvocations} -} - -type ClusterMeta_FetchNodes_OngoingVerification struct { - mock *MockClusterMeta - methodInvocations []pegomock.MethodInvocation -} - -func (c *ClusterMeta_FetchNodes_OngoingVerification) GetCapturedArguments() { -} - -func (c *ClusterMeta_FetchNodes_OngoingVerification) GetAllCapturedArguments() { -} - -func (verifier *VerifierClusterMeta) GetNodes() *ClusterMeta_GetNodes_OngoingVerification { - params := []pegomock.Param{} - methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "GetNodes", params, verifier.timeout) - return &ClusterMeta_GetNodes_OngoingVerification{mock: verifier.mock, methodInvocations: methodInvocations} -} - -type ClusterMeta_GetNodes_OngoingVerification struct { - mock *MockClusterMeta - methodInvocations []pegomock.MethodInvocation -} - -func (c *ClusterMeta_GetNodes_OngoingVerification) GetCapturedArguments() { -} - -func (c *ClusterMeta_GetNodes_OngoingVerification) GetAllCapturedArguments() { -} - -func (verifier *VerifierClusterMeta) HasMetrics() *ClusterMeta_HasMetrics_OngoingVerification { - params := []pegomock.Param{} - methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "HasMetrics", params, verifier.timeout) - return &ClusterMeta_HasMetrics_OngoingVerification{mock: verifier.mock, methodInvocations: methodInvocations} -} - -type ClusterMeta_HasMetrics_OngoingVerification struct { - mock *MockClusterMeta - methodInvocations []pegomock.MethodInvocation -} - -func (c *ClusterMeta_HasMetrics_OngoingVerification) GetCapturedArguments() { -} - -func (c *ClusterMeta_HasMetrics_OngoingVerification) GetAllCapturedArguments() { -} - -func (verifier *VerifierClusterMeta) IsNamespaced(_param0 string) *ClusterMeta_IsNamespaced_OngoingVerification { - params := []pegomock.Param{_param0} - methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "IsNamespaced", params, verifier.timeout) - return &ClusterMeta_IsNamespaced_OngoingVerification{mock: verifier.mock, methodInvocations: methodInvocations} -} - -type ClusterMeta_IsNamespaced_OngoingVerification struct { - mock *MockClusterMeta - methodInvocations []pegomock.MethodInvocation -} - -func (c *ClusterMeta_IsNamespaced_OngoingVerification) GetCapturedArguments() string { - _param0 := c.GetAllCapturedArguments() - return _param0[len(_param0)-1] -} - -func (c *ClusterMeta_IsNamespaced_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) MXDial() *ClusterMeta_MXDial_OngoingVerification { - params := []pegomock.Param{} - methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "MXDial", params, verifier.timeout) - return &ClusterMeta_MXDial_OngoingVerification{mock: verifier.mock, methodInvocations: methodInvocations} -} - -type ClusterMeta_MXDial_OngoingVerification struct { - mock *MockClusterMeta - methodInvocations []pegomock.MethodInvocation -} - -func (c *ClusterMeta_MXDial_OngoingVerification) GetCapturedArguments() { -} - -func (c *ClusterMeta_MXDial_OngoingVerification) GetAllCapturedArguments() { -} - -func (verifier *VerifierClusterMeta) NSDialOrDie() *ClusterMeta_NSDialOrDie_OngoingVerification { - params := []pegomock.Param{} - methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "NSDialOrDie", params, verifier.timeout) - return &ClusterMeta_NSDialOrDie_OngoingVerification{mock: verifier.mock, methodInvocations: methodInvocations} -} - -type ClusterMeta_NSDialOrDie_OngoingVerification struct { - mock *MockClusterMeta - methodInvocations []pegomock.MethodInvocation -} - -func (c *ClusterMeta_NSDialOrDie_OngoingVerification) GetCapturedArguments() { -} - -func (c *ClusterMeta_NSDialOrDie_OngoingVerification) GetAllCapturedArguments() { -} - -func (verifier *VerifierClusterMeta) NodePods(_param0 string) *ClusterMeta_NodePods_OngoingVerification { - params := []pegomock.Param{_param0} - methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "NodePods", params, verifier.timeout) - return &ClusterMeta_NodePods_OngoingVerification{mock: verifier.mock, methodInvocations: methodInvocations} -} - -type ClusterMeta_NodePods_OngoingVerification struct { - mock *MockClusterMeta - methodInvocations []pegomock.MethodInvocation -} - -func (c *ClusterMeta_NodePods_OngoingVerification) GetCapturedArguments() string { - _param0 := c.GetAllCapturedArguments() - return _param0[len(_param0)-1] -} - -func (c *ClusterMeta_NodePods_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) RestConfigOrDie() *ClusterMeta_RestConfigOrDie_OngoingVerification { - params := []pegomock.Param{} - methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "RestConfigOrDie", params, verifier.timeout) - return &ClusterMeta_RestConfigOrDie_OngoingVerification{mock: verifier.mock, methodInvocations: methodInvocations} -} - -type ClusterMeta_RestConfigOrDie_OngoingVerification struct { - mock *MockClusterMeta - methodInvocations []pegomock.MethodInvocation -} - -func (c *ClusterMeta_RestConfigOrDie_OngoingVerification) GetCapturedArguments() { -} - -func (c *ClusterMeta_RestConfigOrDie_OngoingVerification) GetAllCapturedArguments() { -} - -func (verifier *VerifierClusterMeta) ServerVersion() *ClusterMeta_ServerVersion_OngoingVerification { - params := []pegomock.Param{} - methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "ServerVersion", params, verifier.timeout) - return &ClusterMeta_ServerVersion_OngoingVerification{mock: verifier.mock, methodInvocations: methodInvocations} -} - -type ClusterMeta_ServerVersion_OngoingVerification struct { - mock *MockClusterMeta - methodInvocations []pegomock.MethodInvocation -} - -func (c *ClusterMeta_ServerVersion_OngoingVerification) GetCapturedArguments() { -} - -func (c *ClusterMeta_ServerVersion_OngoingVerification) GetAllCapturedArguments() { -} - -func (verifier *VerifierClusterMeta) SupportsRes(_param0 string, _param1 []string) *ClusterMeta_SupportsRes_OngoingVerification { - params := []pegomock.Param{_param0, _param1} - methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "SupportsRes", params, verifier.timeout) - return &ClusterMeta_SupportsRes_OngoingVerification{mock: verifier.mock, methodInvocations: methodInvocations} -} - -type ClusterMeta_SupportsRes_OngoingVerification struct { - mock *MockClusterMeta - methodInvocations []pegomock.MethodInvocation -} - -func (c *ClusterMeta_SupportsRes_OngoingVerification) GetCapturedArguments() (string, []string) { - _param0, _param1 := c.GetAllCapturedArguments() - return _param0[len(_param0)-1], _param1[len(_param1)-1] -} - -func (c *ClusterMeta_SupportsRes_OngoingVerification) GetAllCapturedArguments() (_param0 []string, _param1 [][]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) - } - _param1 = make([][]string, len(params[1])) - for u, param := range params[1] { - _param1[u] = param.([]string) - } - } - return -} - -func (verifier *VerifierClusterMeta) SupportsResource(_param0 string) *ClusterMeta_SupportsResource_OngoingVerification { - params := []pegomock.Param{_param0} - methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "SupportsResource", params, verifier.timeout) - return &ClusterMeta_SupportsResource_OngoingVerification{mock: verifier.mock, methodInvocations: methodInvocations} -} - -type ClusterMeta_SupportsResource_OngoingVerification struct { - mock *MockClusterMeta - methodInvocations []pegomock.MethodInvocation -} - -func (c *ClusterMeta_SupportsResource_OngoingVerification) GetCapturedArguments() string { - _param0 := c.GetAllCapturedArguments() - return _param0[len(_param0)-1] -} - -func (c *ClusterMeta_SupportsResource_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) SwitchContextOrDie(_param0 string) *ClusterMeta_SwitchContextOrDie_OngoingVerification { - params := []pegomock.Param{_param0} - methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "SwitchContextOrDie", params, verifier.timeout) - return &ClusterMeta_SwitchContextOrDie_OngoingVerification{mock: verifier.mock, methodInvocations: methodInvocations} -} - -type ClusterMeta_SwitchContextOrDie_OngoingVerification struct { - mock *MockClusterMeta - methodInvocations []pegomock.MethodInvocation -} - -func (c *ClusterMeta_SwitchContextOrDie_OngoingVerification) GetCapturedArguments() string { - _param0 := c.GetAllCapturedArguments() - return _param0[len(_param0)-1] -} - -func (c *ClusterMeta_SwitchContextOrDie_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) UserName() *ClusterMeta_UserName_OngoingVerification { - params := []pegomock.Param{} - methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "UserName", params, verifier.timeout) - return &ClusterMeta_UserName_OngoingVerification{mock: verifier.mock, methodInvocations: methodInvocations} -} - -type ClusterMeta_UserName_OngoingVerification struct { - mock *MockClusterMeta - methodInvocations []pegomock.MethodInvocation -} - -func (c *ClusterMeta_UserName_OngoingVerification) GetCapturedArguments() { -} - -func (c *ClusterMeta_UserName_OngoingVerification) GetAllCapturedArguments() { -} - -func (verifier *VerifierClusterMeta) ValidNamespaces() *ClusterMeta_ValidNamespaces_OngoingVerification { - params := []pegomock.Param{} - methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "ValidNamespaces", params, verifier.timeout) - return &ClusterMeta_ValidNamespaces_OngoingVerification{mock: verifier.mock, methodInvocations: methodInvocations} -} - -type ClusterMeta_ValidNamespaces_OngoingVerification struct { - mock *MockClusterMeta - methodInvocations []pegomock.MethodInvocation -} - -func (c *ClusterMeta_ValidNamespaces_OngoingVerification) GetCapturedArguments() { -} - -func (c *ClusterMeta_ValidNamespaces_OngoingVerification) GetAllCapturedArguments() { -} - -func (verifier *VerifierClusterMeta) Version() *ClusterMeta_Version_OngoingVerification { - params := []pegomock.Param{} - methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "Version", params, verifier.timeout) - return &ClusterMeta_Version_OngoingVerification{mock: verifier.mock, methodInvocations: methodInvocations} -} - -type ClusterMeta_Version_OngoingVerification struct { - mock *MockClusterMeta - methodInvocations []pegomock.MethodInvocation -} - -func (c *ClusterMeta_Version_OngoingVerification) GetCapturedArguments() { -} - -func (c *ClusterMeta_Version_OngoingVerification) GetAllCapturedArguments() { -} diff --git a/internal/views/mock_connection.go b/internal/views/mock_connection.go deleted file mode 100644 index 66f8a948..00000000 --- a/internal/views/mock_connection.go +++ /dev/null @@ -1,711 +0,0 @@ -// Code generated by pegomock. DO NOT EDIT. -// Source: github.com/derailed/k9s/internal/config (interfaces: Connection) - -package views - -import ( - k8s "github.com/derailed/k9s/internal/k8s" - pegomock "github.com/petergtz/pegomock" - v1 "k8s.io/api/core/v1" - version "k8s.io/apimachinery/pkg/version" - dynamic "k8s.io/client-go/dynamic" - kubernetes "k8s.io/client-go/kubernetes" - rest "k8s.io/client-go/rest" - versioned "k8s.io/metrics/pkg/client/clientset/versioned" - "reflect" - "time" -) - -type MockConnection struct { - fail func(message string, callerSkip ...int) -} - -func NewMockConnection() *MockConnection { - return &MockConnection{fail: pegomock.GlobalFailHandler} -} - -func (mock *MockConnection) CanIAccess(_param0 string, _param1 string, _param2 string, _param3 []string) (bool, error) { - if mock == nil { - panic("mock must not be nil. Use myMock := NewMockConnection().") - } - params := []pegomock.Param{_param0, _param1, _param2, _param3} - result := pegomock.GetGenericMockFrom(mock).Invoke("CanIAccess", params, []reflect.Type{reflect.TypeOf((*bool)(nil)).Elem(), reflect.TypeOf((*error)(nil)).Elem()}) - var ret0 bool - var ret1 error - if len(result) != 0 { - if result[0] != nil { - ret0 = result[0].(bool) - } - if result[1] != nil { - ret1 = result[1].(error) - } - } - return ret0, ret1 -} - -func (mock *MockConnection) Config() *k8s.Config { - if mock == nil { - panic("mock must not be nil. Use myMock := NewMockConnection().") - } - params := []pegomock.Param{} - result := pegomock.GetGenericMockFrom(mock).Invoke("Config", params, []reflect.Type{reflect.TypeOf((**k8s.Config)(nil)).Elem()}) - var ret0 *k8s.Config - if len(result) != 0 { - if result[0] != nil { - ret0 = result[0].(*k8s.Config) - } - } - return ret0 -} - -func (mock *MockConnection) CurrentNamespaceName() (string, error) { - if mock == nil { - panic("mock must not be nil. Use myMock := NewMockConnection().") - } - params := []pegomock.Param{} - result := pegomock.GetGenericMockFrom(mock).Invoke("CurrentNamespaceName", 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 *MockConnection) DialOrDie() kubernetes.Interface { - if mock == nil { - panic("mock must not be nil. Use myMock := NewMockConnection().") - } - params := []pegomock.Param{} - result := pegomock.GetGenericMockFrom(mock).Invoke("DialOrDie", params, []reflect.Type{reflect.TypeOf((*kubernetes.Interface)(nil)).Elem()}) - var ret0 kubernetes.Interface - if len(result) != 0 { - if result[0] != nil { - ret0 = result[0].(kubernetes.Interface) - } - } - return ret0 -} - -func (mock *MockConnection) DynDialOrDie() dynamic.Interface { - if mock == nil { - panic("mock must not be nil. Use myMock := NewMockConnection().") - } - params := []pegomock.Param{} - result := pegomock.GetGenericMockFrom(mock).Invoke("DynDialOrDie", params, []reflect.Type{reflect.TypeOf((*dynamic.Interface)(nil)).Elem()}) - var ret0 dynamic.Interface - if len(result) != 0 { - if result[0] != nil { - ret0 = result[0].(dynamic.Interface) - } - } - return ret0 -} - -func (mock *MockConnection) FetchNodes() (*v1.NodeList, error) { - if mock == nil { - panic("mock must not be nil. Use myMock := NewMockConnection().") - } - params := []pegomock.Param{} - result := pegomock.GetGenericMockFrom(mock).Invoke("FetchNodes", params, []reflect.Type{reflect.TypeOf((**v1.NodeList)(nil)).Elem(), reflect.TypeOf((*error)(nil)).Elem()}) - var ret0 *v1.NodeList - var ret1 error - if len(result) != 0 { - if result[0] != nil { - ret0 = result[0].(*v1.NodeList) - } - if result[1] != nil { - ret1 = result[1].(error) - } - } - return ret0, ret1 -} - -func (mock *MockConnection) HasMetrics() bool { - if mock == nil { - panic("mock must not be nil. Use myMock := NewMockConnection().") - } - 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 *MockConnection) IsNamespaced(_param0 string) bool { - if mock == nil { - panic("mock must not be nil. Use myMock := NewMockConnection().") - } - params := []pegomock.Param{_param0} - result := pegomock.GetGenericMockFrom(mock).Invoke("IsNamespaced", 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 *MockConnection) MXDial() (*versioned.Clientset, error) { - if mock == nil { - panic("mock must not be nil. Use myMock := NewMockConnection().") - } - params := []pegomock.Param{} - result := pegomock.GetGenericMockFrom(mock).Invoke("MXDial", params, []reflect.Type{reflect.TypeOf((**versioned.Clientset)(nil)).Elem(), reflect.TypeOf((*error)(nil)).Elem()}) - var ret0 *versioned.Clientset - var ret1 error - if len(result) != 0 { - if result[0] != nil { - ret0 = result[0].(*versioned.Clientset) - } - if result[1] != nil { - ret1 = result[1].(error) - } - } - return ret0, ret1 -} - -func (mock *MockConnection) NSDialOrDie() dynamic.NamespaceableResourceInterface { - if mock == nil { - panic("mock must not be nil. Use myMock := NewMockConnection().") - } - params := []pegomock.Param{} - result := pegomock.GetGenericMockFrom(mock).Invoke("NSDialOrDie", params, []reflect.Type{reflect.TypeOf((*dynamic.NamespaceableResourceInterface)(nil)).Elem()}) - var ret0 dynamic.NamespaceableResourceInterface - if len(result) != 0 { - if result[0] != nil { - ret0 = result[0].(dynamic.NamespaceableResourceInterface) - } - } - return ret0 -} - -func (mock *MockConnection) NodePods(_param0 string) (*v1.PodList, error) { - if mock == nil { - panic("mock must not be nil. Use myMock := NewMockConnection().") - } - params := []pegomock.Param{_param0} - result := pegomock.GetGenericMockFrom(mock).Invoke("NodePods", params, []reflect.Type{reflect.TypeOf((**v1.PodList)(nil)).Elem(), reflect.TypeOf((*error)(nil)).Elem()}) - var ret0 *v1.PodList - var ret1 error - if len(result) != 0 { - if result[0] != nil { - ret0 = result[0].(*v1.PodList) - } - if result[1] != nil { - ret1 = result[1].(error) - } - } - return ret0, ret1 -} - -func (mock *MockConnection) RestConfigOrDie() *rest.Config { - if mock == nil { - panic("mock must not be nil. Use myMock := NewMockConnection().") - } - params := []pegomock.Param{} - result := pegomock.GetGenericMockFrom(mock).Invoke("RestConfigOrDie", params, []reflect.Type{reflect.TypeOf((**rest.Config)(nil)).Elem()}) - var ret0 *rest.Config - if len(result) != 0 { - if result[0] != nil { - ret0 = result[0].(*rest.Config) - } - } - return ret0 -} - -func (mock *MockConnection) ServerVersion() (*version.Info, error) { - if mock == nil { - panic("mock must not be nil. Use myMock := NewMockConnection().") - } - params := []pegomock.Param{} - result := pegomock.GetGenericMockFrom(mock).Invoke("ServerVersion", params, []reflect.Type{reflect.TypeOf((**version.Info)(nil)).Elem(), reflect.TypeOf((*error)(nil)).Elem()}) - var ret0 *version.Info - var ret1 error - if len(result) != 0 { - if result[0] != nil { - ret0 = result[0].(*version.Info) - } - if result[1] != nil { - ret1 = result[1].(error) - } - } - return ret0, ret1 -} - -func (mock *MockConnection) SupportsRes(_param0 string, _param1 []string) (string, bool, error) { - if mock == nil { - panic("mock must not be nil. Use myMock := NewMockConnection().") - } - params := []pegomock.Param{_param0, _param1} - result := pegomock.GetGenericMockFrom(mock).Invoke("SupportsRes", params, []reflect.Type{reflect.TypeOf((*string)(nil)).Elem(), reflect.TypeOf((*bool)(nil)).Elem(), reflect.TypeOf((*error)(nil)).Elem()}) - var ret0 string - var ret1 bool - var ret2 error - if len(result) != 0 { - if result[0] != nil { - ret0 = result[0].(string) - } - if result[1] != nil { - ret1 = result[1].(bool) - } - if result[2] != nil { - ret2 = result[2].(error) - } - } - return ret0, ret1, ret2 -} - -func (mock *MockConnection) SupportsResource(_param0 string) bool { - if mock == nil { - panic("mock must not be nil. Use myMock := NewMockConnection().") - } - params := []pegomock.Param{_param0} - result := pegomock.GetGenericMockFrom(mock).Invoke("SupportsResource", 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 *MockConnection) SwitchContextOrDie(_param0 string) { - if mock == nil { - panic("mock must not be nil. Use myMock := NewMockConnection().") - } - params := []pegomock.Param{_param0} - pegomock.GetGenericMockFrom(mock).Invoke("SwitchContextOrDie", params, []reflect.Type{}) -} - -func (mock *MockConnection) ValidNamespaces() ([]v1.Namespace, error) { - if mock == nil { - panic("mock must not be nil. Use myMock := NewMockConnection().") - } - params := []pegomock.Param{} - result := pegomock.GetGenericMockFrom(mock).Invoke("ValidNamespaces", params, []reflect.Type{reflect.TypeOf((*[]v1.Namespace)(nil)).Elem(), reflect.TypeOf((*error)(nil)).Elem()}) - var ret0 []v1.Namespace - var ret1 error - if len(result) != 0 { - if result[0] != nil { - ret0 = result[0].([]v1.Namespace) - } - if result[1] != nil { - ret1 = result[1].(error) - } - } - return ret0, ret1 -} - -func (mock *MockConnection) VerifyWasCalledOnce() *VerifierConnection { - return &VerifierConnection{ - mock: mock, - invocationCountMatcher: pegomock.Times(1), - } -} - -func (mock *MockConnection) VerifyWasCalled(invocationCountMatcher pegomock.Matcher) *VerifierConnection { - return &VerifierConnection{ - mock: mock, - invocationCountMatcher: invocationCountMatcher, - } -} - -func (mock *MockConnection) VerifyWasCalledInOrder(invocationCountMatcher pegomock.Matcher, inOrderContext *pegomock.InOrderContext) *VerifierConnection { - return &VerifierConnection{ - mock: mock, - invocationCountMatcher: invocationCountMatcher, - inOrderContext: inOrderContext, - } -} - -func (mock *MockConnection) VerifyWasCalledEventually(invocationCountMatcher pegomock.Matcher, timeout time.Duration) *VerifierConnection { - return &VerifierConnection{ - mock: mock, - invocationCountMatcher: invocationCountMatcher, - timeout: timeout, - } -} - -type VerifierConnection struct { - mock *MockConnection - invocationCountMatcher pegomock.Matcher - inOrderContext *pegomock.InOrderContext - timeout time.Duration -} - -func (verifier *VerifierConnection) CanIAccess(_param0 string, _param1 string, _param2 string, _param3 []string) *Connection_CanIAccess_OngoingVerification { - params := []pegomock.Param{_param0, _param1, _param2, _param3} - methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "CanIAccess", params, verifier.timeout) - return &Connection_CanIAccess_OngoingVerification{mock: verifier.mock, methodInvocations: methodInvocations} -} - -type Connection_CanIAccess_OngoingVerification struct { - mock *MockConnection - methodInvocations []pegomock.MethodInvocation -} - -func (c *Connection_CanIAccess_OngoingVerification) GetCapturedArguments() (string, string, string, []string) { - _param0, _param1, _param2, _param3 := c.GetAllCapturedArguments() - return _param0[len(_param0)-1], _param1[len(_param1)-1], _param2[len(_param2)-1], _param3[len(_param3)-1] -} - -func (c *Connection_CanIAccess_OngoingVerification) GetAllCapturedArguments() (_param0 []string, _param1 []string, _param2 []string, _param3 [][]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) - } - _param1 = make([]string, len(params[1])) - for u, param := range params[1] { - _param1[u] = param.(string) - } - _param2 = make([]string, len(params[2])) - for u, param := range params[2] { - _param2[u] = param.(string) - } - _param3 = make([][]string, len(params[3])) - for u, param := range params[3] { - _param3[u] = param.([]string) - } - } - return -} - -func (verifier *VerifierConnection) Config() *Connection_Config_OngoingVerification { - params := []pegomock.Param{} - methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "Config", params, verifier.timeout) - return &Connection_Config_OngoingVerification{mock: verifier.mock, methodInvocations: methodInvocations} -} - -type Connection_Config_OngoingVerification struct { - mock *MockConnection - methodInvocations []pegomock.MethodInvocation -} - -func (c *Connection_Config_OngoingVerification) GetCapturedArguments() { -} - -func (c *Connection_Config_OngoingVerification) GetAllCapturedArguments() { -} - -func (verifier *VerifierConnection) CurrentNamespaceName() *Connection_CurrentNamespaceName_OngoingVerification { - params := []pegomock.Param{} - methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "CurrentNamespaceName", params, verifier.timeout) - return &Connection_CurrentNamespaceName_OngoingVerification{mock: verifier.mock, methodInvocations: methodInvocations} -} - -type Connection_CurrentNamespaceName_OngoingVerification struct { - mock *MockConnection - methodInvocations []pegomock.MethodInvocation -} - -func (c *Connection_CurrentNamespaceName_OngoingVerification) GetCapturedArguments() { -} - -func (c *Connection_CurrentNamespaceName_OngoingVerification) GetAllCapturedArguments() { -} - -func (verifier *VerifierConnection) DialOrDie() *Connection_DialOrDie_OngoingVerification { - params := []pegomock.Param{} - methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "DialOrDie", params, verifier.timeout) - return &Connection_DialOrDie_OngoingVerification{mock: verifier.mock, methodInvocations: methodInvocations} -} - -type Connection_DialOrDie_OngoingVerification struct { - mock *MockConnection - methodInvocations []pegomock.MethodInvocation -} - -func (c *Connection_DialOrDie_OngoingVerification) GetCapturedArguments() { -} - -func (c *Connection_DialOrDie_OngoingVerification) GetAllCapturedArguments() { -} - -func (verifier *VerifierConnection) DynDialOrDie() *Connection_DynDialOrDie_OngoingVerification { - params := []pegomock.Param{} - methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "DynDialOrDie", params, verifier.timeout) - return &Connection_DynDialOrDie_OngoingVerification{mock: verifier.mock, methodInvocations: methodInvocations} -} - -type Connection_DynDialOrDie_OngoingVerification struct { - mock *MockConnection - methodInvocations []pegomock.MethodInvocation -} - -func (c *Connection_DynDialOrDie_OngoingVerification) GetCapturedArguments() { -} - -func (c *Connection_DynDialOrDie_OngoingVerification) GetAllCapturedArguments() { -} - -func (verifier *VerifierConnection) FetchNodes() *Connection_FetchNodes_OngoingVerification { - params := []pegomock.Param{} - methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "FetchNodes", params, verifier.timeout) - return &Connection_FetchNodes_OngoingVerification{mock: verifier.mock, methodInvocations: methodInvocations} -} - -type Connection_FetchNodes_OngoingVerification struct { - mock *MockConnection - methodInvocations []pegomock.MethodInvocation -} - -func (c *Connection_FetchNodes_OngoingVerification) GetCapturedArguments() { -} - -func (c *Connection_FetchNodes_OngoingVerification) GetAllCapturedArguments() { -} - -func (verifier *VerifierConnection) HasMetrics() *Connection_HasMetrics_OngoingVerification { - params := []pegomock.Param{} - methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "HasMetrics", params, verifier.timeout) - return &Connection_HasMetrics_OngoingVerification{mock: verifier.mock, methodInvocations: methodInvocations} -} - -type Connection_HasMetrics_OngoingVerification struct { - mock *MockConnection - methodInvocations []pegomock.MethodInvocation -} - -func (c *Connection_HasMetrics_OngoingVerification) GetCapturedArguments() { -} - -func (c *Connection_HasMetrics_OngoingVerification) GetAllCapturedArguments() { -} - -func (verifier *VerifierConnection) IsNamespaced(_param0 string) *Connection_IsNamespaced_OngoingVerification { - params := []pegomock.Param{_param0} - methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "IsNamespaced", params, verifier.timeout) - return &Connection_IsNamespaced_OngoingVerification{mock: verifier.mock, methodInvocations: methodInvocations} -} - -type Connection_IsNamespaced_OngoingVerification struct { - mock *MockConnection - methodInvocations []pegomock.MethodInvocation -} - -func (c *Connection_IsNamespaced_OngoingVerification) GetCapturedArguments() string { - _param0 := c.GetAllCapturedArguments() - return _param0[len(_param0)-1] -} - -func (c *Connection_IsNamespaced_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 *VerifierConnection) MXDial() *Connection_MXDial_OngoingVerification { - params := []pegomock.Param{} - methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "MXDial", params, verifier.timeout) - return &Connection_MXDial_OngoingVerification{mock: verifier.mock, methodInvocations: methodInvocations} -} - -type Connection_MXDial_OngoingVerification struct { - mock *MockConnection - methodInvocations []pegomock.MethodInvocation -} - -func (c *Connection_MXDial_OngoingVerification) GetCapturedArguments() { -} - -func (c *Connection_MXDial_OngoingVerification) GetAllCapturedArguments() { -} - -func (verifier *VerifierConnection) NSDialOrDie() *Connection_NSDialOrDie_OngoingVerification { - params := []pegomock.Param{} - methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "NSDialOrDie", params, verifier.timeout) - return &Connection_NSDialOrDie_OngoingVerification{mock: verifier.mock, methodInvocations: methodInvocations} -} - -type Connection_NSDialOrDie_OngoingVerification struct { - mock *MockConnection - methodInvocations []pegomock.MethodInvocation -} - -func (c *Connection_NSDialOrDie_OngoingVerification) GetCapturedArguments() { -} - -func (c *Connection_NSDialOrDie_OngoingVerification) GetAllCapturedArguments() { -} - -func (verifier *VerifierConnection) NodePods(_param0 string) *Connection_NodePods_OngoingVerification { - params := []pegomock.Param{_param0} - methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "NodePods", params, verifier.timeout) - return &Connection_NodePods_OngoingVerification{mock: verifier.mock, methodInvocations: methodInvocations} -} - -type Connection_NodePods_OngoingVerification struct { - mock *MockConnection - methodInvocations []pegomock.MethodInvocation -} - -func (c *Connection_NodePods_OngoingVerification) GetCapturedArguments() string { - _param0 := c.GetAllCapturedArguments() - return _param0[len(_param0)-1] -} - -func (c *Connection_NodePods_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 *VerifierConnection) RestConfigOrDie() *Connection_RestConfigOrDie_OngoingVerification { - params := []pegomock.Param{} - methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "RestConfigOrDie", params, verifier.timeout) - return &Connection_RestConfigOrDie_OngoingVerification{mock: verifier.mock, methodInvocations: methodInvocations} -} - -type Connection_RestConfigOrDie_OngoingVerification struct { - mock *MockConnection - methodInvocations []pegomock.MethodInvocation -} - -func (c *Connection_RestConfigOrDie_OngoingVerification) GetCapturedArguments() { -} - -func (c *Connection_RestConfigOrDie_OngoingVerification) GetAllCapturedArguments() { -} - -func (verifier *VerifierConnection) ServerVersion() *Connection_ServerVersion_OngoingVerification { - params := []pegomock.Param{} - methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "ServerVersion", params, verifier.timeout) - return &Connection_ServerVersion_OngoingVerification{mock: verifier.mock, methodInvocations: methodInvocations} -} - -type Connection_ServerVersion_OngoingVerification struct { - mock *MockConnection - methodInvocations []pegomock.MethodInvocation -} - -func (c *Connection_ServerVersion_OngoingVerification) GetCapturedArguments() { -} - -func (c *Connection_ServerVersion_OngoingVerification) GetAllCapturedArguments() { -} - -func (verifier *VerifierConnection) SupportsRes(_param0 string, _param1 []string) *Connection_SupportsRes_OngoingVerification { - params := []pegomock.Param{_param0, _param1} - methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "SupportsRes", params, verifier.timeout) - return &Connection_SupportsRes_OngoingVerification{mock: verifier.mock, methodInvocations: methodInvocations} -} - -type Connection_SupportsRes_OngoingVerification struct { - mock *MockConnection - methodInvocations []pegomock.MethodInvocation -} - -func (c *Connection_SupportsRes_OngoingVerification) GetCapturedArguments() (string, []string) { - _param0, _param1 := c.GetAllCapturedArguments() - return _param0[len(_param0)-1], _param1[len(_param1)-1] -} - -func (c *Connection_SupportsRes_OngoingVerification) GetAllCapturedArguments() (_param0 []string, _param1 [][]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) - } - _param1 = make([][]string, len(params[1])) - for u, param := range params[1] { - _param1[u] = param.([]string) - } - } - return -} - -func (verifier *VerifierConnection) SupportsResource(_param0 string) *Connection_SupportsResource_OngoingVerification { - params := []pegomock.Param{_param0} - methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "SupportsResource", params, verifier.timeout) - return &Connection_SupportsResource_OngoingVerification{mock: verifier.mock, methodInvocations: methodInvocations} -} - -type Connection_SupportsResource_OngoingVerification struct { - mock *MockConnection - methodInvocations []pegomock.MethodInvocation -} - -func (c *Connection_SupportsResource_OngoingVerification) GetCapturedArguments() string { - _param0 := c.GetAllCapturedArguments() - return _param0[len(_param0)-1] -} - -func (c *Connection_SupportsResource_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 *VerifierConnection) SwitchContextOrDie(_param0 string) *Connection_SwitchContextOrDie_OngoingVerification { - params := []pegomock.Param{_param0} - methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "SwitchContextOrDie", params, verifier.timeout) - return &Connection_SwitchContextOrDie_OngoingVerification{mock: verifier.mock, methodInvocations: methodInvocations} -} - -type Connection_SwitchContextOrDie_OngoingVerification struct { - mock *MockConnection - methodInvocations []pegomock.MethodInvocation -} - -func (c *Connection_SwitchContextOrDie_OngoingVerification) GetCapturedArguments() string { - _param0 := c.GetAllCapturedArguments() - return _param0[len(_param0)-1] -} - -func (c *Connection_SwitchContextOrDie_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 *VerifierConnection) ValidNamespaces() *Connection_ValidNamespaces_OngoingVerification { - params := []pegomock.Param{} - methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "ValidNamespaces", params, verifier.timeout) - return &Connection_ValidNamespaces_OngoingVerification{mock: verifier.mock, methodInvocations: methodInvocations} -} - -type Connection_ValidNamespaces_OngoingVerification struct { - mock *MockConnection - methodInvocations []pegomock.MethodInvocation -} - -func (c *Connection_ValidNamespaces_OngoingVerification) GetCapturedArguments() { -} - -func (c *Connection_ValidNamespaces_OngoingVerification) GetAllCapturedArguments() { -} diff --git a/internal/views/mock_kubesettings.go b/internal/views/mock_kubesettings.go deleted file mode 100644 index fda68e58..00000000 --- a/internal/views/mock_kubesettings.go +++ /dev/null @@ -1,242 +0,0 @@ -// Code generated by pegomock. DO NOT EDIT. -// Source: github.com/derailed/k9s/internal/config (interfaces: KubeSettings) - -package views - -import ( - pegomock "github.com/petergtz/pegomock" - v1 "k8s.io/api/core/v1" - "reflect" - "time" -) - -type MockKubeSettings struct { - fail func(message string, callerSkip ...int) -} - -func NewMockKubeSettings() *MockKubeSettings { - return &MockKubeSettings{fail: pegomock.GlobalFailHandler} -} - -func (mock *MockKubeSettings) ClusterNames() ([]string, error) { - if mock == nil { - panic("mock must not be nil. Use myMock := NewMockKubeSettings().") - } - params := []pegomock.Param{} - result := pegomock.GetGenericMockFrom(mock).Invoke("ClusterNames", 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 *MockKubeSettings) CurrentClusterName() (string, error) { - if mock == nil { - panic("mock must not be nil. Use myMock := NewMockKubeSettings().") - } - params := []pegomock.Param{} - result := pegomock.GetGenericMockFrom(mock).Invoke("CurrentClusterName", 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 *MockKubeSettings) CurrentContextName() (string, error) { - if mock == nil { - panic("mock must not be nil. Use myMock := NewMockKubeSettings().") - } - params := []pegomock.Param{} - result := pegomock.GetGenericMockFrom(mock).Invoke("CurrentContextName", 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 *MockKubeSettings) CurrentNamespaceName() (string, error) { - if mock == nil { - panic("mock must not be nil. Use myMock := NewMockKubeSettings().") - } - params := []pegomock.Param{} - result := pegomock.GetGenericMockFrom(mock).Invoke("CurrentNamespaceName", 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 *MockKubeSettings) NamespaceNames(_param0 []v1.Namespace) []string { - if mock == nil { - panic("mock must not be nil. Use myMock := NewMockKubeSettings().") - } - params := []pegomock.Param{_param0} - result := pegomock.GetGenericMockFrom(mock).Invoke("NamespaceNames", params, []reflect.Type{reflect.TypeOf((*[]string)(nil)).Elem()}) - var ret0 []string - if len(result) != 0 { - if result[0] != nil { - ret0 = result[0].([]string) - } - } - return ret0 -} - -func (mock *MockKubeSettings) VerifyWasCalledOnce() *VerifierKubeSettings { - return &VerifierKubeSettings{ - mock: mock, - invocationCountMatcher: pegomock.Times(1), - } -} - -func (mock *MockKubeSettings) VerifyWasCalled(invocationCountMatcher pegomock.Matcher) *VerifierKubeSettings { - return &VerifierKubeSettings{ - mock: mock, - invocationCountMatcher: invocationCountMatcher, - } -} - -func (mock *MockKubeSettings) VerifyWasCalledInOrder(invocationCountMatcher pegomock.Matcher, inOrderContext *pegomock.InOrderContext) *VerifierKubeSettings { - return &VerifierKubeSettings{ - mock: mock, - invocationCountMatcher: invocationCountMatcher, - inOrderContext: inOrderContext, - } -} - -func (mock *MockKubeSettings) VerifyWasCalledEventually(invocationCountMatcher pegomock.Matcher, timeout time.Duration) *VerifierKubeSettings { - return &VerifierKubeSettings{ - mock: mock, - invocationCountMatcher: invocationCountMatcher, - timeout: timeout, - } -} - -type VerifierKubeSettings struct { - mock *MockKubeSettings - invocationCountMatcher pegomock.Matcher - inOrderContext *pegomock.InOrderContext - timeout time.Duration -} - -func (verifier *VerifierKubeSettings) ClusterNames() *KubeSettings_ClusterNames_OngoingVerification { - params := []pegomock.Param{} - methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "ClusterNames", params, verifier.timeout) - return &KubeSettings_ClusterNames_OngoingVerification{mock: verifier.mock, methodInvocations: methodInvocations} -} - -type KubeSettings_ClusterNames_OngoingVerification struct { - mock *MockKubeSettings - methodInvocations []pegomock.MethodInvocation -} - -func (c *KubeSettings_ClusterNames_OngoingVerification) GetCapturedArguments() { -} - -func (c *KubeSettings_ClusterNames_OngoingVerification) GetAllCapturedArguments() { -} - -func (verifier *VerifierKubeSettings) CurrentClusterName() *KubeSettings_CurrentClusterName_OngoingVerification { - params := []pegomock.Param{} - methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "CurrentClusterName", params, verifier.timeout) - return &KubeSettings_CurrentClusterName_OngoingVerification{mock: verifier.mock, methodInvocations: methodInvocations} -} - -type KubeSettings_CurrentClusterName_OngoingVerification struct { - mock *MockKubeSettings - methodInvocations []pegomock.MethodInvocation -} - -func (c *KubeSettings_CurrentClusterName_OngoingVerification) GetCapturedArguments() { -} - -func (c *KubeSettings_CurrentClusterName_OngoingVerification) GetAllCapturedArguments() { -} - -func (verifier *VerifierKubeSettings) CurrentContextName() *KubeSettings_CurrentContextName_OngoingVerification { - params := []pegomock.Param{} - methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "CurrentContextName", params, verifier.timeout) - return &KubeSettings_CurrentContextName_OngoingVerification{mock: verifier.mock, methodInvocations: methodInvocations} -} - -type KubeSettings_CurrentContextName_OngoingVerification struct { - mock *MockKubeSettings - methodInvocations []pegomock.MethodInvocation -} - -func (c *KubeSettings_CurrentContextName_OngoingVerification) GetCapturedArguments() { -} - -func (c *KubeSettings_CurrentContextName_OngoingVerification) GetAllCapturedArguments() { -} - -func (verifier *VerifierKubeSettings) CurrentNamespaceName() *KubeSettings_CurrentNamespaceName_OngoingVerification { - params := []pegomock.Param{} - methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "CurrentNamespaceName", params, verifier.timeout) - return &KubeSettings_CurrentNamespaceName_OngoingVerification{mock: verifier.mock, methodInvocations: methodInvocations} -} - -type KubeSettings_CurrentNamespaceName_OngoingVerification struct { - mock *MockKubeSettings - methodInvocations []pegomock.MethodInvocation -} - -func (c *KubeSettings_CurrentNamespaceName_OngoingVerification) GetCapturedArguments() { -} - -func (c *KubeSettings_CurrentNamespaceName_OngoingVerification) GetAllCapturedArguments() { -} - -func (verifier *VerifierKubeSettings) NamespaceNames(_param0 []v1.Namespace) *KubeSettings_NamespaceNames_OngoingVerification { - params := []pegomock.Param{_param0} - methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "NamespaceNames", params, verifier.timeout) - return &KubeSettings_NamespaceNames_OngoingVerification{mock: verifier.mock, methodInvocations: methodInvocations} -} - -type KubeSettings_NamespaceNames_OngoingVerification struct { - mock *MockKubeSettings - methodInvocations []pegomock.MethodInvocation -} - -func (c *KubeSettings_NamespaceNames_OngoingVerification) GetCapturedArguments() []v1.Namespace { - _param0 := c.GetAllCapturedArguments() - return _param0[len(_param0)-1] -} - -func (c *KubeSettings_NamespaceNames_OngoingVerification) GetAllCapturedArguments() (_param0 [][]v1.Namespace) { - params := pegomock.GetGenericMockFrom(c.mock).GetInvocationParams(c.methodInvocations) - if len(params) > 0 { - _param0 = make([][]v1.Namespace, len(params[0])) - for u, param := range params[0] { - _param0[u] = param.([]v1.Namespace) - } - } - return -} diff --git a/internal/views/mock_metricsserver.go b/internal/views/mock_metricsserver.go deleted file mode 100644 index d5700512..00000000 --- a/internal/views/mock_metricsserver.go +++ /dev/null @@ -1,296 +0,0 @@ -// Code generated by pegomock. DO NOT EDIT. -// Source: github.com/derailed/k9s/internal/resource (interfaces: MetricsServer) - -package views - -import ( - k8s "github.com/derailed/k9s/internal/k8s" - pegomock "github.com/petergtz/pegomock" - v1beta1 "k8s.io/metrics/pkg/apis/metrics/v1beta1" - "reflect" - "time" -) - -type MockMetricsServer struct { - fail func(message string, callerSkip ...int) -} - -func NewMockMetricsServer() *MockMetricsServer { - return &MockMetricsServer{fail: pegomock.GlobalFailHandler} -} - -func (mock *MockMetricsServer) ClusterLoad(_param0 k8s.Collection, _param1 k8s.Collection, _param2 *k8s.ClusterMetrics) { - if mock == nil { - panic("mock must not be nil. Use myMock := NewMockMetricsServer().") - } - params := []pegomock.Param{_param0, _param1, _param2} - pegomock.GetGenericMockFrom(mock).Invoke("ClusterLoad", params, []reflect.Type{}) -} - -func (mock *MockMetricsServer) FetchNodesMetrics() (*v1beta1.NodeMetricsList, error) { - if mock == nil { - panic("mock must not be nil. Use myMock := NewMockMetricsServer().") - } - params := []pegomock.Param{} - result := pegomock.GetGenericMockFrom(mock).Invoke("FetchNodesMetrics", params, []reflect.Type{reflect.TypeOf((**v1beta1.NodeMetricsList)(nil)).Elem(), reflect.TypeOf((*error)(nil)).Elem()}) - var ret0 *v1beta1.NodeMetricsList - var ret1 error - if len(result) != 0 { - if result[0] != nil { - ret0 = result[0].(*v1beta1.NodeMetricsList) - } - if result[1] != nil { - ret1 = result[1].(error) - } - } - return ret0, ret1 -} - -func (mock *MockMetricsServer) FetchPodsMetrics(_param0 string) (*v1beta1.PodMetricsList, error) { - if mock == nil { - panic("mock must not be nil. Use myMock := NewMockMetricsServer().") - } - params := []pegomock.Param{_param0} - result := pegomock.GetGenericMockFrom(mock).Invoke("FetchPodsMetrics", params, []reflect.Type{reflect.TypeOf((**v1beta1.PodMetricsList)(nil)).Elem(), reflect.TypeOf((*error)(nil)).Elem()}) - var ret0 *v1beta1.PodMetricsList - var ret1 error - if len(result) != 0 { - if result[0] != nil { - ret0 = result[0].(*v1beta1.PodMetricsList) - } - if result[1] != nil { - ret1 = result[1].(error) - } - } - return ret0, ret1 -} - -func (mock *MockMetricsServer) HasMetrics() bool { - if mock == nil { - panic("mock must not be nil. Use myMock := NewMockMetricsServer().") - } - 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 *MockMetricsServer) NodesMetrics(_param0 k8s.Collection, _param1 *v1beta1.NodeMetricsList, _param2 k8s.NodesMetrics) { - if mock == nil { - panic("mock must not be nil. Use myMock := NewMockMetricsServer().") - } - params := []pegomock.Param{_param0, _param1, _param2} - pegomock.GetGenericMockFrom(mock).Invoke("NodesMetrics", params, []reflect.Type{}) -} - -func (mock *MockMetricsServer) PodsMetrics(_param0 *v1beta1.PodMetricsList, _param1 k8s.PodsMetrics) { - if mock == nil { - panic("mock must not be nil. Use myMock := NewMockMetricsServer().") - } - params := []pegomock.Param{_param0, _param1} - pegomock.GetGenericMockFrom(mock).Invoke("PodsMetrics", params, []reflect.Type{}) -} - -func (mock *MockMetricsServer) VerifyWasCalledOnce() *VerifierMetricsServer { - return &VerifierMetricsServer{ - mock: mock, - invocationCountMatcher: pegomock.Times(1), - } -} - -func (mock *MockMetricsServer) VerifyWasCalled(invocationCountMatcher pegomock.Matcher) *VerifierMetricsServer { - return &VerifierMetricsServer{ - mock: mock, - invocationCountMatcher: invocationCountMatcher, - } -} - -func (mock *MockMetricsServer) VerifyWasCalledInOrder(invocationCountMatcher pegomock.Matcher, inOrderContext *pegomock.InOrderContext) *VerifierMetricsServer { - return &VerifierMetricsServer{ - mock: mock, - invocationCountMatcher: invocationCountMatcher, - inOrderContext: inOrderContext, - } -} - -func (mock *MockMetricsServer) VerifyWasCalledEventually(invocationCountMatcher pegomock.Matcher, timeout time.Duration) *VerifierMetricsServer { - return &VerifierMetricsServer{ - mock: mock, - invocationCountMatcher: invocationCountMatcher, - timeout: timeout, - } -} - -type VerifierMetricsServer struct { - mock *MockMetricsServer - invocationCountMatcher pegomock.Matcher - inOrderContext *pegomock.InOrderContext - timeout time.Duration -} - -func (verifier *VerifierMetricsServer) ClusterLoad(_param0 k8s.Collection, _param1 k8s.Collection, _param2 *k8s.ClusterMetrics) *MetricsServer_ClusterLoad_OngoingVerification { - params := []pegomock.Param{_param0, _param1, _param2} - methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "ClusterLoad", params, verifier.timeout) - return &MetricsServer_ClusterLoad_OngoingVerification{mock: verifier.mock, methodInvocations: methodInvocations} -} - -type MetricsServer_ClusterLoad_OngoingVerification struct { - mock *MockMetricsServer - methodInvocations []pegomock.MethodInvocation -} - -func (c *MetricsServer_ClusterLoad_OngoingVerification) GetCapturedArguments() (k8s.Collection, k8s.Collection, *k8s.ClusterMetrics) { - _param0, _param1, _param2 := c.GetAllCapturedArguments() - return _param0[len(_param0)-1], _param1[len(_param1)-1], _param2[len(_param2)-1] -} - -func (c *MetricsServer_ClusterLoad_OngoingVerification) GetAllCapturedArguments() (_param0 []k8s.Collection, _param1 []k8s.Collection, _param2 []*k8s.ClusterMetrics) { - params := pegomock.GetGenericMockFrom(c.mock).GetInvocationParams(c.methodInvocations) - if len(params) > 0 { - _param0 = make([]k8s.Collection, len(params[0])) - for u, param := range params[0] { - _param0[u] = param.(k8s.Collection) - } - _param1 = make([]k8s.Collection, len(params[1])) - for u, param := range params[1] { - _param1[u] = param.(k8s.Collection) - } - _param2 = make([]*k8s.ClusterMetrics, len(params[2])) - for u, param := range params[2] { - _param2[u] = param.(*k8s.ClusterMetrics) - } - } - return -} - -func (verifier *VerifierMetricsServer) FetchNodesMetrics() *MetricsServer_FetchNodesMetrics_OngoingVerification { - params := []pegomock.Param{} - methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "FetchNodesMetrics", params, verifier.timeout) - return &MetricsServer_FetchNodesMetrics_OngoingVerification{mock: verifier.mock, methodInvocations: methodInvocations} -} - -type MetricsServer_FetchNodesMetrics_OngoingVerification struct { - mock *MockMetricsServer - methodInvocations []pegomock.MethodInvocation -} - -func (c *MetricsServer_FetchNodesMetrics_OngoingVerification) GetCapturedArguments() { -} - -func (c *MetricsServer_FetchNodesMetrics_OngoingVerification) GetAllCapturedArguments() { -} - -func (verifier *VerifierMetricsServer) FetchPodsMetrics(_param0 string) *MetricsServer_FetchPodsMetrics_OngoingVerification { - params := []pegomock.Param{_param0} - methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "FetchPodsMetrics", params, verifier.timeout) - return &MetricsServer_FetchPodsMetrics_OngoingVerification{mock: verifier.mock, methodInvocations: methodInvocations} -} - -type MetricsServer_FetchPodsMetrics_OngoingVerification struct { - mock *MockMetricsServer - methodInvocations []pegomock.MethodInvocation -} - -func (c *MetricsServer_FetchPodsMetrics_OngoingVerification) GetCapturedArguments() string { - _param0 := c.GetAllCapturedArguments() - return _param0[len(_param0)-1] -} - -func (c *MetricsServer_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 *VerifierMetricsServer) HasMetrics() *MetricsServer_HasMetrics_OngoingVerification { - params := []pegomock.Param{} - methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "HasMetrics", params, verifier.timeout) - return &MetricsServer_HasMetrics_OngoingVerification{mock: verifier.mock, methodInvocations: methodInvocations} -} - -type MetricsServer_HasMetrics_OngoingVerification struct { - mock *MockMetricsServer - methodInvocations []pegomock.MethodInvocation -} - -func (c *MetricsServer_HasMetrics_OngoingVerification) GetCapturedArguments() { -} - -func (c *MetricsServer_HasMetrics_OngoingVerification) GetAllCapturedArguments() { -} - -func (verifier *VerifierMetricsServer) NodesMetrics(_param0 k8s.Collection, _param1 *v1beta1.NodeMetricsList, _param2 k8s.NodesMetrics) *MetricsServer_NodesMetrics_OngoingVerification { - params := []pegomock.Param{_param0, _param1, _param2} - methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "NodesMetrics", params, verifier.timeout) - return &MetricsServer_NodesMetrics_OngoingVerification{mock: verifier.mock, methodInvocations: methodInvocations} -} - -type MetricsServer_NodesMetrics_OngoingVerification struct { - mock *MockMetricsServer - methodInvocations []pegomock.MethodInvocation -} - -func (c *MetricsServer_NodesMetrics_OngoingVerification) GetCapturedArguments() (k8s.Collection, *v1beta1.NodeMetricsList, k8s.NodesMetrics) { - _param0, _param1, _param2 := c.GetAllCapturedArguments() - return _param0[len(_param0)-1], _param1[len(_param1)-1], _param2[len(_param2)-1] -} - -func (c *MetricsServer_NodesMetrics_OngoingVerification) GetAllCapturedArguments() (_param0 []k8s.Collection, _param1 []*v1beta1.NodeMetricsList, _param2 []k8s.NodesMetrics) { - params := pegomock.GetGenericMockFrom(c.mock).GetInvocationParams(c.methodInvocations) - if len(params) > 0 { - _param0 = make([]k8s.Collection, len(params[0])) - for u, param := range params[0] { - _param0[u] = param.(k8s.Collection) - } - _param1 = make([]*v1beta1.NodeMetricsList, len(params[1])) - for u, param := range params[1] { - _param1[u] = param.(*v1beta1.NodeMetricsList) - } - _param2 = make([]k8s.NodesMetrics, len(params[2])) - for u, param := range params[2] { - _param2[u] = param.(k8s.NodesMetrics) - } - } - return -} - -func (verifier *VerifierMetricsServer) PodsMetrics(_param0 *v1beta1.PodMetricsList, _param1 k8s.PodsMetrics) *MetricsServer_PodsMetrics_OngoingVerification { - params := []pegomock.Param{_param0, _param1} - methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "PodsMetrics", params, verifier.timeout) - return &MetricsServer_PodsMetrics_OngoingVerification{mock: verifier.mock, methodInvocations: methodInvocations} -} - -type MetricsServer_PodsMetrics_OngoingVerification struct { - mock *MockMetricsServer - methodInvocations []pegomock.MethodInvocation -} - -func (c *MetricsServer_PodsMetrics_OngoingVerification) GetCapturedArguments() (*v1beta1.PodMetricsList, k8s.PodsMetrics) { - _param0, _param1 := c.GetAllCapturedArguments() - return _param0[len(_param0)-1], _param1[len(_param1)-1] -} - -func (c *MetricsServer_PodsMetrics_OngoingVerification) GetAllCapturedArguments() (_param0 []*v1beta1.PodMetricsList, _param1 []k8s.PodsMetrics) { - params := pegomock.GetGenericMockFrom(c.mock).GetInvocationParams(c.methodInvocations) - if len(params) > 0 { - _param0 = make([]*v1beta1.PodMetricsList, len(params[0])) - for u, param := range params[0] { - _param0[u] = param.(*v1beta1.PodMetricsList) - } - _param1 = make([]k8s.PodsMetrics, len(params[1])) - for u, param := range params[1] { - _param1[u] = param.(k8s.PodsMetrics) - } - } - return -} diff --git a/internal/views/mock_metricsservice.go b/internal/views/mock_metricsservice.go deleted file mode 100644 index 766a99a5..00000000 --- a/internal/views/mock_metricsservice.go +++ /dev/null @@ -1,170 +0,0 @@ -// Code generated by pegomock. DO NOT EDIT. -// Source: github.com/derailed/k9s/internal/resource (interfaces: MetricsService) - -package views - -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/views/no.go b/internal/views/no.go index 2852aaf9..1863dc6f 100644 --- a/internal/views/no.go +++ b/internal/views/no.go @@ -26,7 +26,7 @@ func (v *nodeView) extraActions(aa keyActions) { func (v *nodeView) sortColCmd(col int, asc bool) func(evt *tcell.EventKey) *tcell.EventKey { return func(evt *tcell.EventKey) *tcell.EventKey { - t := v.getTV() + t := v.masterPage() t.sortCol.index, t.sortCol.asc = t.nameColIndex()+col, asc t.refresh() diff --git a/internal/views/ns.go b/internal/views/ns.go index fd4afbf1..489181e3 100644 --- a/internal/views/ns.go +++ b/internal/views/ns.go @@ -27,7 +27,7 @@ func newNamespaceView(t string, app *appView, list resource.List) resourceViewer v.selectedFn = v.getSelectedItem v.decorateFn = v.decorate v.enterFn = v.switchNs - v.getTV().cleanseFn = v.cleanser + v.masterPage().cleanseFn = v.cleanser return &v } @@ -50,11 +50,11 @@ func (v *namespaceView) useNsCmd(evt *tcell.EventKey) *tcell.EventKey { return nil } -func (v *namespaceView) useNamespace(name string) { - if err := v.app.config.SetActiveNamespace(name); err != nil { +func (v *namespaceView) useNamespace(ns string) { + if err := v.app.config.SetActiveNamespace(ns); err != nil { v.app.flash().err(err) } else { - v.app.flash().infof("Namespace %s is now active!", name) + v.app.flash().infof("Namespace %s is now active!", ns) } v.app.config.Save() } @@ -70,7 +70,7 @@ func (*namespaceView) cleanser(s string) string { func (v *namespaceView) decorate(data resource.TableData) resource.TableData { if _, ok := data.Rows[resource.AllNamespaces]; !ok { - if acc, err := v.app.conn().CanIAccess("", "namespaces", "namespace.v1", []string{"list"}); acc && err == nil { + if err := v.app.conn().CheckNSAccess(""); err == nil { data.Rows[resource.AllNamespace] = &resource.RowEvent{ Action: resource.Unchanged, Fields: resource.Row{resource.AllNamespace, "Active", "0"}, diff --git a/internal/views/pod.go b/internal/views/pod.go index 6d8ac977..d0ef6f3b 100644 --- a/internal/views/pod.go +++ b/internal/views/pod.go @@ -72,7 +72,6 @@ func (v *podView) extraActions(aa keyActions) { func (v *podView) listContainers(app *appView, _, res, sel string) { po, err := v.app.informer.Get(watch.PodIndex, sel, metav1.GetOptions{}) if err != nil { - log.Error().Err(err).Msgf("Unable to retrieve pod %s", sel) app.flash().errf("Unable to retrieve pods %s", err) return } @@ -100,7 +99,7 @@ func (v *podView) exitFn() { v.childCancelFn() } v.RemovePage("containers") - v.switchPage("po") + v.switchPage("master") v.restartUpdates() } @@ -157,7 +156,7 @@ func (v *podView) viewLogs(prev bool) bool { if v.list.AllNamespaces() { col = 3 } - status := strings.TrimSpace(v.getTV().GetCell(r, col).Text) + status := strings.TrimSpace(v.masterPage().GetCell(r, col).Text) if status == "Running" || status == "Completed" { v.showLogs(v.selectedItem, "", v.list.GetName(), v, prev) return true @@ -181,7 +180,6 @@ func (v *podView) shellCmd(evt *tcell.EventKey) *tcell.EventKey { cc, err := fetchContainers(v.list, v.selectedItem, false) if err != nil { v.app.flash().errf("Unable to retrieve containers %s", err) - log.Error().Msgf("Error fetching containers %v", err) return evt } if len(cc) == 1 { @@ -206,7 +204,7 @@ func (v *podView) shellIn(path, co string) { func (v *podView) sortColCmd(col int, asc bool) func(evt *tcell.EventKey) *tcell.EventKey { return func(evt *tcell.EventKey) *tcell.EventKey { - t := v.getTV() + t := v.masterPage() t.sortCol.index, t.sortCol.asc = t.nameColIndex()+col, asc t.refresh() diff --git a/internal/views/policy.go b/internal/views/policy.go index 9550396d..bb3f9343 100644 --- a/internal/views/policy.go +++ b/internal/views/policy.go @@ -49,7 +49,6 @@ func (v *policyView) init(c context.Context, ns string) { for { select { case <-ctx.Done(): - log.Debug().Msgf("Policy %s:%s Watch bailing out!", v.subjectKind, v.subjectName) return case <-time.After(time.Duration(v.app.config.K9s.RefreshRate) * time.Second): v.refresh() @@ -118,8 +117,6 @@ func (v *policyView) hints() hints { func (v *policyView) reconcile() (resource.TableData, error) { var table resource.TableData - log.Debug().Msgf(">>> Policy %s-%s", v.subjectKind, v.subjectName) - evts, errs := v.clusterPolicies() if len(errs) > 0 { for _, err := range errs { @@ -172,7 +169,6 @@ func (v *policyView) clusterPolicies() (resource.RowEvents, []error) { } } } - log.Debug().Msgf("Matching clusterroles: %#v", rr) for _, r := range rr { role, err := v.app.conn().DialOrDie().Rbac().ClusterRoles().Get(r, metav1.GetOptions{}) @@ -208,7 +204,6 @@ func (v *policyView) namespacePolicies() (resource.RowEvents, []error) { } } } - log.Debug().Msgf("Matching roles: %#v", rr) for _, r := range rr { cr, err := v.app.conn().DialOrDie().Rbac().Roles(r.ns).Get(r.role, metav1.GetOptions{}) diff --git a/internal/views/rbac.go b/internal/views/rbac.go index 400c0cd4..77513496 100644 --- a/internal/views/rbac.go +++ b/internal/views/rbac.go @@ -22,21 +22,6 @@ const ( rbacTitleFmt = " [fg:bg:b]%s([hilite:bg:b]%s[fg:bg:-])" ) -type ( - roleKind = int8 - - rbacView struct { - *tableView - - app *appView - current igniter - cancel context.CancelFunc - roleType roleKind - roleName string - cache resource.RowEvents - } -) - var ( rbacHeaderVerbs = resource.Row{ "GET ", @@ -78,16 +63,29 @@ var ( } ) +type ( + roleKind = int8 + + rbacView struct { + *tableView + + app *appView + current igniter + cancel context.CancelFunc + roleType roleKind + roleName string + cache resource.RowEvents + } +) + func newRBACView(app *appView, ns, name string, kind roleKind) *rbacView { v := rbacView{app: app} - { - v.roleName, v.roleType = name, kind - v.tableView = newTableView(app, v.getTitle()) - v.currentNS = ns - v.colorerFn = rbacColorer - v.current = app.content.GetPrimitive("main").(igniter) - v.bindKeys() - } + v.roleName, v.roleType = name, kind + v.tableView = newTableView(app, v.getTitle()) + v.currentNS = ns + v.colorerFn = rbacColorer + v.current = app.content.GetPrimitive("main").(igniter) + v.bindKeys() return &v } @@ -102,7 +100,6 @@ func (v *rbacView) init(c context.Context, ns string) { for { select { case <-ctx.Done(): - log.Debug().Msg("RBAC Watch bailing out!") return case <-time.After(time.Duration(v.app.config.K9s.RefreshRate) * time.Second): v.app.QueueUpdateDraw(func() { @@ -113,6 +110,7 @@ func (v *rbacView) init(c context.Context, ns string) { }(ctx) v.refresh() + v.app.setHints(v.hints()) v.app.SetFocus(v) } @@ -122,7 +120,6 @@ func (v *rbacView) bindKeys() { v.actions[tcell.KeyEscape] = newKeyAction("Reset", v.resetCmd, false) v.actions[KeySlash] = newKeyAction("Filter", v.activateCmd, false) v.actions[KeyP] = newKeyAction("Previous", v.app.prevCmd, false) - v.actions[KeyShiftO] = newKeyAction("Sort APIGroup", v.sortColCmd(1), true) } @@ -135,7 +132,6 @@ func (v *rbacView) hints() hints { } func (v *rbacView) refresh() { - log.Debug().Msg("RBAC Watching...") data, err := v.reconcile(v.currentNS, v.roleName, v.roleType) if err != nil { log.Error().Err(err).Msgf("Unable to reconcile for %s:%d", v.roleName, v.roleType) diff --git a/internal/views/resource.go b/internal/views/resource.go index f606a27a..cdc70bcc 100644 --- a/internal/views/resource.go +++ b/internal/views/resource.go @@ -3,21 +3,15 @@ package views import ( "context" "fmt" - "path" "strconv" - "strings" "time" "github.com/derailed/k9s/internal/config" - "github.com/derailed/k9s/internal/k8s" "github.com/derailed/k9s/internal/resource" - "github.com/derailed/tview" "github.com/gdamore/tcell" "github.com/rs/zerolog/log" ) -const noSelection = "" - type ( updatable interface { restartUpdates() @@ -25,93 +19,43 @@ type ( update(context.Context) } - masterDetail struct { - *tview.Pages - - app *appView - actions keyActions - title string - selectedItem string - selectedRow int - selectedNS string - path *string - } - resourceView struct { *masterDetail - namespaces map[int]string - list resource.List - enterFn enterFn - extraActionsFn func(keyActions) - selectedFn func() string - decorateFn decorateFn - colorerFn colorerFn - nsListAccess bool - cancelFn context.CancelFunc - parentCtx context.Context + namespaces map[int]string + list resource.List + cancelFn context.CancelFunc + parentCtx context.Context + path *string } ) func newResourceView(title string, app *appView, list resource.List) resourceViewer { v := resourceView{ - masterDetail: &masterDetail{ - Pages: tview.NewPages(), - app: app, - title: title, - actions: make(keyActions), - selectedNS: list.GetNamespace(), - }, - list: list, + masterDetail: newMasterDetail(title, app, list.GetNamespace()), + list: list, } - - tv := newTableView(app, v.title) - tv.SetSelectionChangedFunc(v.selChanged) - tv.filterChanged(v.filterResource) - v.AddPage(v.list.GetName(), tv, true, true) - - details := newDetailsView(app, v.backCmd) - v.AddPage("details", details, true, false) + v.masterPage().filterChanged(v.filterResource) return &v } // Init watches all running pods in given namespace func (v *resourceView) init(ctx context.Context, ns string) { + v.masterDetail.init(ns, v.backCmd) + v.parentCtx = ctx var vctx context.Context vctx, v.cancelFn = context.WithCancel(ctx) - v.selectedItem, v.selectedNS = noSelection, ns - - colorer := defaultColorer - if v.colorerFn != nil { - colorer = v.colorerFn - } - v.getTV().setColorer(colorer) - - v.nsListAccess, _ = v.app.conn().CanIAccess("", "namespaces", "namespace.v1", []string{"list"}) - if v.nsListAccess { - nn, err := k8s.NewNamespace(v.app.conn()).List(resource.AllNamespaces) - if err != nil { - log.Warn().Err(err).Msg("List namespaces") - v.app.flash().errf("Unable to list namespaces %s", err) - } - - if v.list.Namespaced() && !v.list.AllNamespaces() { - if !config.InNSList(nn, v.list.GetNamespace()) { - v.list.SetNamespace(resource.DefaultNamespace) - } - } - } v.update(vctx) v.app.clusterInfoRefresh() v.refresh() - if tv, ok := v.CurrentPage().Item.(*tableView); ok { - r, _ := tv.GetSelection() - if r == 0 && tv.GetRowCount() > 0 { - tv.Select(1, 0) - } + + tv := v.masterPage() + r, _ := tv.GetSelection() + if r == 0 && tv.GetRowCount() > 0 { + tv.Select(1, 0) } } @@ -152,56 +96,17 @@ func (v *resourceView) update(ctx context.Context) { }(ctx) } -func (v *resourceView) setExtraActionsFn(f actionsFn) { - f(v.actions) -} - -func (v *resourceView) getTitle() string { - return v.title -} - -func (v *resourceView) selChanged(r, c int) { - v.selectedRow = r - v.selectItem(r, c) -} - -func (v *resourceView) getSelectedItem() string { - if v.selectedFn != nil { - return v.selectedFn() - } - return v.selectedItem -} - -// Protocol... - -// Hints fetch menu hints -func (v *resourceView) hints() hints { - return v.CurrentPage().Item.(hinter).hints() -} - -func (v *resourceView) setColorerFn(f colorerFn) { - v.colorerFn = f - v.getTV().setColorer(f) -} - -func (v *resourceView) setEnterFn(f enterFn) { - v.enterFn = f -} - -func (v *resourceView) setDecorateFn(f decorateFn) { - v.decorateFn = f -} - // ---------------------------------------------------------------------------- // Actions... +func (v *resourceView) backCmd(*tcell.EventKey) *tcell.EventKey { + v.switchPage("master") + return nil +} + func (v *resourceView) enterCmd(evt *tcell.EventKey) *tcell.EventKey { // If in command mode run filter otherwise enter function. - if v.getTV().filterCmd(evt) == nil { - return nil - } - - if v.selectedItem == "" { + if v.masterPage().filterCmd(evt) == nil || !v.rowSelected() { return nil } @@ -220,84 +125,41 @@ func (v *resourceView) refreshCmd(*tcell.EventKey) *tcell.EventKey { return nil } -func (v *resourceView) backCmd(*tcell.EventKey) *tcell.EventKey { - v.switchPage(v.list.GetName()) - return nil -} - func (v *resourceView) deleteCmd(evt *tcell.EventKey) *tcell.EventKey { if !v.rowSelected() { return evt } sel := v.getSelectedItem() - v.showDelete(fmt.Sprintf("Delete %s %s?", v.list.GetName(), sel), func(cascade, force bool) { - v.getTV().setDeleted() + msg := fmt.Sprintf("Delete %s %s?", v.list.GetName(), sel) + showDeleteDialog(v.Pages, msg, func(cascade, force bool) { + v.masterPage().setDeleted() v.app.flash().infof("Deleting %s %s", v.list.GetName(), sel) if err := v.list.Resource().Delete(sel, cascade, force); err != nil { v.app.flash().errf("Delete failed with %s", err) } else { v.refresh() } - v.dismissModal() + }, func() { + v.switchPage("master") }) - return nil } -func (v *resourceView) showDelete(msg string, done func(bool, bool)) { - cascade, force := true, false - f := tview.NewForm() - f.SetItemPadding(0) - f.SetButtonsAlign(tview.AlignCenter). - SetButtonBackgroundColor(tview.Styles.PrimitiveBackgroundColor). - SetButtonTextColor(tview.Styles.PrimaryTextColor). - SetLabelColor(tcell.ColorAqua). - SetFieldTextColor(tcell.ColorOrange) - f.AddCheckbox("Cascade:", cascade, func(checked bool) { - cascade = checked - }) - f.AddCheckbox("Force:", force, func(checked bool) { - force = checked - }) - f.AddButton("Cancel", func() { - v.dismissModal() - }) - f.AddButton("OK", func() { - done(cascade, force) - v.dismissModal() - }) - - confirm := tview.NewModalForm("", f) - confirm.SetText(msg) - confirm.SetDoneFunc(func(int, string) { - v.dismissModal() - }) - v.AddPage("confirm", confirm, false, false) - v.ShowPage("confirm") -} - -func (v *resourceView) dismissModal() { - v.RemovePage("confirm") - v.switchPage(v.list.GetName()) -} - func (v *resourceView) defaultEnter(ns, resource, selection string) { - yaml, err := v.list.Resource().Describe(v.title, selection) + yaml, err := v.list.Resource().Describe(v.masterPage().baseTitle, selection) if err != nil { v.app.flash().errf("Describe command failed %s", err) - log.Warn().Msgf("Describe %v", err.Error()) return } - details := v.GetPrimitive("details").(*detailsView) - { - details.setCategory("Describe") - details.setTitle(selection) - details.SetTextColor(tcell.ColorAqua) - details.SetText(colorizeYAML(v.app.styles.Style, yaml)) - details.ScrollToBeginning() - } + details := v.detailsPage() + details.setCategory("Describe") + details.setTitle(selection) + details.SetTextColor(v.app.styles.FgColor()) + details.SetText(colorizeYAML(v.app.styles.Style, yaml)) + details.ScrollToBeginning() + v.switchPage("details") } @@ -319,17 +181,14 @@ func (v *resourceView) viewCmd(evt *tcell.EventKey) *tcell.EventKey { raw, err := v.list.Resource().Marshal(sel) if err != nil { v.app.flash().errf("Unable to marshal resource %s", err) - log.Error().Err(err) return evt } - details := v.GetPrimitive("details").(*detailsView) - { - details.setCategory("YAML") - details.setTitle(sel) - details.SetTextColor(tcell.ColorMediumAquamarine) - details.SetText(colorizeYAML(v.app.styles.Style, raw)) - details.ScrollToBeginning() - } + details := v.detailsPage() + details.setCategory("YAML") + details.setTitle(sel) + details.SetTextColor(v.app.styles.FgColor()) + details.SetText(colorizeYAML(v.app.styles.Style, raw)) + details.ScrollToBeginning() v.switchPage("details") return nil @@ -359,29 +218,34 @@ func (v *resourceView) editCmd(evt *tcell.EventKey) *tcell.EventKey { return evt } +func (v *resourceView) setNamespace(ns string) { + if v.list.Namespaced() { + v.currentNS = ns + v.list.SetNamespace(ns) + } +} + func (v *resourceView) switchNamespaceCmd(evt *tcell.EventKey) *tcell.EventKey { i, _ := strconv.Atoi(string(evt.Rune())) ns := v.namespaces[i] - v.doSwitchNamespace(ns) - - return nil -} - -func (v *resourceView) doSwitchNamespace(ns string) { if ns == "" { ns = resource.AllNamespace } - v.selectedNS = ns - v.app.flash().infof("Viewing `%s namespace...", ns) - v.list.SetNamespace(v.selectedNS) + if v.currentNS == ns { + return nil + } + v.setNamespace(ns) + v.app.flash().infof("Viewing `%s namespace...", ns) v.refresh() - v.getTV().resetTitle() - v.getTV().Select(1, 0) + v.masterPage().resetTitle() + v.masterPage().Select(1, 0) v.selectItem(1, 0) v.app.cmdBuff.reset() - v.app.config.SetActiveNamespace(v.selectedNS) + v.app.config.SetActiveNamespace(v.currentNS) v.app.config.Save() + + return nil } func (v *resourceView) refresh() { @@ -390,57 +254,28 @@ func (v *resourceView) refresh() { } v.refreshActions() - if v.list.Namespaced() { - v.list.SetNamespace(v.selectedNS) + v.list.SetNamespace(v.currentNS) } if err := v.list.Reconcile(v.app.informer, v.path); err != nil { - log.Error().Err(err).Msgf("Reconciliation for %s failed", v.title) - v.app.flash().errf("Reconciliation for %s failed - %s", v.title, err) + v.app.flash().errf("Reconciliation for %s failed - %s", v.list.GetName(), err) } data := v.list.Data() if v.decorateFn != nil { data = v.decorateFn(data) } - v.getTV().update(data) + v.masterPage().update(data) v.selectItem(v.selectedRow, 0) } -func (v *resourceView) getTV() *tableView { - if tv, ok := v.GetPrimitive(v.list.GetName()).(*tableView); ok { - return tv - } - return nil -} - -func (v *resourceView) selectItem(r, c int) { - t := v.getTV() - if r == 0 || t.GetCell(r, 0) == nil { - v.selectedItem = noSelection - return - } - - col0 := strings.TrimSpace(t.GetCell(r, 0).Text) - switch v.list.GetNamespace() { - case resource.NotNamespaced: - v.selectedItem = col0 - case resource.AllNamespaces: - v.selectedItem = path.Join(col0, strings.TrimSpace(t.GetCell(r, 1).Text)) - default: - v.selectedItem = path.Join(v.selectedNS, col0) - } -} - func (v *resourceView) switchPage(p string) { log.Debug().Msgf("Switching page to %s", p) if _, ok := v.CurrentPage().Item.(*tableView); ok { v.stopUpdates() - } else { - log.Debug().Msgf("Not a table %T", v.CurrentPage().Item) } v.SwitchToPage(p) - v.selectedNS = v.list.GetNamespace() + v.currentNS = v.list.GetNamespace() if vu, ok := v.GetPrimitive(p).(hinter); ok { v.app.setHints(vu.hints()) } @@ -450,30 +285,33 @@ func (v *resourceView) switchPage(p string) { } } -func (v *resourceView) rowSelected() bool { - return v.selectedItem != noSelection +func (v *resourceView) namespaceActions() { + if !v.list.Access(resource.NamespaceAccess) { + return + } + v.namespaces = make(map[int]string, config.MaxFavoritesNS) + // User can't list namespace. Don't offer a choice. + if v.app.conn().CheckListNSAccess() != nil { + return + } + v.actions[tcell.Key(numKeys[0])] = newKeyAction(resource.AllNamespace, v.switchNamespaceCmd, true) + v.namespaces[0] = resource.AllNamespace + index := 1 + for _, n := range v.app.config.FavNamespaces() { + if n == resource.AllNamespace { + continue + } + v.actions[tcell.Key(numKeys[index])] = newKeyAction(n, v.switchNamespaceCmd, true) + v.namespaces[index] = n + index++ + } } func (v *resourceView) refreshActions() { - if v.list.Access(resource.NamespaceAccess) { - v.namespaces = make(map[int]string, config.MaxFavoritesNS) - v.actions[tcell.Key(numKeys[0])] = newKeyAction(resource.AllNamespace, v.switchNamespaceCmd, true) - v.namespaces[0] = resource.AllNamespace - index := 1 - for _, n := range v.app.config.FavNamespaces() { - if n == resource.AllNamespace { - continue - } - v.actions[tcell.Key(numKeys[index])] = newKeyAction(n, v.switchNamespaceCmd, true) - v.namespaces[index] = n - index++ - } - } - + v.namespaceActions() + v.defaultActions() v.actions[tcell.KeyEnter] = newKeyAction("Enter", v.enterCmd, false) v.actions[tcell.KeyCtrlR] = newKeyAction("Refresh", v.refreshCmd, false) - v.actions[KeyHelp] = newKeyAction("Help", v.app.noopCmd, false) - v.actions[KeyP] = newKeyAction("Previous", v.app.prevCmd, false) if v.list.Access(resource.EditAccess) { v.actions[KeyE] = newKeyAction("Edit", v.editCmd, true) @@ -488,10 +326,7 @@ func (v *resourceView) refreshActions() { v.actions[KeyD] = newKeyAction("Describe", v.describeCmd, true) } - if v.extraActionsFn != nil { - v.extraActionsFn(v.actions) - } - t := v.getTV() + t := v.masterPage() t.setActions(v.actions) v.app.setHints(t.hints()) } diff --git a/internal/views/resource_test.go b/internal/views/resource_test.go deleted file mode 100644 index 93acdf8a..00000000 --- a/internal/views/resource_test.go +++ /dev/null @@ -1,23 +0,0 @@ -package views - -// import ( -// "context" -// "testing" - -// "github.com/derailed/k9s/internal/config" -// "github.com/derailed/k9s/internal/resource" -// ) - -// func TestNewResource(t *testing.T) { -// mc := NewMockConnection() -// mk := NewMockKubeSettings() - -// c := config.NewConfig(mk) -// c.SetConnection(mc) -// a := NewApp(c) -// l := resource.NewPodList(nil, "") -// v := newResourceView("fred", a, l) - -// ctx, _ := context.WithCancel(context.Background()) -// v.init(ctx, "") -// } diff --git a/internal/views/rs.go b/internal/views/rs.go index b2f9c824..b6e02cb3 100644 --- a/internal/views/rs.go +++ b/internal/views/rs.go @@ -37,7 +37,7 @@ func (v *replicaSetView) extraActions(aa keyActions) { func (v *replicaSetView) sortColCmd(col int, asc bool) func(evt *tcell.EventKey) *tcell.EventKey { return func(evt *tcell.EventKey) *tcell.EventKey { - t := v.getTV() + t := v.masterPage() t.sortCol.index, t.sortCol.asc = t.nameColIndex()+col, asc t.refresh() @@ -50,14 +50,12 @@ func (v *replicaSetView) showPods(app *appView, ns, res, sel string) { rset := k8s.NewReplicaSet(app.conn()) r, err := rset.Get(ns, n) if err != nil { - log.Error().Err(err).Msgf("Fetching ReplicaSet %s", sel) app.flash().errf("Replicaset failed %s", err) } rs := r.(*v1.ReplicaSet) l, err := metav1.LabelSelectorAsSelector(rs.Spec.Selector) if err != nil { - log.Error().Err(err).Msgf("Converting selector for ReplicaSet %s", sel) app.flash().errf("Selector failed %s", err) return } @@ -88,6 +86,11 @@ func (v *replicaSetView) rollbackCmd(evt *tcell.EventKey) *tcell.EventKey { return nil } +func (v *replicaSetView) dismissModal() { + v.RemovePage("confirm") + v.switchPage("master") +} + func (v *replicaSetView) showModal(msg string, done func(int, string)) { confirm := tview.NewModal(). AddButtons([]string{"Cancel", "OK"}). @@ -106,7 +109,6 @@ func rollback(app *appView, selectedItem string) bool { rset := k8s.NewReplicaSet(app.conn()) r, err := rset.Get(ns, n) if err != nil { - log.Error().Err(err).Msgf("Fetching ReplicaSet %s", selectedItem) app.flash().errf("Failed retrieving replicaset %s", err) return false } @@ -133,7 +135,6 @@ func rollback(app *appView, selectedItem string) bool { dpr := k8s.NewDeployment(app.conn()) dep, err := dpr.Get(ns, ctrlName) if err != nil { - log.Error().Err(err).Msgf("Fetching Deployment %s", selectedItem) app.flash().errf("Unable to retrieve deployments %s", err) return false } diff --git a/internal/views/secret.go b/internal/views/secret.go index b9917418..0058cd81 100644 --- a/internal/views/secret.go +++ b/internal/views/secret.go @@ -5,7 +5,6 @@ import ( "github.com/derailed/k9s/internal/resource" "github.com/gdamore/tcell" - "github.com/rs/zerolog/log" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) @@ -44,18 +43,15 @@ func (v *secretView) decodeCmd(evt *tcell.EventKey) *tcell.EventKey { raw, err := yaml.Marshal(d) if err != nil { v.app.flash().errf("Error decoding secret %s", err) - log.Error().Err(err).Msgf("Marshal error getting secret %s", sel) return nil } - details := v.GetPrimitive("details").(*detailsView) - { - details.setCategory("Decoder") - details.setTitle(sel) - details.SetTextColor(tcell.ColorMediumAquamarine) - details.SetText(colorizeYAML(v.app.styles.Style, string(raw))) - details.ScrollToBeginning() - } + details := v.detailsPage() + details.setCategory("Decoder") + details.setTitle(sel) + details.SetTextColor(v.app.styles.FgColor()) + details.SetText(colorizeYAML(v.app.styles.Style, string(raw))) + details.ScrollToBeginning() v.switchPage("details") return nil diff --git a/internal/views/select_list.go b/internal/views/select_list.go index 1db43424..b0fcd432 100644 --- a/internal/views/select_list.go +++ b/internal/views/select_list.go @@ -36,7 +36,7 @@ func newSelectList(parent loggable) *selectList { } func (v *selectList) back(evt *tcell.EventKey) *tcell.EventKey { - v.parent.switchPage(v.parent.getList().GetName()) + v.parent.switchPage("master") return nil } diff --git a/internal/views/svc.go b/internal/views/svc.go index 56b21f2d..fc5fbeb2 100644 --- a/internal/views/svc.go +++ b/internal/views/svc.go @@ -49,7 +49,7 @@ func (v *svcView) extraActions(aa keyActions) { func (v *svcView) sortColCmd(col int, asc bool) func(evt *tcell.EventKey) *tcell.EventKey { return func(evt *tcell.EventKey) *tcell.EventKey { - t := v.getTV() + t := v.masterPage() t.sortCol.index, t.sortCol.asc = t.nameColIndex()+col, asc t.refresh() @@ -62,7 +62,6 @@ func (v *svcView) showPods(app *appView, ns, res, sel string) { ns, n := namespaced(sel) svc, err := s.Get(ns, n) if err != nil { - log.Error().Err(err).Msgf("Fetch service %s", sel) app.flash().err(err) return } @@ -112,7 +111,7 @@ func trimCell(tv *tableView, row, col int) (string, error) { } func (v *svcView) checkSvc(row int) error { - svcType, err := trimCell(v.getTV(), row, 1) + svcType, err := trimCell(v.masterPage(), row, 1) if err != nil { return err } @@ -123,7 +122,7 @@ func (v *svcView) checkSvc(row int) error { } func (v *svcView) getExternalPort(row int) (string, error) { - ports, err := trimCell(v.getTV(), row, 5) + ports, err := trimCell(v.masterPage(), row, 5) if err != nil { return "", err } @@ -158,7 +157,6 @@ func (v *svcView) benchCmd(evt *tcell.EventKey) *tcell.EventKey { return nil } if err := v.reloadBenchCfg(); err != nil { - log.Error().Err(err).Msg("Bench config reload") v.app.flash().err(err) return nil } @@ -171,7 +169,7 @@ func (v *svcView) benchCmd(evt *tcell.EventKey) *tcell.EventKey { } cfg.Name = sel - row, _ := v.getTV().GetSelection() + row, _ := v.masterPage().GetSelection() if err := v.checkSvc(row); err != nil { v.app.flash().err(err) return nil @@ -182,7 +180,6 @@ func (v *svcView) benchCmd(evt *tcell.EventKey) *tcell.EventKey { return nil } if err := v.runBenchmark(port, cfg); err != nil { - log.Error().Err(err).Msg("Benchmark failed!") v.app.flash().errf("Benchmark failed %v", err) v.app.statusReset() v.bench = nil diff --git a/internal/views/table.go b/internal/views/table.go index 6f5f528f..14ea56ee 100644 --- a/internal/views/table.go +++ b/internal/views/table.go @@ -22,8 +22,6 @@ const ( titleFmt = "[fg:bg:b] %s[fg:bg:-][[count:bg:b]%d[fg:bg:-]] " searchFmt = "<[filter:bg:b]/%s[fg:bg:]> " nsTitleFmt = "[fg:bg:b] %s([hilite:bg:b]%s[fg:bg:-])[fg:bg:-][[count:bg:b]%d[fg:bg:-]][fg:bg:-] " - descIndicator = "↓" - ascIndicator = "↑" labelSelIndicator = "-l" ) diff --git a/internal/views/table_helper.go b/internal/views/table_helper.go index 3cd8baac..867e3b03 100644 --- a/internal/views/table_helper.go +++ b/internal/views/table_helper.go @@ -12,6 +12,11 @@ import ( var labelCmd = regexp.MustCompile(`\A\-l`) +const ( + descIndicator = "↓" + ascIndicator = "↑" +) + func isLabelSelector(s string) bool { if s == "" { return false diff --git a/internal/watch/informer.go b/internal/watch/informer.go index 90d5ff4b..5d708045 100644 --- a/internal/watch/informer.go +++ b/internal/watch/informer.go @@ -62,62 +62,37 @@ type Informer struct { } // NewInformer creates a new cluster resource informer -func NewInformer(client k8s.Connection, ns string) *Informer { - if ns == allNamespace { - ns = allNamespaces - } - log.Debug().Msgf(">> Starting Informer in namespace %q", ns) +func NewInformer(client k8s.Connection, ns string) (*Informer, error) { i := Informer{client: client, informers: map[string]StoreInformer{}} - - nsAccess, err := client.CanIAccess("", "", "namespaces", []string{"list", "watch"}) - if ns == allNamespaces && (err != nil || !nsAccess) { - user, _ := client.Config().CurrentUserName() - if err != nil { - log.Panic().Err(err).Msgf("Unauthorized: All namespaces. No access for user `%s", user) - } - log.Panic().Msgf("Unauthorized: All namespaces for user `%s. Missing verbs ['list', 'watch']. Please specify a namespace or correct RBAC", user) - } - - // Namespace is locked in. check if user has auth for this ns access. - if ns != allNamespaces { - acc, err := client.CanIAccess("", ns, "namespaces", []string{"get", "watch"}) - if err != nil { - log.Panic().Err(err).Msgf("Failed access %s", ns) - } - if !acc { - user, _ := client.Config().CurrentUserName() - log.Panic().Msgf("Unauthorized: %s access to namespace %q is missing verbs ['get', 'watch']", user, ns) - } - i.init(ns) - } else { + if client.CheckListNSAccess() == nil { i.init(allNamespaces) + return &i, nil } - return &i + if err := client.CheckNSAccess(ns); err != nil { + return nil, err + } + + i.init(ns) + return &i, nil } func (i *Informer) init(ns string) { + log.Debug().Msgf(">>>>> Starting Informer in namespace %q", ns) + i.initOnce.Do(func() { po := NewPod(i.client, ns) i.informers = map[string]StoreInformer{ PodIndex: po, ContainerIndex: NewContainer(po), } - - if acc, err := i.client.CanIAccess("", "", "nodes", []string{"list", "watch"}); acc && err == nil { - i.informers[NodeIndex] = NewNode(i.client) - } + i.informers[NodeIndex] = NewNode(i.client) if !i.client.HasMetrics() { return } - - if acc, err := i.client.CanIAccess(ns, "", "nodes.metrics.k8s.io", []string{"list", "watch"}); acc && err == nil { - i.informers[NodeMXIndex] = NewNodeMetrics(i.client) - } - if acc, err := i.client.CanIAccess(ns, "", "pods.metrics.k8s.io", []string{"list", "watch"}); acc && err == nil { - i.informers[PodMXIndex] = NewPodMetrics(i.client, ns) - } + i.informers[NodeMXIndex] = NewNodeMetrics(i.client) + i.informers[PodMXIndex] = NewPodMetrics(i.client, ns) }) } @@ -131,7 +106,7 @@ func (i *Informer) List(res, ns string, opts metav1.ListOptions) (k8s.Collection return i.List(ns, opts), nil } - return nil, fmt.Errorf("No informer found for resource %s:%q", res, ns) + return nil, fmt.Errorf("No informer found for resource %s in namespace %q", res, ns) } // Get a resource by name. @@ -140,7 +115,7 @@ func (i *Informer) Get(res, fqn string, opts metav1.GetOptions) (interface{}, er return informer.Get(fqn, opts) } - return nil, fmt.Errorf("No informer found for resource %s:%q", res, fqn) + return nil, fmt.Errorf("No informer found for resource %s in namespace %q", res, fqn) } // Run starts watching cluster resources. diff --git a/internal/watch/informer_test.go b/internal/watch/informer_test.go index 7740467e..b279297d 100644 --- a/internal/watch/informer_test.go +++ b/internal/watch/informer_test.go @@ -1,6 +1,7 @@ package watch import ( + "errors" "sync" "testing" @@ -11,18 +12,44 @@ import ( "k8s.io/cli-runtime/pkg/genericclioptions" ) -func TestInformerInitWithNS(t *testing.T) { - ns := "ns1" - +func TestInformerAllNSNoAccess(t *testing.T) { + ns := "" f := new(genericclioptions.ConfigFlags) f.Namespace = &ns cmo := NewMockConnection() m.When(cmo.Config()).ThenReturn(k8s.NewConfig(f)) m.When(cmo.HasMetrics()).ThenReturn(true) - m.When(cmo.CanIAccess("", "", "namespaces", []string{"list", "watch"})).ThenReturn(false, nil) - m.When(cmo.CanIAccess("", ns, "namespaces", []string{"get", "watch"})).ThenReturn(true, nil) - m.When(cmo.CanIAccess("", ns, "metrics.k8s.io", []string{"list", "watch"})).ThenReturn(true, nil) - i := NewInformer(cmo, ns) + m.When(cmo.CheckListNSAccess()).ThenReturn(errors.New("denied")) + m.When(cmo.CheckNSAccess(ns)).ThenReturn(errors.New("denied")) + + _, err := NewInformer(cmo, ns) + assert.Error(t, err, "denied") +} + +func TestInformerNSNoAccess(t *testing.T) { + ns := "ns1" + f := new(genericclioptions.ConfigFlags) + f.Namespace = &ns + cmo := NewMockConnection() + m.When(cmo.Config()).ThenReturn(k8s.NewConfig(f)) + m.When(cmo.HasMetrics()).ThenReturn(true) + m.When(cmo.CheckNSAccess(ns)).ThenReturn(errors.New("denied")) + m.When(cmo.CheckListNSAccess()).ThenReturn(errors.New("denied")) + + _, err := NewInformer(cmo, ns) + assert.Error(t, err, "denied") +} + +func TestInformerInitWithNS(t *testing.T) { + ns := "ns1" + f := new(genericclioptions.ConfigFlags) + f.Namespace = &ns + cmo := NewMockConnection() + m.When(cmo.Config()).ThenReturn(k8s.NewConfig(f)) + m.When(cmo.HasMetrics()).ThenReturn(true) + m.When(cmo.CheckNSAccess(ns)).ThenReturn(nil) + i, err := NewInformer(cmo, ns) + assert.NilError(t, err) o, err := i.List(PodIndex, "fred", metav1.ListOptions{}) assert.NilError(t, err) @@ -33,7 +60,8 @@ func TestInformerList(t *testing.T) { f := new(genericclioptions.ConfigFlags) cmo := NewMockConnection() m.When(cmo.Config()).ThenReturn(k8s.NewConfig(f)) - i := NewInformer(cmo, "") + i, err := NewInformer(cmo, "") + assert.NilError(t, err) o, err := i.List(PodIndex, "fred", metav1.ListOptions{}) assert.NilError(t, err) @@ -44,7 +72,8 @@ func TestInformerListNoRes(t *testing.T) { f := new(genericclioptions.ConfigFlags) cmo := NewMockConnection() m.When(cmo.Config()).ThenReturn(k8s.NewConfig(f)) - i := NewInformer(cmo, "") + i, err := NewInformer(cmo, "") + assert.NilError(t, err) o, err := i.List("dp", "fred", metav1.ListOptions{}) assert.ErrorContains(t, err, "No informer found") @@ -55,7 +84,8 @@ func TestInformerGet(t *testing.T) { f := new(genericclioptions.ConfigFlags) cmo := NewMockConnection() m.When(cmo.Config()).ThenReturn(k8s.NewConfig(f)) - i := NewInformer(cmo, "") + i, err := NewInformer(cmo, "") + assert.NilError(t, err) o, err := i.Get(PodIndex, "fred", metav1.GetOptions{}) assert.ErrorContains(t, err, "Pod fred not found") @@ -66,7 +96,8 @@ func TestInformerGetNoRes(t *testing.T) { f := new(genericclioptions.ConfigFlags) cmo := NewMockConnection() m.When(cmo.Config()).ThenReturn(k8s.NewConfig(f)) - i := NewInformer(cmo, "") + i, err := NewInformer(cmo, "") + assert.NilError(t, err) o, err := i.Get("rs", "fred", metav1.GetOptions{}) assert.ErrorContains(t, err, "No informer found") @@ -77,7 +108,8 @@ func TestInformerRun(t *testing.T) { f := new(genericclioptions.ConfigFlags) cmo := NewMockConnection() m.When(cmo.Config()).ThenReturn(k8s.NewConfig(f)) - i := NewInformer(cmo, "") + i, err := NewInformer(cmo, "") + assert.NilError(t, err) var wg sync.WaitGroup wg.Add(1) diff --git a/internal/watch/mock_connection_test.go b/internal/watch/mock_connection_test.go index cdce32ca..00012139 100644 --- a/internal/watch/mock_connection_test.go +++ b/internal/watch/mock_connection_test.go @@ -24,23 +24,34 @@ func NewMockConnection() *MockConnection { return &MockConnection{fail: pegomock.GlobalFailHandler} } -func (mock *MockConnection) CanIAccess(_param0 string, _param1 string, _param2 string, _param3 []string) (bool, error) { +func (mock *MockConnection) CheckListNSAccess() error { if mock == nil { panic("mock must not be nil. Use myMock := NewMockConnection().") } - params := []pegomock.Param{_param0, _param1, _param2, _param3} - result := pegomock.GetGenericMockFrom(mock).Invoke("CanIAccess", params, []reflect.Type{reflect.TypeOf((*bool)(nil)).Elem(), reflect.TypeOf((*error)(nil)).Elem()}) - var ret0 bool - var ret1 error + params := []pegomock.Param{} + result := pegomock.GetGenericMockFrom(mock).Invoke("CheckListNSAccess", params, []reflect.Type{reflect.TypeOf((*error)(nil)).Elem()}) + var ret0 error if len(result) != 0 { if result[0] != nil { - ret0 = result[0].(bool) - } - if result[1] != nil { - ret1 = result[1].(error) + ret0 = result[0].(error) } } - return ret0, ret1 + return ret0 +} + +func (mock *MockConnection) CheckNSAccess(_param0 string) error { + if mock == nil { + panic("mock must not be nil. Use myMock := NewMockConnection().") + } + params := []pegomock.Param{_param0} + result := pegomock.GetGenericMockFrom(mock).Invoke("CheckNSAccess", 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 *MockConnection) Config() *k8s.Config { @@ -345,41 +356,46 @@ type VerifierConnection struct { timeout time.Duration } -func (verifier *VerifierConnection) CanIAccess(_param0 string, _param1 string, _param2 string, _param3 []string) *Connection_CanIAccess_OngoingVerification { - params := []pegomock.Param{_param0, _param1, _param2, _param3} - methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "CanIAccess", params, verifier.timeout) - return &Connection_CanIAccess_OngoingVerification{mock: verifier.mock, methodInvocations: methodInvocations} +func (verifier *VerifierConnection) CheckListNSAccess() *Connection_CheckListNSAccess_OngoingVerification { + params := []pegomock.Param{} + methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "CheckListNSAccess", params, verifier.timeout) + return &Connection_CheckListNSAccess_OngoingVerification{mock: verifier.mock, methodInvocations: methodInvocations} } -type Connection_CanIAccess_OngoingVerification struct { +type Connection_CheckListNSAccess_OngoingVerification struct { mock *MockConnection methodInvocations []pegomock.MethodInvocation } -func (c *Connection_CanIAccess_OngoingVerification) GetCapturedArguments() (string, string, string, []string) { - _param0, _param1, _param2, _param3 := c.GetAllCapturedArguments() - return _param0[len(_param0)-1], _param1[len(_param1)-1], _param2[len(_param2)-1], _param3[len(_param3)-1] +func (c *Connection_CheckListNSAccess_OngoingVerification) GetCapturedArguments() { } -func (c *Connection_CanIAccess_OngoingVerification) GetAllCapturedArguments() (_param0 []string, _param1 []string, _param2 []string, _param3 [][]string) { +func (c *Connection_CheckListNSAccess_OngoingVerification) GetAllCapturedArguments() { +} + +func (verifier *VerifierConnection) CheckNSAccess(_param0 string) *Connection_CheckNSAccess_OngoingVerification { + params := []pegomock.Param{_param0} + methodInvocations := pegomock.GetGenericMockFrom(verifier.mock).Verify(verifier.inOrderContext, verifier.invocationCountMatcher, "CheckNSAccess", params, verifier.timeout) + return &Connection_CheckNSAccess_OngoingVerification{mock: verifier.mock, methodInvocations: methodInvocations} +} + +type Connection_CheckNSAccess_OngoingVerification struct { + mock *MockConnection + methodInvocations []pegomock.MethodInvocation +} + +func (c *Connection_CheckNSAccess_OngoingVerification) GetCapturedArguments() string { + _param0 := c.GetAllCapturedArguments() + return _param0[len(_param0)-1] +} + +func (c *Connection_CheckNSAccess_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) } - _param1 = make([]string, len(params[1])) - for u, param := range params[1] { - _param1[u] = param.(string) - } - _param2 = make([]string, len(params[2])) - for u, param := range params[2] { - _param2[u] = param.(string) - } - _param3 = make([][]string, len(params[3])) - for u, param := range params[3] { - _param3[u] = param.([]string) - } } return }