Merge pull request #758 from adamreese/feat/tunnel2

feat(tunnel): add logic for detecting tiller pod
pull/759/head
Adam Reese 9 years ago
commit d16e788122

@ -0,0 +1,36 @@
package main
import (
"fmt"
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/labels"
"github.com/kubernetes/helm/pkg/kube"
)
func newTillerPortForwarder() (*kube.Tunnel, error) {
podName, err := getTillerPodName("helm")
if err != nil {
return nil, err
}
return kube.New(nil).ForwardPort("helm", podName, 44134)
}
func getTillerPodName(namespace string) (string, error) {
client, err := kube.New(nil).Client()
if err != nil {
return "", err
}
selector := labels.Set{"app": "helm", "name": "tiller"}.AsSelector()
options := api.ListOptions{LabelSelector: selector}
pods, err := client.Pods(namespace).List(options)
if err != nil {
return "", err
}
if len(pods.Items) < 1 {
return "", fmt.Errorf("I could not find tiller")
}
return pods.Items[0].ObjectMeta.GetName(), nil
}

@ -10,6 +10,7 @@ import (
"k8s.io/kubernetes/pkg/client/unversioned/remotecommand"
)
// Tunnel describes a ssh-like tunnel to a kubernetes pod
type Tunnel struct {
Local int
Remote int
@ -33,7 +34,8 @@ func (c *Client) ForwardPort(namespace, podName string, remote int) (*Tunnel, er
return nil, err
}
// http://192.168.64.94:8080/api/v1/namespaces/helm/pods/tiller-rc-9itlq/portforward
// Build a url to the portforward endpoing
// example: http://localhost:8080/api/v1/namespaces/helm/pods/tiller-rc-9itlq/portforward
u := client.RESTClient.Post().
Resource("pods").
Namespace(namespace).

Loading…
Cancel
Save