feat(helm): adding kubeconfig flag

reviewable/pr2621/r1
gardlt 8 years ago
parent 56ed16aeca
commit 3fd4af9209

@ -95,6 +95,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(&settings.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")
}
@ -102,6 +103,7 @@ func addRootFlags(cmd *cobra.Command) {
func initRootFlags(cmd *cobra.Command) {
setFlagsFromEnv(map[string]string{
"debug": helm_env.DebugEnvVar,
"kubeconfig": helm_env.KubeconfigEnvVar,
"home": helm_env.HomeEnvVar,
"host": helm_env.HostEnvVar,
"tiller-namespace": tiller_env.TillerNamespaceEnvVar,
@ -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, settings.Kubeconfig).ClientConfig()
if err != nil {
return nil, fmt.Errorf("could not get Kubernetes config for context %q: %s", context, err)
}

@ -432,7 +432,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, settings.Kubeconfig).Namespace(); err == nil {
return ns
}
return "default"

@ -40,6 +40,8 @@ const (
HostEnvVar = "HELM_HOST"
// DebugEnvVar is the HELM_DEBUG environment variable key.
DebugEnvVar = "HELM_DEBUG"
// KubeconfigVar is the HELM_KUBECONFIG enviroment variable key.
KubeconfigEnvVar = "HELM_KUBECONFIG"
)
// DefaultHelmHome is the default HELM_HOME.
@ -55,6 +57,8 @@ type EnvSettings struct {
Home helmpath.Home
// Debug indicates whether or not Helm is running in Debug mode.
Debug bool
// Kubeconfig is the local paht to the kubernetes config directory
Kubeconfig string
}
// PluginDirs is the path to the plugin directories.

@ -19,7 +19,7 @@ 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 {
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)
}

Loading…
Cancel
Save