diff --git a/cmd/helm/helm.go b/cmd/helm/helm.go index 3e244e0cd..ad32659c1 100644 --- a/cmd/helm/helm.go +++ b/cmd/helm/helm.go @@ -47,6 +47,7 @@ var ( tlsEnable bool // enable TLS kubeContext string + kubeConfig string tillerTunnel *kube.Tunnel settings helm_env.EnvSettings ) @@ -95,6 +96,7 @@ func addRootFlags(cmd *cobra.Command) { pf.StringVar((*string)(&settings.Home), "home", helm_env.DefaultHelmHome, "location of your Helm config. Overrides $HELM_HOME") pf.StringVar(&settings.TillerHost, "host", "", "address of Tiller. Overrides $HELM_HOST") pf.StringVar(&kubeContext, "kube-context", "", "name of the kubeconfig context to use") + pf.StringVar(&kubeConfig, "kubeconfig", "", "path to kubeconfig file") pf.BoolVar(&settings.Debug, "debug", false, "enable verbose output") pf.StringVar(&settings.TillerNamespace, "tiller-namespace", tiller_env.DefaultTillerNamespace, "namespace of Tiller") } @@ -244,7 +246,7 @@ func prettyError(err error) error { // configForContext creates a Kubernetes REST client configuration for a given kubeconfig context. func configForContext(context string) (*rest.Config, error) { - config, err := kube.GetConfig(context).ClientConfig() + config, err := kube.GetConfig(context, kubeConfig).ClientConfig() if err != nil { return nil, fmt.Errorf("could not get Kubernetes config for context %q: %s", context, err) } diff --git a/cmd/helm/install.go b/cmd/helm/install.go index 988e7f0a1..43df4ef71 100644 --- a/cmd/helm/install.go +++ b/cmd/helm/install.go @@ -434,7 +434,7 @@ func generateName(nameTemplate string) (string, error) { } func defaultNamespace() string { - if ns, _, err := kube.GetConfig(kubeContext).Namespace(); err == nil { + if ns, _, err := kube.GetConfig(kubeContext, kubeConfig).Namespace(); err == nil { return ns } return "default" diff --git a/pkg/kube/config.go b/pkg/kube/config.go index b6560486e..841c95784 100644 --- a/pkg/kube/config.go +++ b/pkg/kube/config.go @@ -18,8 +18,8 @@ package kube // import "k8s.io/helm/pkg/kube" import "k8s.io/client-go/tools/clientcmd" -// GetConfig returns a Kubernetes client config for a given context. -func GetConfig(context string) clientcmd.ClientConfig { +// GetConfig returns a kubernetes client config for a given context. +func GetConfig(context string, kubeconfig string) clientcmd.ClientConfig { rules := clientcmd.NewDefaultClientConfigLoadingRules() rules.DefaultClientConfig = &clientcmd.DefaultClientConfig @@ -28,5 +28,10 @@ func GetConfig(context string) clientcmd.ClientConfig { if context != "" { overrides.CurrentContext = context } + + if kubeconfig != "" { + rules.ExplicitPath = kubeconfig + } + return clientcmd.NewNonInteractiveDeferredLoadingClientConfig(rules, overrides) }