Merge pull request #1337 from adamreese/feat/1127-kube-context

feat(helm): add kubeconfig context switching
pull/1359/head
Adam Reese 8 years ago committed by GitHub
commit 7374ca3f3b

@ -35,8 +35,9 @@ const (
) )
var ( var (
helmHome string helmHome string
tillerHost string tillerHost string
kubeContext string
) )
// flagDebug is a signal that the user wants additional output. // flagDebug is a signal that the user wants additional output.
@ -82,6 +83,7 @@ func newRootCmd(out io.Writer) *cobra.Command {
p := cmd.PersistentFlags() p := cmd.PersistentFlags()
p.StringVar(&helmHome, "home", home, "location of your Helm config. Overrides $HELM_HOME") p.StringVar(&helmHome, "home", home, "location of your Helm config. Overrides $HELM_HOME")
p.StringVar(&tillerHost, "host", thost, "address of tiller. Overrides $HELM_HOST") p.StringVar(&tillerHost, "host", thost, "address of tiller. Overrides $HELM_HOST")
p.StringVar(&kubeContext, "kube-context", "", "name of the kubeconfig context to use")
p.BoolVarP(&flagDebug, "debug", "", false, "enable verbose output") p.BoolVarP(&flagDebug, "debug", "", false, "enable verbose output")
rup := newRepoUpdateCmd(out) rup := newRepoUpdateCmd(out)
@ -124,7 +126,7 @@ func main() {
func setupConnection(c *cobra.Command, args []string) error { func setupConnection(c *cobra.Command, args []string) error {
if tillerHost == "" { if tillerHost == "" {
tunnel, err := newTillerPortForwarder(tillerNamespace) tunnel, err := newTillerPortForwarder(tillerNamespace, kubeContext)
if err != nil { if err != nil {
return err return err
} }

@ -21,6 +21,7 @@ import (
"k8s.io/kubernetes/pkg/api" "k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/client/unversioned" "k8s.io/kubernetes/pkg/client/unversioned"
"k8s.io/kubernetes/pkg/client/unversioned/clientcmd"
"k8s.io/kubernetes/pkg/labels" "k8s.io/kubernetes/pkg/labels"
"k8s.io/helm/pkg/kube" "k8s.io/helm/pkg/kube"
@ -29,8 +30,17 @@ import (
// TODO refactor out this global var // TODO refactor out this global var
var tunnel *kube.Tunnel var tunnel *kube.Tunnel
func newTillerPortForwarder(namespace string) (*kube.Tunnel, error) { func getKubeConfig(context string) clientcmd.ClientConfig {
kc := kube.New(nil) rules := clientcmd.NewDefaultClientConfigLoadingRules()
overrides := &clientcmd.ConfigOverrides{}
if context != "" {
overrides.CurrentContext = context
}
return clientcmd.NewNonInteractiveDeferredLoadingClientConfig(rules, overrides)
}
func newTillerPortForwarder(namespace, context string) (*kube.Tunnel, error) {
kc := kube.New(getKubeConfig(context))
client, err := kc.Client() client, err := kc.Client()
if err != nil { if err != nil {
return nil, err return nil, err

Loading…
Cancel
Save