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

fix(helm): allow user to skip namespace creation
pull/725/head
Matt Butcher 8 years ago
commit 3f2aa7a340

@ -15,15 +15,18 @@ Kubernetes Cluster and sets up local configuration in $HELM_HOME (default: ~/.he
`
var (
tillerImg string
clientOnly bool
tillerNamespace string
tillerImg string
tillerNamespace string
clientOnly bool
initSkipNamespace bool
)
func init() {
initCmd.Flags().StringVarP(&tillerImg, "tiller-image", "i", "", "override tiller image")
initCmd.Flags().BoolVarP(&clientOnly, "client-only", "c", false, "If set does not install tiller")
initCmd.Flags().StringVarP(&tillerNamespace, "namespace", "n", "helm", "set the tiller namespace")
f := initCmd.Flags()
f.StringVarP(&tillerImg, "tiller-image", "i", "", "override tiller image")
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)
}
@ -60,7 +63,7 @@ func installTiller() error {
i := client.NewInstaller()
i.Tiller["Image"] = tillerImg
i.Tiller["Namespace"] = tillerNamespace
err := i.Install(flagVerbose)
err := i.Install(flagVerbose, !initSkipNamespace)
if err != nil {
return fmt.Errorf("error installing: %s", err)

@ -33,14 +33,24 @@ func NewInstaller() *Installer {
//
// Returns the string output received from the operation, and an error if the
// 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
err := template.Must(template.New("manifest").Funcs(sprig.TxtFuncMap()).
Parse(InstallYAML)).
Execute(&b, i)
t := template.New("manifest").Funcs(sprig.TxtFuncMap())
// Add namespace
if createNS {
if err := template.Must(t.Parse(NamespaceYAML)).Execute(&b, i); err != nil {
return err
}
}
if err != nil {
// Add main install YAML
if err := template.Must(t.Parse(InstallYAML)).Execute(&b, i); err != nil {
return err
}
@ -48,11 +58,10 @@ func (i *Installer) Install(verbose bool) error {
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 InstallYAML = `
const NamespaceYAML = `
---{{$namespace := default "helm" .Tiller.Namespace}}
apiVersion: v1
kind: Namespace
@ -61,7 +70,11 @@ metadata:
app: helm
name: helm-namespace
name: {{$namespace}}
---
`
// InstallYAML is the installation YAML for DM.
const InstallYAML = `
---{{$namespace := default "helm" .Tiller.Namespace}}
apiVersion: v1
kind: ReplicationController
metadata:
@ -93,5 +106,4 @@ spec:
- containerPort: 44134
name: tiller
imagePullPolicy: Always
---
`

Loading…
Cancel
Save