Merge pull request #725 from technosophos/fix/724-tiller-host

fix(helm): allow TILLER_HOME to be used everywhere
pull/723/head
Matt Butcher 9 years ago
commit 0cbb6c6e86

@ -6,11 +6,20 @@ import (
"os"
"strings"
"github.com/kubernetes/helm/pkg/helm"
"github.com/spf13/cobra"
"google.golang.org/grpc"
)
const (
homeEnvVar = "HELM_HOME"
defaultHome = "$HOME/.helm" // FIXME: is $HOME windows compatible?
hostEnvVar = "TILLER_HOST"
defaultHost = ":44134"
)
var helmHome string
var tillerHost string
// flagVerbose is a signal that the user wants additional output.
var flagVerbose bool
@ -33,6 +42,7 @@ Common actions from this point include:
Environment:
$HELM_HOME Set an alternative location for Helm files. By default, these are stored in ~/.helm
$TILLER_HOST Set an alternative Tiller host. The format is host:port (default ":44134").
`
// RootCommand is the top-level command for Helm.
@ -40,11 +50,22 @@ var RootCommand = &cobra.Command{
Use: "helm",
Short: "The Helm package manager for Kubernetes.",
Long: globalUsage,
PersistentPreRun: bootstrap,
}
func init() {
RootCommand.PersistentFlags().StringVar(&helmHome, "home", "$HOME/.helm", "location of your Helm config")
RootCommand.PersistentFlags().BoolVarP(&flagVerbose, "verbose", "v", false, "enable verbose output")
home := os.Getenv(homeEnvVar)
if home == "" {
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 $TILLER_HOST.")
p.BoolVarP(&flagVerbose, "verbose", "v", false, "enable verbose output")
}
func main() {
@ -53,6 +74,11 @@ func main() {
}
}
func bootstrap(c *cobra.Command, args []string) {
// Set up the gRPC config.
helm.Config.ServAddr = tillerHost
}
func checkArgsLength(expectedNum, actualNum int, requiredArgs ...string) error {
if actualNum != expectedNum {
arg := "arguments"

@ -2,7 +2,6 @@ package main
import (
"fmt"
"os"
"github.com/spf13/cobra"
@ -19,17 +18,10 @@ path to a chart directory or the name of a
chart in the current working directory.
`
const (
hostEnvVar = "TILLER_HOST"
defaultHost = ":44134"
)
// install flags & args
var (
// installArg is the name or relative path of the chart to install
installArg string
// tillerHost overrides TILLER_HOST envVar
tillerHost string
// installDryRun performs a dry-run install
installDryRun bool
)
@ -46,7 +38,6 @@ func runInstall(cmd *cobra.Command, args []string) error {
return err
}
installArg = args[0]
setupInstallEnv()
res, err := helm.InstallRelease(installArg, installDryRun)
if err != nil {
@ -72,23 +63,7 @@ func printRelease(rel *release.Release) {
}
}
func setupInstallEnv() {
// The 'host' flag takes precendence uber alles.
// If set, proceed with install using provided host
// address. If unset, the 'TILLER_HOST' environment
// variable (if set) is used, otherwise defaults to ":44134".
if tillerHost == "" {
tillerHost = os.Getenv(hostEnvVar)
if tillerHost == "" {
tillerHost = defaultHost
}
}
helm.Config.ServAddr = tillerHost
}
func init() {
installCmd.Flags().StringVar(&tillerHost, "host", "", "address of tiller server (default \":44134\")")
installCmd.Flags().BoolVar(&installDryRun, "dry-run", false, "simulate an install")
RootCommand.AddCommand(installCmd)

Loading…
Cancel
Save