Commit 3f2aa7a3 authored by Matt Butcher's avatar Matt Butcher

Merge pull request #714 from technosophos/fix/skip-namespace

fix(helm): allow user to skip namespace creation
parents df4dc3e1 e9440287
...@@ -16,14 +16,17 @@ Kubernetes Cluster and sets up local configuration in $HELM_HOME (default: ~/.he ...@@ -16,14 +16,17 @@ Kubernetes Cluster and sets up local configuration in $HELM_HOME (default: ~/.he
var ( var (
tillerImg string tillerImg string
clientOnly bool
tillerNamespace string tillerNamespace string
clientOnly bool
initSkipNamespace bool
) )
func init() { func init() {
initCmd.Flags().StringVarP(&tillerImg, "tiller-image", "i", "", "override tiller image") f := initCmd.Flags()
initCmd.Flags().BoolVarP(&clientOnly, "client-only", "c", false, "If set does not install tiller") f.StringVarP(&tillerImg, "tiller-image", "i", "", "override tiller image")
initCmd.Flags().StringVarP(&tillerNamespace, "namespace", "n", "helm", "set the tiller namespace") f.BoolVarP(&clientOnly, "client-only", "c", false, "If set does not install tiller")
f.BoolVarP(&initSkipNamespace, "skip-namespace", "s", false, "Do not attempt to create a namespace. Assume the namespace is already there.")
f.StringVarP(&tillerNamespace, "namespace", "n", "helm", "set the tiller namespace")
RootCommand.AddCommand(initCmd) RootCommand.AddCommand(initCmd)
} }
...@@ -60,7 +63,7 @@ func installTiller() error { ...@@ -60,7 +63,7 @@ func installTiller() error {
i := client.NewInstaller() i := client.NewInstaller()
i.Tiller["Image"] = tillerImg i.Tiller["Image"] = tillerImg
i.Tiller["Namespace"] = tillerNamespace i.Tiller["Namespace"] = tillerNamespace
err := i.Install(flagVerbose) err := i.Install(flagVerbose, !initSkipNamespace)
if err != nil { if err != nil {
return fmt.Errorf("error installing: %s", err) return fmt.Errorf("error installing: %s", err)
......
...@@ -33,14 +33,24 @@ func NewInstaller() *Installer { ...@@ -33,14 +33,24 @@ func NewInstaller() *Installer {
// //
// Returns the string output received from the operation, and an error if the // Returns the string output received from the operation, and an error if the
// command failed. // command failed.
func (i *Installer) Install(verbose bool) error { //
// If verbose is true, this will print the manifest to stdout.
//
// If createNS is true, this will also create the namespace.
func (i *Installer) Install(verbose, createNS bool) error {
var b bytes.Buffer var b bytes.Buffer
err := template.Must(template.New("manifest").Funcs(sprig.TxtFuncMap()). t := template.New("manifest").Funcs(sprig.TxtFuncMap())
Parse(InstallYAML)).
Execute(&b, i)
if err != nil { // Add namespace
if createNS {
if err := template.Must(t.Parse(NamespaceYAML)).Execute(&b, i); err != nil {
return err
}
}
// Add main install YAML
if err := template.Must(t.Parse(InstallYAML)).Execute(&b, i); err != nil {
return err return err
} }
...@@ -48,11 +58,10 @@ func (i *Installer) Install(verbose bool) error { ...@@ -48,11 +58,10 @@ func (i *Installer) Install(verbose bool) error {
fmt.Println(b.String()) fmt.Println(b.String())
} }
return kube.New(nil).Create("helm", &b) return kube.New(nil).Create(i.Tiller["Namespace"].(string), &b)
} }
// InstallYAML is the installation YAML for DM. const NamespaceYAML = `
const InstallYAML = `
---{{$namespace := default "helm" .Tiller.Namespace}} ---{{$namespace := default "helm" .Tiller.Namespace}}
apiVersion: v1 apiVersion: v1
kind: Namespace kind: Namespace
...@@ -61,7 +70,11 @@ metadata: ...@@ -61,7 +70,11 @@ metadata:
app: helm app: helm
name: helm-namespace name: helm-namespace
name: {{$namespace}} name: {{$namespace}}
--- `
// InstallYAML is the installation YAML for DM.
const InstallYAML = `
---{{$namespace := default "helm" .Tiller.Namespace}}
apiVersion: v1 apiVersion: v1
kind: ReplicationController kind: ReplicationController
metadata: metadata:
...@@ -93,5 +106,4 @@ spec: ...@@ -93,5 +106,4 @@ spec:
- containerPort: 44134 - containerPort: 44134
name: tiller name: tiller
imagePullPolicy: Always imagePullPolicy: Always
---
` `
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