mirror of https://github.com/helm/helm.git
feat(helm): add structure.go to hold paths
This commit is contained in:
parent
7fde06438f
commit
5251344318
|
@ -1,8 +1,6 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"os"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
|
@ -25,7 +23,3 @@ func init() {
|
|||
func home(cmd *cobra.Command, args []string) {
|
||||
cmd.Printf(homePath() + "\n")
|
||||
}
|
||||
|
||||
func homePath() string {
|
||||
return os.ExpandEnv(helmHome)
|
||||
}
|
||||
|
|
|
@ -5,7 +5,6 @@ import (
|
|||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/deis/tiller/pkg/client"
|
||||
"github.com/deis/tiller/pkg/kubectl"
|
||||
|
@ -17,13 +16,10 @@ This command installs Tiller (the helm server side component) onto your
|
|||
Kubernetes Cluster and sets up local configuration in $HELM_HOME (default: ~/.helm/)
|
||||
`
|
||||
|
||||
var repositoriesFilePath string
|
||||
var cachePath string
|
||||
var localRepoPath string
|
||||
var localCacheFilePath string
|
||||
var tillerImg string
|
||||
|
||||
var defaultRepo = map[string]string{"default-name": "default-url"}
|
||||
var (
|
||||
tillerImg string
|
||||
defaultRepo = map[string]string{"default-name": "default-url"}
|
||||
)
|
||||
|
||||
func init() {
|
||||
initCmd.Flags().StringVarP(&tillerImg, "tiller-image", "i", "", "override tiller image")
|
||||
|
@ -43,7 +39,7 @@ func runInit(cmd *cobra.Command, args []string) error {
|
|||
return errors.New("This command does not accept arguments. \n")
|
||||
}
|
||||
|
||||
if err := ensureHome(homePath()); err != nil {
|
||||
if err := ensureHome(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
@ -81,14 +77,8 @@ func buildKubectlRunner(kubectlPath string) kubectl.Runner {
|
|||
// ensureHome checks to see if $HELM_HOME exists
|
||||
//
|
||||
// If $HELM_HOME does not exist, this function will create it.
|
||||
func ensureHome(home string) error {
|
||||
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}
|
||||
func ensureHome() error {
|
||||
configDirectories := []string{homePath(), cacheDirectory(), localRepoDirectory()}
|
||||
|
||||
for _, p := range configDirectories {
|
||||
if fi, err := os.Stat(p); err != nil {
|
||||
|
@ -101,28 +91,30 @@ func ensureHome(home string) error {
|
|||
}
|
||||
}
|
||||
|
||||
if fi, err := os.Stat(repositoriesFilePath); err != nil {
|
||||
fmt.Printf("Creating %s \n", repositoriesFilePath)
|
||||
if err := ioutil.WriteFile(repositoriesFilePath, []byte("local: localhost:8879/charts\n"), 0644); err != nil {
|
||||
repoFile := repositoriesFile()
|
||||
if fi, err := os.Stat(repoFile); err != nil {
|
||||
fmt.Printf("Creating %s \n", repoFile)
|
||||
if err := ioutil.WriteFile(repoFile, []byte("local: localhost:8879/charts\n"), 0644); err != nil {
|
||||
return err
|
||||
}
|
||||
} else if fi.IsDir() {
|
||||
return fmt.Errorf("%s must be a file, not a directory", repositoriesFilePath)
|
||||
return fmt.Errorf("%s must be a file, not a directory", repoFile)
|
||||
}
|
||||
|
||||
if fi, err := os.Stat(localCacheFilePath); err != nil {
|
||||
fmt.Printf("Creating %s \n", localCacheFilePath)
|
||||
_, err := os.Create(localCacheFilePath)
|
||||
localRepoCacheFile := localRepoDirectory(localRepoCacheFilePath)
|
||||
if fi, err := os.Stat(localRepoCacheFile); err != nil {
|
||||
fmt.Printf("Creating %s \n", localRepoCacheFile)
|
||||
_, err := os.Create(localRepoCacheFile)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
//TODO: take this out and replace with helm update functionality
|
||||
os.Symlink(localCacheFilePath, filepath.Join(cachePath, "local-cache.yaml"))
|
||||
os.Symlink(localRepoCacheFile, cacheDirectory("local-cache.yaml"))
|
||||
} else if fi.IsDir() {
|
||||
return fmt.Errorf("%s must be a file, not a directory", localCacheFilePath)
|
||||
return fmt.Errorf("%s must be a file, not a directory", localRepoCacheFile)
|
||||
}
|
||||
|
||||
fmt.Printf("$HELM_HOME has also been configured at %s.\n", helmHome)
|
||||
fmt.Printf("$HELM_HOME has been configured at %s.\n", helmHome)
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -8,11 +8,12 @@ import (
|
|||
|
||||
func TestEnsureHome(t *testing.T) {
|
||||
home := createTmpHome()
|
||||
if err := ensureHome(home); err != nil {
|
||||
helmHome = home
|
||||
if err := ensureHome(); err != nil {
|
||||
t.Errorf("%s", err)
|
||||
}
|
||||
|
||||
expectedDirs := []string{home, cachePath, localRepoPath}
|
||||
expectedDirs := []string{homePath(), cacheDirectory(), localRepoDirectory()}
|
||||
for _, dir := range expectedDirs {
|
||||
if fi, err := os.Stat(dir); err != nil {
|
||||
t.Errorf("%s", err)
|
||||
|
@ -21,13 +22,13 @@ func TestEnsureHome(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
if fi, err := os.Stat(repositoriesFilePath); err != nil {
|
||||
if fi, err := os.Stat(repositoriesFile()); err != nil {
|
||||
t.Errorf("%s", err)
|
||||
} else if fi.IsDir() {
|
||||
t.Errorf("%s should not be a directory", fi)
|
||||
}
|
||||
|
||||
if fi, err := os.Stat(localCacheFilePath); err != nil {
|
||||
if fi, err := os.Stat(localRepoDirectory(localRepoCacheFilePath)); err != nil {
|
||||
t.Errorf("%s", err)
|
||||
} else if fi.IsDir() {
|
||||
t.Errorf("%s should not be a directory", fi)
|
||||
|
|
|
@ -56,7 +56,7 @@ func runPackage(cmd *cobra.Command, args []string) error {
|
|||
|
||||
// Save to $HELM_HOME/local directory.
|
||||
if save {
|
||||
if err := repo.AddChartToLocalRepo(ch, localRepoPath); err != nil {
|
||||
if err := repo.AddChartToLocalRepo(ch, localRepoDirectory()); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
|
|
@ -40,7 +40,7 @@ func search(cmd *cobra.Command, args []string) error {
|
|||
|
||||
func searchCacheForPattern(name string) ([]string, error) {
|
||||
fileList := []string{}
|
||||
filepath.Walk(cachePath, func(path string, f os.FileInfo, err error) error {
|
||||
filepath.Walk(cacheDirectory(), func(path string, f os.FileInfo, err error) error {
|
||||
if !f.IsDir() {
|
||||
fileList = append(fileList, path)
|
||||
}
|
||||
|
|
|
@ -22,5 +22,5 @@ var serveCmd = &cobra.Command{
|
|||
}
|
||||
|
||||
func serve(cmd *cobra.Command, args []string) {
|
||||
repo.StartLocalRepo(localRepoPath)
|
||||
repo.StartLocalRepo(localRepoDirectory())
|
||||
}
|
||||
|
|
|
@ -0,0 +1,31 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
)
|
||||
|
||||
const (
|
||||
repositoriesFilePath string = "repositories.yaml"
|
||||
cachePath string = "cache"
|
||||
localRepoPath string = "local"
|
||||
localRepoCacheFilePath string = "cache.yaml"
|
||||
)
|
||||
|
||||
func homePath() string {
|
||||
return os.ExpandEnv(helmHome)
|
||||
}
|
||||
|
||||
func cacheDirectory(paths ...string) string {
|
||||
fragments := append([]string{homePath(), cachePath}, paths...)
|
||||
return filepath.Join(fragments...)
|
||||
}
|
||||
|
||||
func localRepoDirectory(paths ...string) string {
|
||||
fragments := append([]string{homePath(), localRepoPath}, paths...)
|
||||
return filepath.Join(fragments...)
|
||||
}
|
||||
|
||||
func repositoriesFile() string {
|
||||
return filepath.Join(homePath(), repositoriesFilePath)
|
||||
}
|
Loading…
Reference in New Issue