feat(tunnel): wire in the tunnel setup and teardown

pull/759/head
Adam Reese 9 years ago
parent d16e788122
commit f0a15743d4

@ -24,6 +24,7 @@ var deleteCommand = &cobra.Command{
Short: "Given a release name, delete the release from Kubernetes",
Long: deleteDesc,
RunE: delRelease,
PersistentPreRunE: setupConnection,
}
func init() {

@ -50,6 +50,7 @@ var getCommand = &cobra.Command{
Short: "Download a named release",
Long: getHelp,
RunE: getCmd,
PersistentPreRunE: setupConnection,
}
var getValuesCommand = &cobra.Command{

@ -50,7 +50,7 @@ var RootCommand = &cobra.Command{
Use: "helm",
Short: "The Helm package manager for Kubernetes.",
Long: globalUsage,
PersistentPreRun: bootstrap,
PersistentPostRun: teardown,
}
func init() {
@ -59,9 +59,6 @@ func init() {
home = "$HOME/.helm"
}
thost := os.Getenv(hostEnvVar)
if thost == "" {
thost = defaultHost
}
p := RootCommand.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.")
@ -74,12 +71,32 @@ func main() {
}
}
func bootstrap(c *cobra.Command, args []string) {
func setupConnection(c *cobra.Command, args []string) error {
if tillerHost == "" {
// Should failure fall back to default host?
tunnel, err := newTillerPortForwarder()
if err != nil {
return err
}
tillerHost = fmt.Sprintf(":%d", tunnel.Local)
if flagVerbose {
fmt.Printf("Created tunnel using local port: '%d'\n", tunnel.Local)
}
}
// Set up the gRPC config.
helm.Config.ServAddr = tillerHost
if flagVerbose {
fmt.Printf("Server: %q\n", helm.Config.ServAddr)
}
return nil
}
func teardown(c *cobra.Command, args []string) {
if tunnel != nil {
tunnel.Close()
}
}
func checkArgsLength(expectedNum, actualNum int, requiredArgs ...string) error {

@ -39,6 +39,7 @@ var installCmd = &cobra.Command{
Short: "install a chart archive.",
Long: installDesc,
RunE: runInstall,
PersistentPreRunE: setupConnection,
}
func init() {

@ -42,6 +42,7 @@ var listCommand = &cobra.Command{
Long: listHelp,
RunE: listCmd,
Aliases: []string{"ls"},
PersistentPreRunE: setupConnection,
}
var (

@ -17,6 +17,7 @@ var statusCommand = &cobra.Command{
Short: "Displays the status of the named release",
Long: statusHelp,
RunE: status,
PersistentPreRunE: setupConnection,
}
func init() {

@ -9,12 +9,17 @@ import (
"github.com/kubernetes/helm/pkg/kube"
)
// TODO refactor out this global var
var tunnel *kube.Tunnel
func newTillerPortForwarder() (*kube.Tunnel, error) {
podName, err := getTillerPodName("helm")
if err != nil {
return nil, err
}
return kube.New(nil).ForwardPort("helm", podName, 44134)
// FIXME use a constain that is accessable on init
const tillerPort = 44134
return kube.New(nil).ForwardPort("helm", podName, tillerPort)
}
func getTillerPodName(namespace string) (string, error) {
@ -23,6 +28,7 @@ func getTillerPodName(namespace string) (string, error) {
return "", err
}
// TODO use a const for labels
selector := labels.Set{"app": "helm", "name": "tiller"}.AsSelector()
options := api.ListOptions{LabelSelector: selector}
pods, err := client.Pods(namespace).List(options)

Loading…
Cancel
Save