Commit a2e57781 authored by Adam Reese's avatar Adam Reese

feat(helm): add kubeconfig context switching

closes: #1127
parent 7a5ee459
......@@ -35,8 +35,9 @@ const (
)
var (
helmHome string
tillerHost string
helmHome string
tillerHost string
kubeContext string
)
// 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.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(&kubeContext, "kube-context", "", "name of the kubeconfig context to use")
p.BoolVarP(&flagDebug, "debug", "", false, "enable verbose output")
rup := newRepoUpdateCmd(out)
......@@ -124,7 +126,7 @@ func main() {
func setupConnection(c *cobra.Command, args []string) error {
if tillerHost == "" {
tunnel, err := newTillerPortForwarder(tillerNamespace)
tunnel, err := newTillerPortForwarder(tillerNamespace, kubeContext)
if err != nil {
return err
}
......
......@@ -21,6 +21,7 @@ import (
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/client/unversioned"
"k8s.io/kubernetes/pkg/client/unversioned/clientcmd"
"k8s.io/kubernetes/pkg/labels"
"k8s.io/helm/pkg/kube"
......@@ -29,8 +30,17 @@ import (
// TODO refactor out this global var
var tunnel *kube.Tunnel
func newTillerPortForwarder(namespace string) (*kube.Tunnel, error) {
kc := kube.New(nil)
func getKubeConfig(context string) clientcmd.ClientConfig {
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()
if err != nil {
return nil, err
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment