Skip to content

Commit

Permalink
fix: Use namespace specified by current config context (#1489)
Browse files Browse the repository at this point in the history
Use the namespace defined in the current context, if it's been set. Otherwise, default to 'default'.

Signed-off-by: Nick Jones <nick@dischord.org>
  • Loading branch information
yankcrime committed May 8, 2020
1 parent 58ef809 commit 8ae008e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
5 changes: 4 additions & 1 deletion pkg/kudoctl/env/environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/spf13/pflag"
"k8s.io/client-go/util/homedir"

"github.com/kudobuilder/kudo/pkg/kudoctl/kube"
"github.com/kudobuilder/kudo/pkg/kudoctl/kudohome"
"github.com/kudobuilder/kudo/pkg/kudoctl/util/kudo"
)
Expand Down Expand Up @@ -54,9 +55,11 @@ var DefaultSettings = &Settings{

// AddFlags binds flags to the given flagset.
func (s *Settings) AddFlags(fs *pflag.FlagSet) {
namespace, _, _ := kube.GetConfig(s.KubeConfig).Namespace()

fs.StringVar((*string)(&s.Home), "home", kudoHome(), "Location of your KUDO config.")
fs.StringVar(&s.KubeConfig, "kubeconfig", kubeConfigHome(), "Path to your Kubernetes configuration file.")
fs.StringVarP(&s.Namespace, "namespace", "n", "default", "Target namespace for the object.")
fs.StringVarP(&s.Namespace, "namespace", "n", namespace, "Target namespace for the object.")
fs.Int64Var(&s.RequestTimeout, "request-timeout", 0, "Request timeout value, in seconds. Defaults to 0 (unlimited)")
fs.BoolVar(&s.Validate, "validate-install", true, "Validate KUDO installation before running.")
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/kudoctl/kube/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ type Client struct {
DynamicClient dynamic.Interface
}

// getConfig returns a Kubernetes client config for a given kubeconfig.
func getConfig(kubeconfig string) clientcmd.ClientConfig {
// GetConfig returns a Kubernetes client config for a given kubeconfig.
func GetConfig(kubeconfig string) clientcmd.ClientConfig {
rules := clientcmd.NewDefaultClientConfigLoadingRules()
rules.DefaultClientConfig = &clientcmd.DefaultClientConfig

Expand All @@ -34,7 +34,7 @@ func getConfig(kubeconfig string) clientcmd.ClientConfig {
}

func getRestConfig(kubeconfig string) (*rest.Config, error) {
config, err := getConfig(kubeconfig).ClientConfig()
config, err := GetConfig(kubeconfig).ClientConfig()
if err != nil {
return nil, fmt.Errorf("could not get Kubernetes config using configuration %q: %s", kubeconfig, err)
}
Expand Down

0 comments on commit 8ae008e

Please sign in to comment.