ref(init): save helm paths to variables

pull/613/head
Michelle Noorali 9 years ago
parent ab906a4f27
commit 8404d743a0

@ -23,5 +23,9 @@ func init() {
} }
func home(cmd *cobra.Command, args []string) { func home(cmd *cobra.Command, args []string) {
cmd.Printf(os.ExpandEnv(helmHome) + "\n") cmd.Printf(homePath() + "\n")
}
func homePath() string {
return os.ExpandEnv(helmHome)
} }

@ -17,13 +17,13 @@ This command installs Tiller (the helm server side component) onto your
Kubernetes Cluster and sets up local configuration in $HELM_HOME (default: ~/.helm/) Kubernetes Cluster and sets up local configuration in $HELM_HOME (default: ~/.helm/)
` `
const repositoriesPath = ".repositories" var repositoriesFilePath string
const cachePath = "cache" var cachePath string
const localPath = "local" var localRepoPath string
const localCacheFilePath = localPath + "/cache.yaml" var localCacheFilePath string
var tillerImg string
var defaultRepo = map[string]string{"default-name": "default-url"} var defaultRepo = map[string]string{"default-name": "default-url"}
var tillerImg string
func init() { func init() {
initCmd.Flags().StringVarP(&tillerImg, "tiller-image", "i", "", "override tiller image") initCmd.Flags().StringVarP(&tillerImg, "tiller-image", "i", "", "override tiller image")
@ -43,7 +43,7 @@ func runInit(cmd *cobra.Command, args []string) error {
return errors.New("This command does not accept arguments. \n") return errors.New("This command does not accept arguments. \n")
} }
if err := ensureHome(os.ExpandEnv(helmHome)); err != nil { if err := ensureHome(homePath()); err != nil {
return err return err
} }
@ -51,7 +51,7 @@ func runInit(cmd *cobra.Command, args []string) error {
return err return err
} }
fmt.Printf("Tiller (the helm server side component) has been installed into your Kubernetes Cluster.\n$HELM_HOME has also been configured at %s.\nHappy Helming!\n", helmHome) fmt.Println("Happy Helming!")
return nil return nil
} }
@ -66,6 +66,7 @@ func installTiller() error {
if err != nil { if err != nil {
return fmt.Errorf("error installing %s %s", string(out), err) return fmt.Errorf("error installing %s %s", string(out), err)
} }
fmt.Println("\nTiller (the helm server side component) has been installed into your Kubernetes Cluster.")
return nil return nil
} }
@ -81,7 +82,13 @@ func buildKubectlRunner(kubectlPath string) kubectl.Runner {
// //
// If $HELM_HOME does not exist, this function will create it. // If $HELM_HOME does not exist, this function will create it.
func ensureHome(home string) error { func ensureHome(home string) error {
configDirectories := []string{home, cacheDirectory(home), localDirectory(home)} repositoriesFilePath = filepath.Join(home, "repositories.yaml")
cachePath = filepath.Join(home, "cache")
localRepoPath = filepath.Join(home, "local")
localCacheFilePath = filepath.Join(home, "cache.yaml")
fmt.Println("home path: " + home)
configDirectories := []string{home, cachePath, localRepoPath}
for _, p := range configDirectories { for _, p := range configDirectories {
if fi, err := os.Stat(p); err != nil { if fi, err := os.Stat(p); err != nil {
@ -94,44 +101,28 @@ func ensureHome(home string) error {
} }
} }
repoPath := repositoriesFile(home) if fi, err := os.Stat(repositoriesFilePath); err != nil {
if fi, err := os.Stat(repoPath); err != nil { fmt.Printf("Creating %s \n", repositoriesFilePath)
fmt.Printf("Creating %s \n", repoPath) if err := ioutil.WriteFile(repositoriesFilePath, []byte("local: localhost:8879/charts\n"), 0644); err != nil {
if err := ioutil.WriteFile(repoPath, []byte("local: localhost:8879/charts\n"), 0644); err != nil {
return err return err
} }
} else if fi.IsDir() { } else if fi.IsDir() {
return fmt.Errorf("%s must be a file, not a directory", repoPath) return fmt.Errorf("%s must be a file, not a directory", repositoriesFilePath)
} }
localCacheFile := localDirCacheFile(home) if fi, err := os.Stat(localCacheFilePath); err != nil {
if fi, err := os.Stat(localCacheFile); err != nil { fmt.Printf("Creating %s \n", localCacheFilePath)
fmt.Printf("Creating %s \n", localCacheFile) _, err := os.Create(localCacheFilePath)
_, err := os.Create(localCacheFile)
if err != nil { if err != nil {
return err return err
} }
//TODO: take this out and replace with helm update functionality //TODO: take this out and replace with helm update functionality
os.Symlink(localCacheFile, cacheDirectory(home)+"/local-cache.yaml") os.Symlink(localCacheFilePath, filepath.Join(cachePath, "local-cache.yaml"))
} else if fi.IsDir() { } else if fi.IsDir() {
return fmt.Errorf("%s must be a file, not a directory", repoPath) return fmt.Errorf("%s must be a file, not a directory", localCacheFilePath)
} }
return nil
}
func cacheDirectory(home string) string {
return filepath.Join(home, cachePath)
}
func repositoriesFile(home string) string {
return filepath.Join(home, repositoriesPath)
}
func localDirectory(home string) string { fmt.Printf("$HELM_HOME has also been configured at %s.\n", helmHome)
return filepath.Join(home, localPath) return nil
}
func localDirCacheFile(home string) string {
return filepath.Join(home, localCacheFilePath)
} }

@ -12,8 +12,8 @@ func TestEnsureHome(t *testing.T) {
t.Errorf("%s", err) t.Errorf("%s", err)
} }
dirs := []string{home, cacheDirectory(home), localDirectory(home)} expectedDirs := []string{home, cachePath, localRepoPath}
for _, dir := range dirs { for _, dir := range expectedDirs {
if fi, err := os.Stat(dir); err != nil { if fi, err := os.Stat(dir); err != nil {
t.Errorf("%s", err) t.Errorf("%s", err)
} else if !fi.IsDir() { } else if !fi.IsDir() {
@ -21,12 +21,17 @@ func TestEnsureHome(t *testing.T) {
} }
} }
if fi, err := os.Stat(repositoriesFile(home)); err != nil { if fi, err := os.Stat(repositoriesFilePath); err != nil {
t.Errorf("%s", err) t.Errorf("%s", err)
} else if fi.IsDir() { } else if fi.IsDir() {
t.Errorf("%s should not be a directory", fi) t.Errorf("%s should not be a directory", fi)
} }
if fi, err := os.Stat(localCacheFilePath); err != nil {
t.Errorf("%s", err)
} else if fi.IsDir() {
t.Errorf("%s should not be a directory", fi)
}
} }
func createTmpHome() string { func createTmpHome() string {

@ -56,7 +56,7 @@ func runPackage(cmd *cobra.Command, args []string) error {
// Save to $HELM_HOME/local directory. // Save to $HELM_HOME/local directory.
if save { if save {
if err := repo.AddChartToLocalRepo(ch, localDirectory(os.ExpandEnv(helmHome))); err != nil { if err := repo.AddChartToLocalRepo(ch, localRepoPath); err != nil {
return err return err
} }
} }

@ -39,9 +39,8 @@ func search(cmd *cobra.Command, args []string) error {
} }
func searchCacheForPattern(name string) ([]string, error) { func searchCacheForPattern(name string) ([]string, error) {
dir := cacheDirectory(os.ExpandEnv(helmHome))
fileList := []string{} fileList := []string{}
filepath.Walk(dir, func(path string, f os.FileInfo, err error) error { filepath.Walk(cachePath, func(path string, f os.FileInfo, err error) error {
if !f.IsDir() { if !f.IsDir() {
fileList = append(fileList, path) fileList = append(fileList, path)
} }

@ -1,8 +1,6 @@
package main package main
import ( import (
"os"
"github.com/deis/tiller/pkg/repo" "github.com/deis/tiller/pkg/repo"
"github.com/spf13/cobra" "github.com/spf13/cobra"
) )
@ -24,5 +22,5 @@ var serveCmd = &cobra.Command{
} }
func serve(cmd *cobra.Command, args []string) { func serve(cmd *cobra.Command, args []string) {
repo.StartLocalRepo(localDirectory(os.ExpandEnv(helmHome))) repo.StartLocalRepo(localRepoPath)
} }

Loading…
Cancel
Save