Commit 6c0c4ce3 authored by Adam Reese's avatar Adam Reese Committed by GitHub
Browse files

Merge pull request #1691 from adamreese/feat/tiller-namespace

feat(*): allow tiller to be installed in an alternate namespace
parents 7f4ea910 84928e27
main Release add-codeql dependabot/go_modules/github.com/docker/distribution-2.8.2incompatible dependabot/go_modules/github.com/lib/pq-1.10.9 dependabot/go_modules/github.com/rubenv/sql-migrate-1.4.0 dependabot/go_modules/golang.org/x/crypto-0.9.0 dependabot/go_modules/golang.org/x/term-0.8.0 dependabot/go_modules/k8s.io/klog/v2-2.100.1 dev-v2 feat-v3/event-emitter-lua release-2.10 release-2.11 release-2.12 release-2.13 release-2.14 release-2.15 release-2.16 release-2.17 release-2.2 release-2.3 release-2.4 release-2.5 release-2.6 release-2.7 release-2.8 release-2.9 release-3.0 release-3.1 release-3.10 release-3.11 release-3.12 release-3.2 release-3.3 release-3.4 release-3.5 release-3.6 release-3.6.1 release-3.6.2 release-3.7 release-3.8 release-3.9 release-v3.0.0-beta.4 v3.12.0 v3.12.0-rc.1 v3.12.0-dev.1 v3.11.3 v3.11.2 v3.11.1 v3.11.0 v3.11.0-rc.2 v3.11.0-rc.1 v3.10.3 v3.10.2 v3.10.1 v3.10.0 v3.10.0-rc.1 v3.9.4 v3.9.3 v3.9.2 v3.9.1 v3.9.0 v3.9.0-rc.1 v3.8.2 v3.8.1 v3.8.0 v3.8.0-rc.2 v3.8.0-rc.1 v3.7.2 v3.7.1 v3.7.0 v3.7.0-rc.3 v3.7.0-rc.2 v3.7.0-rc.1 v3.6.3 v3.6.2 v3.6.1 v3.6.0 v3.6.0-rc.1 v3.5.4 v3.5.3 v3.5.2 v3.5.1 v3.5.0 v3.5.0-rc.2 v3.5.0-rc.1 v3.4.2 v3.4.1 v3.4.0 v3.4.0-rc.1 v3.3.4 v3.3.3 v3.3.2 v3.3.1 v3.3.0 v3.3.0-rc.2 v3.3.0-rc.1 v3.2.4 v3.2.3 v3.2.2 v3.2.1 v3.2.0 v3.2.0-rc.1 v3.1.3 v3.1.2 v3.1.1 v3.1.0 v3.1.0-rc.3 v3.1.0-rc.2 v3.1.0-rc.1 v3.0.3 v3.0.2 v3.0.1 v3.0.0 v3.0.0-rc.4 v3.0.0-rc.3 v3.0.0-rc.2 v3.0.0-rc.1 v3.0.0-beta.5 v3.0.0-beta.4 v3.0.0-beta.3 v3.0.0-beta.2 v3.0.0-beta.1 v3.0.0-alpha.2 v3.0.0-alpha.1 v2.17.0 v2.17.0-rc.1 v2.16.12 v2.16.11 v2.16.10 v2.16.9 v2.16.8 v2.16.7 v2.16.6 v2.16.5 v2.16.4 v2.16.3 v2.16.2 v2.16.1 v2.16.0 v2.16.0-rc.2 v2.16.0-rc.1 v2.15.2 v2.15.1 v2.15.0 v2.15.0-rc.2 v2.15.0-rc.1 v2.14.3 v2.14.2 v2.14.1 v2.14.0 v2.14.0-rc.2 v2.14.0-rc.1 v2.13.1 v2.13.1-rc.1 v2.13.0 v2.13.0-rc.2 v2.13.0-rc.1 v2.12.3 v2.12.2 v2.12.1 v2.12.0 v2.12.0-rc.2 v2.12.0-rc.1 v2.11.0 v2.11.0-rc.4 v2.11.0-rc.3 v2.11.0-rc.2 v2.11.0-rc.1 v2.10.0 v2.10.0-rc.3 v2.10.0-rc.2 v2.10.0-rc.1 v2.9.1 v2.9.0 v2.9.0-rc5 v2.9.0-rc4 v2.9.0-rc3 v2.9.0-rc2 v2.9.0-rc1 v2.8.2 v2.8.2-rc1 v2.8.1 v2.8.0 v2.8.0-rc.1 v2.7.2 v2.7.1 v2.7.0 v2.7.0-rc1 v2.6.2 v2.6.1 v2.6.0 v2.5.1 v2.5.0 v2.4.2 v2.4.1 v2.4.0 v2.3.1 v2.3.0 v2.2.3 v2.2.2 v2.2.1 v2.2.0
No related merge requests found
Showing with 72 additions and 22 deletions
+72 -22
...@@ -23,6 +23,7 @@ import ( ...@@ -23,6 +23,7 @@ import (
"io/ioutil" "io/ioutil"
"log" "log"
"os" "os"
"path/filepath"
"strings" "strings"
"github.com/spf13/cobra" "github.com/spf13/cobra"
...@@ -40,12 +41,14 @@ const ( ...@@ -40,12 +41,14 @@ const (
localRepoIndexFilePath = "index.yaml" localRepoIndexFilePath = "index.yaml"
homeEnvVar = "HELM_HOME" homeEnvVar = "HELM_HOME"
hostEnvVar = "HELM_HOST" hostEnvVar = "HELM_HOST"
tillerNamespaceEnvVar = "TILLER_NAMESPACE"
) )
var ( var (
helmHome string helmHome string
tillerHost string tillerHost string
kubeContext string tillerNamespace string
kubeContext string
) )
// flagDebug is a signal that the user wants additional output. // flagDebug is a signal that the user wants additional output.
...@@ -68,9 +71,10 @@ Common actions from this point include: ...@@ -68,9 +71,10 @@ Common actions from this point include:
- helm list: list releases of charts - helm list: list releases of charts
Environment: Environment:
$HELM_HOME set an alternative location for Helm files. By default, these are stored in ~/.helm $HELM_HOME set an alternative location for Helm files. By default, these are stored in ~/.helm
$HELM_HOST set an alternative Tiller host. The format is host:port $HELM_HOST set an alternative Tiller host. The format is host:port
$KUBECONFIG set an alternate Kubernetes configuration file (default "~/.kube/config") $TILLER_NAMESPACE set an alternative Tiller namespace (default "kube-namespace")
$KUBECONFIG set an alternative Kubernetes configuration file (default "~/.kube/config")
` `
func newRootCmd(out io.Writer) *cobra.Command { func newRootCmd(out io.Writer) *cobra.Command {
...@@ -83,16 +87,12 @@ func newRootCmd(out io.Writer) *cobra.Command { ...@@ -83,16 +87,12 @@ func newRootCmd(out io.Writer) *cobra.Command {
teardown() teardown()
}, },
} }
home := os.Getenv(homeEnvVar)
if home == "" {
home = "$HOME/.helm"
}
thost := os.Getenv(hostEnvVar)
p := cmd.PersistentFlags() p := cmd.PersistentFlags()
p.StringVar(&helmHome, "home", home, "location of your Helm config. Overrides $HELM_HOME") p.StringVar(&helmHome, "home", defaultHelmHome(), "location of your Helm config. Overrides $HELM_HOME")
p.StringVar(&tillerHost, "host", thost, "address of tiller. Overrides $HELM_HOST") p.StringVar(&tillerHost, "host", defaultHelmHost(), "address of tiller. Overrides $HELM_HOST")
p.StringVar(&kubeContext, "kube-context", "", "name of the kubeconfig context to use") p.StringVar(&kubeContext, "kube-context", "", "name of the kubeconfig context to use")
p.BoolVar(&flagDebug, "debug", false, "enable verbose output") p.BoolVar(&flagDebug, "debug", false, "enable verbose output")
p.StringVar(&tillerNamespace, "tiller-namespace", defaultTillerNamespace(), "namespace of tiller")
// Tell gRPC not to log to console. // Tell gRPC not to log to console.
grpclog.SetLogger(log.New(ioutil.Discard, "", log.LstdFlags)) grpclog.SetLogger(log.New(ioutil.Discard, "", log.LstdFlags))
...@@ -146,7 +146,7 @@ func main() { ...@@ -146,7 +146,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(environment.TillerNamespace, kubeContext) tunnel, err := newTillerPortForwarder(tillerNamespace, kubeContext)
if err != nil { if err != nil {
return err return err
} }
...@@ -194,10 +194,28 @@ func prettyError(err error) error { ...@@ -194,10 +194,28 @@ func prettyError(err error) error {
return errors.New(grpc.ErrorDesc(err)) return errors.New(grpc.ErrorDesc(err))
} }
func defaultHelmHome() string {
if home := os.Getenv(homeEnvVar); home != "" {
return home
}
return filepath.Join(os.Getenv("HOME"), ".helm")
}
func homePath() string { func homePath() string {
return os.ExpandEnv(helmHome) return os.ExpandEnv(helmHome)
} }
func defaultHelmHost() string {
return os.Getenv(hostEnvVar)
}
func defaultTillerNamespace() string {
if ns := os.Getenv(tillerNamespaceEnvVar); ns != "" {
return ns
}
return environment.DefaultTillerNamespace
}
// getKubeClient is a convenience method for creating kubernetes config and client // getKubeClient is a convenience method for creating kubernetes config and client
// for a given kubeconfig context // for a given kubeconfig context
func getKubeClient(context string) (*restclient.Config, *internalclientset.Clientset, error) { func getKubeClient(context string) (*restclient.Config, *internalclientset.Clientset, error) {
......
...@@ -29,7 +29,6 @@ import ( ...@@ -29,7 +29,6 @@ import (
"k8s.io/helm/cmd/helm/helmpath" "k8s.io/helm/cmd/helm/helmpath"
"k8s.io/helm/cmd/helm/installer" "k8s.io/helm/cmd/helm/installer"
"k8s.io/helm/pkg/repo" "k8s.io/helm/pkg/repo"
"k8s.io/helm/pkg/tiller/environment"
) )
const initDesc = ` const initDesc = `
...@@ -75,8 +74,7 @@ type initCmd struct { ...@@ -75,8 +74,7 @@ type initCmd struct {
func newInitCmd(out io.Writer) *cobra.Command { func newInitCmd(out io.Writer) *cobra.Command {
i := &initCmd{ i := &initCmd{
out: out, out: out,
namespace: environment.TillerNamespace,
} }
cmd := &cobra.Command{ cmd := &cobra.Command{
...@@ -87,6 +85,7 @@ func newInitCmd(out io.Writer) *cobra.Command { ...@@ -87,6 +85,7 @@ func newInitCmd(out io.Writer) *cobra.Command {
if len(args) != 0 { if len(args) != 0 {
return errors.New("This command does not accept arguments") return errors.New("This command does not accept arguments")
} }
i.namespace = tillerNamespace
i.home = helmpath.Home(homePath()) i.home = helmpath.Home(homePath())
return i.run() return i.run()
}, },
......
...@@ -88,7 +88,12 @@ func generateDeployment(namespace, image string) *extensions.Deployment { ...@@ -88,7 +88,12 @@ func generateDeployment(namespace, image string) *extensions.Deployment {
Name: "tiller", Name: "tiller",
Image: image, Image: image,
ImagePullPolicy: "IfNotPresent", ImagePullPolicy: "IfNotPresent",
Ports: []api.ContainerPort{{ContainerPort: 44134, Name: "tiller"}}, Ports: []api.ContainerPort{
{ContainerPort: 44134, Name: "tiller"},
},
Env: []api.EnvVar{
{Name: "TILLER_NAMESPACE", Value: namespace},
},
LivenessProbe: &api.Probe{ LivenessProbe: &api.Probe{
Handler: api.Handler{ Handler: api.Handler{
HTTPGet: &api.HTTPGetAction{ HTTPGet: &api.HTTPGetAction{
......
...@@ -57,6 +57,10 @@ func TestDeploymentManifest(t *testing.T) { ...@@ -57,6 +57,10 @@ func TestDeploymentManifest(t *testing.T) {
if got := dep.Spec.Template.Spec.Containers[0].Image; got != tt.expect { if got := dep.Spec.Template.Spec.Containers[0].Image; got != tt.expect {
t.Errorf("%s: expected image %q, got %q", tt.name, tt.expect, got) t.Errorf("%s: expected image %q, got %q", tt.name, tt.expect, got)
} }
if got := dep.Spec.Template.Spec.Containers[0].Env[0].Value; got != api.NamespaceDefault {
t.Errorf("%s: expected namespace %q, got %q", tt.name, api.NamespaceDefault, got)
}
} }
} }
......
...@@ -18,10 +18,12 @@ package main // import "k8s.io/helm/cmd/tiller" ...@@ -18,10 +18,12 @@ package main // import "k8s.io/helm/cmd/tiller"
import ( import (
"fmt" "fmt"
"io/ioutil"
"log" "log"
"net" "net"
"net/http" "net/http"
"os" "os"
"strings"
"github.com/spf13/cobra" "github.com/spf13/cobra"
...@@ -70,9 +72,11 @@ var rootCommand = &cobra.Command{ ...@@ -70,9 +72,11 @@ var rootCommand = &cobra.Command{
Run: start, Run: start,
} }
func main() { func init() {
log.SetFlags(log.Flags() | log.Lshortfile) log.SetFlags(log.Flags() | log.Lshortfile)
}
func main() {
p := rootCommand.PersistentFlags() p := rootCommand.PersistentFlags()
p.StringVarP(&grpcAddr, "listen", "l", ":44134", "address:port to listen on") p.StringVarP(&grpcAddr, "listen", "l", ":44134", "address:port to listen on")
p.StringVar(&store, "storage", storageConfigMap, "storage driver to use. One of 'configmap' or 'memory'") p.StringVar(&store, "storage", storageConfigMap, "storage driver to use. One of 'configmap' or 'memory'")
...@@ -90,7 +94,7 @@ func start(c *cobra.Command, args []string) { ...@@ -90,7 +94,7 @@ func start(c *cobra.Command, args []string) {
case storageMemory: case storageMemory:
env.Releases = storage.Init(driver.NewMemory()) env.Releases = storage.Init(driver.NewMemory())
case storageConfigMap: case storageConfigMap:
env.Releases = storage.Init(driver.NewConfigMaps(clientset.Core().ConfigMaps(environment.TillerNamespace))) env.Releases = storage.Init(driver.NewConfigMaps(clientset.Core().ConfigMaps(namespace())))
} }
lstn, err := net.Listen("tcp", grpcAddr) lstn, err := net.Listen("tcp", grpcAddr)
...@@ -132,3 +136,19 @@ func start(c *cobra.Command, args []string) { ...@@ -132,3 +136,19 @@ func start(c *cobra.Command, args []string) {
fmt.Fprintf(os.Stderr, "Probes server died: %s\n", err) fmt.Fprintf(os.Stderr, "Probes server died: %s\n", err)
} }
} }
// namespace returns the namespace of tiller
func namespace() string {
if ns := os.Getenv("POD_NAMESPACE"); ns != "" {
return ns
}
// Fall back to the namespace associated with the service account token, if available
if data, err := ioutil.ReadFile("/var/run/secrets/kubernetes.io/serviceaccount/namespace"); err == nil {
if ns := strings.TrimSpace(string(data)); len(ns) > 0 {
return ns
}
}
return environment.DefaultTillerNamespace
}
...@@ -110,12 +110,16 @@ You can explicitly tell `helm init` to... ...@@ -110,12 +110,16 @@ You can explicitly tell `helm init` to...
- Install the canary build with the `--canary-image` flag - Install the canary build with the `--canary-image` flag
- Install a particular image (version) with `--tiller-image` - Install a particular image (version) with `--tiller-image`
- Install to a particular cluster with `--kube-context` - Install to a particular cluster with `--kube-context`
- Install into a particular namespace with `--tiller-namespace`
Once Tiller is installed, running `helm version` should show you both Once Tiller is installed, running `helm version` should show you both
the client and server version. (If it shows only the client version, the client and server version. (If it shows only the client version,
`helm` cannot yet connect to the server. Use `kubectl` to see if any `helm` cannot yet connect to the server. Use `kubectl` to see if any
`tiller` pods are running.) `tiller` pods are running.)
If Helm will look for Tiller in the `kube-system` namespace unless
`--tiller-namespace` or `TILLER_NAMESPACE` is set.
### Installing Tiller Canary Builds ### Installing Tiller Canary Builds
Canary images are built from the `master` branch. They may not be Canary images are built from the `master` branch. They may not be
......
...@@ -33,8 +33,8 @@ import ( ...@@ -33,8 +33,8 @@ import (
"k8s.io/helm/pkg/storage/driver" "k8s.io/helm/pkg/storage/driver"
) )
// TillerNamespace is the namespace tiller is running in. // DefaultTillerNamespace is the default namespace for tiller.
const TillerNamespace = "kube-system" const DefaultTillerNamespace = "kube-system"
// GoTplEngine is the name of the Go template engine, as registered in the EngineYard. // GoTplEngine is the name of the Go template engine, as registered in the EngineYard.
const GoTplEngine = "gotpl" const GoTplEngine = "gotpl"
......
Supports Markdown
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