From 921a39f89755b25dd90e6536a255019d1c2b9ccf Mon Sep 17 00:00:00 2001 From: derailed Date: Tue, 18 Jun 2019 14:11:53 -0600 Subject: [PATCH] test pass --- README.md | 5 +++-- cmd/root.go | 26 +++++++++++++++++--------- internal/config/style.go | 6 +++--- internal/resource/base.go | 5 ++--- internal/resource/list.go | 5 ++--- internal/watch/informer.go | 19 +++++++++++++------ 6 files changed, 40 insertions(+), 26 deletions(-) diff --git a/README.md b/README.md index d75fcd28..969fe707 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ K9s provides a curses based terminal UI to interact with your Kubernetes clusters. The aim of this project is to make it easier to navigate, observe and manage your applications in the wild. K9s continually watches Kubernetes -for changes and offers subsequent commands to interact with observed resources. +for changes and offers subsequent commands to interact with observed Kubernetes resources. --- @@ -14,6 +14,7 @@ for changes and offers subsequent commands to interact with observed resources. [![release](https://img.shields.io/github/release-pre/derailed/k9s.svg)](https://github.com/derailed/k9s/releases) [![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://github.com/mum4k/termdash/blob/master/LICENSE) [![k9s](https://snapcraft.io/k9s/badge.svg)](https://snapcraft.io/k9s) +[![Releases](https://img.shields.io/github/downloads/derailed/k9s/total.svg)]() --- @@ -418,7 +419,7 @@ Available color names are defined below: This initial drop is brittle. K9s will most likely blow up... 1. You're running older versions of Kubernetes. K9s works best Kubernetes 1.12+. -1. You don't have enough RBAC fu to manage your cluster (see RBAC section below). +2. You don't have enough RBAC fu to manage your cluster. --- diff --git a/cmd/root.go b/cmd/root.go index 3fb8ae14..33a45dda 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -76,7 +76,7 @@ func run(cmd *cobra.Command, args []string) { app := views.NewApp(cfg) { defer app.BailOut() - app.Init(version, refreshRate, k8sFlags) + app.Init(version, refreshRate) app.Run() } } @@ -138,6 +138,7 @@ func initK9sFlags() { func initK8sFlags() { k8sFlags = genericclioptions.NewConfigFlags() + rootCmd.Flags().StringVar( k8sFlags.KubeConfig, "kubeconfig", @@ -173,6 +174,19 @@ func initK8sFlags() { "The name of the kubeconfig user to use", ) + rootCmd.Flags().StringVarP( + k8sFlags.Namespace, + "namespace", + "n", + "", + "If present, the namespace scope for this CLI request", + ) + + initAsFlags() + initCertFlags() +} + +func initAsFlags() { rootCmd.Flags().StringVar( k8sFlags.Impersonate, "as", @@ -186,7 +200,9 @@ func initK8sFlags() { []string{}, "Group to impersonate for the operation", ) +} +func initCertFlags() { rootCmd.Flags().BoolVar( k8sFlags.Insecure, "insecure-skip-tls-verify", @@ -221,14 +237,6 @@ func initK8sFlags() { "", "Bearer token for authentication to the API server", ) - - rootCmd.Flags().StringVarP( - k8sFlags.Namespace, - "namespace", - "n", - "", - "If present, the namespace scope for this CLI request", - ) } // ---------------------------------------------------------------------------- diff --git a/internal/config/style.go b/internal/config/style.go index e1cebe8c..d1090e89 100644 --- a/internal/config/style.go +++ b/internal/config/style.go @@ -191,7 +191,7 @@ func newTable() *Table { func newTableHeader() *TableHeader { return &TableHeader{ FgColor: "white", - BgColor: "red", + BgColor: "black", SorterColor: "aqua", } } @@ -223,9 +223,9 @@ func newMenu() *Menu { } // NewStyles creates a new default config. -func NewStyles(p string) (*Styles, error) { +func NewStyles(path string) (*Styles, error) { s := &Styles{Style: newStyle()} - return s, s.load(p) + return s, s.load(path) } // FgColor returns the foreground color. diff --git a/internal/resource/base.go b/internal/resource/base.go index c4fd01a5..977af6d9 100644 --- a/internal/resource/base.go +++ b/internal/resource/base.go @@ -11,7 +11,6 @@ import ( v1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" - "k8s.io/cli-runtime/pkg/genericclioptions" "k8s.io/cli-runtime/pkg/genericclioptions/printers" "k8s.io/kubernetes/pkg/kubectl/describe" versioned "k8s.io/kubernetes/pkg/kubectl/describe/versioned" @@ -127,7 +126,7 @@ func (b *Base) List(ns string) (Columnars, error) { } // Describe a given resource. -func (b *Base) Describe(kind, pa string, flags *genericclioptions.ConfigFlags) (string, error) { +func (b *Base) Describe(kind, pa string) (string, error) { ns, n := namespaced(pa) mapping, err := k8s.RestMapping.Find(kind) @@ -136,7 +135,7 @@ func (b *Base) Describe(kind, pa string, flags *genericclioptions.ConfigFlags) ( return "", err } - d, err := versioned.Describer(flags, mapping) + d, err := versioned.Describer(b.Connection.Config().Flags(), mapping) if err != nil { log.Error().Err(err).Msgf("Unable to find describer for %#v", mapping) return "", err diff --git a/internal/resource/list.go b/internal/resource/list.go index be6bbf20..adc46478 100644 --- a/internal/resource/list.go +++ b/internal/resource/list.go @@ -9,7 +9,6 @@ import ( v1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/watch" - "k8s.io/cli-runtime/pkg/genericclioptions" mv1beta1 "k8s.io/metrics/pkg/apis/metrics/v1beta1" ) @@ -104,7 +103,7 @@ type ( Get(path string) (Columnar, error) List(ns string) (Columnars, error) Delete(path string, cascade, force bool) error - Describe(kind, pa string, flags *genericclioptions.ConfigFlags) (string, error) + Describe(kind, pa string) (string, error) Marshal(pa string) (string, error) Header(ns string) Row NumCols(ns string) map[string]bool @@ -189,7 +188,7 @@ func (l *list) GetNamespace() string { // SetNamespace updates the namespace on the list. Default ns is "" for all // namespaces. func (l *list) SetNamespace(n string) { - if l.namespace == NotNamespaced { + if !l.Namespaced() { return } diff --git a/internal/watch/informer.go b/internal/watch/informer.go index fafe3702..90d5ff4b 100644 --- a/internal/watch/informer.go +++ b/internal/watch/informer.go @@ -12,8 +12,12 @@ import ( "k8s.io/client-go/tools/cache" ) -// AllNamespaces designates all namespaces. -const AllNamespaces = "" +const ( + // AllNamespaces designates all namespaces. + allNamespaces = "" + // AllNamespaces designate the special `all` namespace. + allNamespace = "all" +) type ( // Row represents a collection of string fields. @@ -59,11 +63,14 @@ type Informer struct { // NewInformer creates a new cluster resource informer func NewInformer(client k8s.Connection, ns string) *Informer { - log.Debug().Msgf(">> Starting Informer") + if ns == allNamespace { + ns = allNamespaces + } + log.Debug().Msgf(">> Starting Informer in namespace %q", ns) i := Informer{client: client, informers: map[string]StoreInformer{}} nsAccess, err := client.CanIAccess("", "", "namespaces", []string{"list", "watch"}) - if ns == AllNamespaces && (err != nil || !nsAccess) { + 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) @@ -72,7 +79,7 @@ func NewInformer(client k8s.Connection, ns string) *Informer { } // Namespace is locked in. check if user has auth for this ns access. - if ns != AllNamespaces { + if ns != allNamespaces { acc, err := client.CanIAccess("", ns, "namespaces", []string{"get", "watch"}) if err != nil { log.Panic().Err(err).Msgf("Failed access %s", ns) @@ -83,7 +90,7 @@ func NewInformer(client k8s.Connection, ns string) *Informer { } i.init(ns) } else { - i.init(AllNamespaces) + i.init(allNamespaces) } return &i