Commit 39ba728b authored by Adam Reese's avatar Adam Reese

ref(cmd): refactor init command

parent a1fffc69
...@@ -84,12 +84,13 @@ func newRootCmd(out io.Writer) *cobra.Command { ...@@ -84,12 +84,13 @@ func newRootCmd(out io.Writer) *cobra.Command {
cmd.AddCommand( cmd.AddCommand(
newCreateCmd(out), newCreateCmd(out),
newDeleteCmd(nil, out),
newGetCmd(nil, out), newGetCmd(nil, out),
newInitCmd(out),
newInspectCmd(nil, out),
newInstallCmd(nil, out),
newListCmd(nil, out), newListCmd(nil, out),
newStatusCmd(nil, out), newStatusCmd(nil, out),
newInstallCmd(nil, out),
newDeleteCmd(nil, out),
newInspectCmd(nil, out),
newUpgradeCmd(nil, out), newUpgradeCmd(nil, out),
) )
return cmd return cmd
......
...@@ -19,6 +19,7 @@ package main ...@@ -19,6 +19,7 @@ package main
import ( import (
"errors" "errors"
"fmt" "fmt"
"io"
"os" "os"
"github.com/spf13/cobra" "github.com/spf13/cobra"
...@@ -32,58 +33,54 @@ Kubernetes Cluster and sets up local configuration in $HELM_HOME (default: ~/.he ...@@ -32,58 +33,54 @@ Kubernetes Cluster and sets up local configuration in $HELM_HOME (default: ~/.he
` `
var ( var (
tillerImg string
clientOnly bool
defaultRepository = "kubernetes-charts" defaultRepository = "kubernetes-charts"
defaultRepositoryURL = "http://storage.googleapis.com/kubernetes-charts" defaultRepositoryURL = "http://storage.googleapis.com/kubernetes-charts"
) )
func init() { type initCmd struct {
f := initCmd.Flags() image string
f.StringVarP(&tillerImg, "tiller-image", "i", "", "override tiller image") clientOnly bool
f.BoolVarP(&clientOnly, "client-only", "c", false, "If set does not install tiller") out io.Writer
RootCommand.AddCommand(initCmd)
} }
var initCmd = &cobra.Command{ func newInitCmd(out io.Writer) *cobra.Command {
Use: "init", i := &initCmd{
Short: "initialize Helm on both client and server", out: out,
Long: initDesc, }
RunE: runInit, cmd := &cobra.Command{
Use: "init",
Short: "initialize Helm on both client and server",
Long: initDesc,
RunE: func(cmd *cobra.Command, args []string) error {
if len(args) != 0 {
return errors.New("This command does not accept arguments")
}
return i.run()
},
}
cmd.Flags().StringVarP(&i.image, "tiller-image", "i", "", "override tiller image")
cmd.Flags().BoolVarP(&i.clientOnly, "client-only", "c", false, "If set does not install tiller")
return cmd
} }
// runInit initializes local config and installs tiller to Kubernetes Cluster // runInit initializes local config and installs tiller to Kubernetes Cluster
func runInit(cmd *cobra.Command, args []string) error { func (i *initCmd) run() error {
if len(args) != 0 {
return errors.New("This command does not accept arguments. \n")
}
if err := ensureHome(); err != nil { if err := ensureHome(); err != nil {
return err return err
} }
if !clientOnly { if !i.clientOnly {
if err := installTiller(); err != nil { if err := client.Install(tillerNamespace, i.image, flagDebug); err != nil {
return err return fmt.Errorf("error installing: %s", err)
} }
fmt.Fprintln(i.out, "\nTiller (the helm server side component) has been installed into your Kubernetes Cluster.")
} else { } else {
fmt.Println("Not installing tiller due to 'client-only' flag having been set") fmt.Fprintln(i.out, "Not installing tiller due to 'client-only' flag having been set")
} }
fmt.Fprintln(i.out, "Happy Helming!")
fmt.Println("Happy Helming!")
return nil
}
func installTiller() error {
if err := client.Install(tillerNamespace, tillerImg, flagDebug); err != nil {
return fmt.Errorf("error installing: %s", err)
}
fmt.Println("\nTiller (the helm server side component) has been installed into your Kubernetes Cluster.")
return nil return nil
} }
// requireHome checks to see if $HELM_HOME exists, and returns an error if it does not.
func requireHome() error { func requireHome() error {
dirs := []string{homePath(), repositoryDirectory(), cacheDirectory(), localRepoDirectory()} dirs := []string{homePath(), repositoryDirectory(), cacheDirectory(), localRepoDirectory()}
for _, d := range dirs { for _, d := range dirs {
......
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