diff --git a/cmd/helm/init.go b/cmd/helm/init.go index a796c144e..030a0dae0 100644 --- a/cmd/helm/init.go +++ b/cmd/helm/init.go @@ -100,18 +100,18 @@ func ensureHome() error { return fmt.Errorf("%s must be a file, not a directory", repoFile) } - localRepoCacheFile := localRepoDirectory(localRepoCacheFilePath) - if fi, err := os.Stat(localRepoCacheFile); err != nil { - fmt.Printf("Creating %s \n", localRepoCacheFile) - _, err := os.Create(localRepoCacheFile) + localRepoIndexFile := localRepoDirectory(localRepoIndexFilePath) + if fi, err := os.Stat(localRepoIndexFile); err != nil { + fmt.Printf("Creating %s \n", localRepoIndexFile) + _, err := os.Create(localRepoIndexFile) if err != nil { return err } //TODO: take this out and replace with helm update functionality - os.Symlink(localRepoCacheFile, cacheDirectory("local-cache.yaml")) + os.Symlink(localRepoIndexFile, cacheDirectory("local-index.yaml")) } else if fi.IsDir() { - return fmt.Errorf("%s must be a file, not a directory", localRepoCacheFile) + return fmt.Errorf("%s must be a file, not a directory", localRepoIndexFile) } fmt.Printf("$HELM_HOME has been configured at %s.\n", helmHome) diff --git a/cmd/helm/init_test.go b/cmd/helm/init_test.go index 6c5bebbe9..72e68a7e5 100644 --- a/cmd/helm/init_test.go +++ b/cmd/helm/init_test.go @@ -28,7 +28,7 @@ func TestEnsureHome(t *testing.T) { t.Errorf("%s should not be a directory", fi) } - if fi, err := os.Stat(localRepoDirectory(localRepoCacheFilePath)); err != nil { + if fi, err := os.Stat(localRepoDirectory(localRepoIndexFilePath)); err != nil { t.Errorf("%s", err) } else if fi.IsDir() { t.Errorf("%s should not be a directory", fi) diff --git a/cmd/helm/repo.go b/cmd/helm/repo.go index 86909c11e..0f820334b 100644 --- a/cmd/helm/repo.go +++ b/cmd/helm/repo.go @@ -47,7 +47,7 @@ func runRepoAdd(cmd *cobra.Command, args []string) error { } name, url := args[0], args[1] - if err := downloadCacheFile(name, url); err != nil { + if err := downloadIndexFile(name, url); err != nil { return errors.New("Oops! Looks like " + url + " is not a valid chart repository or cannot be reached\n") } diff --git a/cmd/helm/search.go b/cmd/helm/search.go index 378ced5a2..64cff12da 100644 --- a/cmd/helm/search.go +++ b/cmd/helm/search.go @@ -64,9 +64,9 @@ func searchCacheForPattern(dir string, search string) ([]string, error) { }) matches := []string{} for _, f := range fileList { - cache, _ := repo.LoadCacheFile(f) - m := searchChartRefsForPattern(search, cache.Entries) - repoName := strings.TrimSuffix(filepath.Base(f), "-cache.yaml") + index, _ := repo.LoadIndexFile(f) + m := searchChartRefsForPattern(search, index.Entries) + repoName := strings.TrimSuffix(filepath.Base(f), "-index.yaml") for _, c := range m { matches = append(matches, repoName+"/"+c) } diff --git a/cmd/helm/search_test.go b/cmd/helm/search_test.go index 292e34c24..7001cdec3 100644 --- a/cmd/helm/search_test.go +++ b/cmd/helm/search_test.go @@ -7,7 +7,7 @@ import ( ) const testDir = "testdata/" -const testFile = "testdata/local-cache.yaml" +const testFile = "testdata/local-index.yaml" type searchTestCase struct { in string @@ -49,9 +49,9 @@ func validateEntries(t *testing.T, in string, found []string, expected []string) } func searchTestRunner(t *testing.T, tc searchTestCase) { - cf, err := repo.LoadCacheFile(testFile) + cf, err := repo.LoadIndexFile(testFile) if err != nil { - t.Errorf("Failed to load cache file : %s : %s", testFile, err) + t.Errorf("Failed to load index file : %s : %s", testFile, err) } u := searchChartRefsForPattern(tc.in, cf.Entries) diff --git a/cmd/helm/structure.go b/cmd/helm/structure.go index 056be291d..e6fe9a482 100644 --- a/cmd/helm/structure.go +++ b/cmd/helm/structure.go @@ -9,7 +9,7 @@ const ( repositoriesFilePath string = "repositories.yaml" cachePath string = "cache" localRepoPath string = "local" - localRepoCacheFilePath string = "cache.yaml" + localRepoIndexFilePath string = "index.yaml" ) func homePath() string { diff --git a/cmd/helm/testdata/foobar-cache.yaml b/cmd/helm/testdata/foobar-index.yaml similarity index 100% rename from cmd/helm/testdata/foobar-cache.yaml rename to cmd/helm/testdata/foobar-index.yaml diff --git a/cmd/helm/testdata/local-cache.yaml b/cmd/helm/testdata/local-index.yaml similarity index 100% rename from cmd/helm/testdata/local-cache.yaml rename to cmd/helm/testdata/local-index.yaml diff --git a/cmd/helm/update.go b/cmd/helm/update.go index 4528d8f09..cab194665 100644 --- a/cmd/helm/update.go +++ b/cmd/helm/update.go @@ -46,7 +46,7 @@ func updateCharts(repos map[string]string, verbose bool) { wg.Add(1) go func(n, u string) { defer wg.Done() - err := downloadCacheFile(n, u) + err := downloadIndexFile(n, u) if err != nil { updateErr := "...Unable to get an update from the " + n + " chart repository" if verbose { @@ -62,17 +62,17 @@ func updateCharts(repos map[string]string, verbose bool) { fmt.Println("Update Complete. Happy Helming!") } -func downloadCacheFile(name, url string) error { - var cacheURL string +func downloadIndexFile(name, url string) error { + var indexURL string - cacheURL = strings.TrimSuffix(url, "/") + "/cache.yaml" - resp, err := http.Get(cacheURL) + indexURL = strings.TrimSuffix(url, "/") + "/index.yaml" + resp, err := http.Get(indexURL) if err != nil { return err } defer resp.Body.Close() - var cacheFile *os.File + var indexFile *os.File var r repo.RepoFile b, err := ioutil.ReadAll(resp.Body) @@ -84,12 +84,12 @@ func downloadCacheFile(name, url string) error { return err } - cacheFile, err = os.Create(cacheDirectory(name + "-cache.yaml")) + indexFile, err = os.Create(cacheDirectory(name + "-index.yaml")) if err != nil { return err } - if _, err := io.Copy(cacheFile, resp.Body); err != nil { + if _, err := io.Copy(indexFile, resp.Body); err != nil { return err } diff --git a/pkg/repo/local.go b/pkg/repo/local.go index 928da026e..1844e2f44 100644 --- a/pkg/repo/local.go +++ b/pkg/repo/local.go @@ -13,12 +13,12 @@ import ( var localRepoPath string -// CacheFile represents the cache file in a chart repository -type CacheFile struct { +// IndexFile represents the index file in a chart repository +type IndexFile struct { Entries map[string]*ChartRef } -// ChartRef represents a chart entry in the CacheFile +// ChartRef represents a chart entry in the IndexFile type ChartRef struct { Name string `yaml:"name"` URL string `yaml:"url"` @@ -43,8 +43,8 @@ func indexHandler(w http.ResponseWriter, r *http.Request) { serveFile(w, r, file) } else if file == "" { fmt.Fprintf(w, "list of charts should be here at some point") - } else if file == "cache" { - fmt.Fprintf(w, "cache file data should be here at some point") + } else if file == "index" { + fmt.Fprintf(w, "index file data should be here at some point") } else { fmt.Fprintf(w, "Ummm... Nothing to see here folks") } @@ -54,13 +54,13 @@ func serveFile(w http.ResponseWriter, r *http.Request, file string) { http.ServeFile(w, r, filepath.Join(localRepoPath, file)) } -// AddChartToLocalRepo saves a chart in the given path and then reindexes the cache file +// AddChartToLocalRepo saves a chart in the given path and then reindexes the index file func AddChartToLocalRepo(ch *chart.Chart, path string) error { name, err := chart.Save(ch, path) if err != nil { return err } - err = ReindexCacheFile(ch, path+"/cache.yaml") + err = Reindex(ch, path+"/index.yaml") if err != nil { return err } @@ -68,15 +68,15 @@ func AddChartToLocalRepo(ch *chart.Chart, path string) error { return nil } -// LoadCacheFile takes a file at the given path and returns a CacheFile object -func LoadCacheFile(path string) (*CacheFile, error) { +// LoadIndexFile takes a file at the given path and returns an IndexFile object +func LoadIndexFile(path string) (*IndexFile, error) { b, err := ioutil.ReadFile(path) if err != nil { return nil, err } //TODO: change variable name - y is not helpful :P - var y CacheFile + var y IndexFile err = yaml.Unmarshal(b, &y) if err != nil { return nil, err @@ -84,10 +84,10 @@ func LoadCacheFile(path string) (*CacheFile, error) { return &y, nil } -// ReindexCacheFile adds an entry to the cache file at the given path -func ReindexCacheFile(ch *chart.Chart, path string) error { +// Reindex adds an entry to the index file at the given path +func Reindex(ch *chart.Chart, path string) error { name := ch.Chartfile().Name + "-" + ch.Chartfile().Version - y, err := LoadCacheFile(path) + y, err := LoadIndexFile(path) if err != nil { return err } @@ -111,25 +111,25 @@ func ReindexCacheFile(ch *chart.Chart, path string) error { return nil } -// UnmarshalYAML unmarshals the cache file -func (c *CacheFile) UnmarshalYAML(unmarshal func(interface{}) error) error { +// UnmarshalYAML unmarshals the index file +func (i *IndexFile) UnmarshalYAML(unmarshal func(interface{}) error) error { var refs map[string]*ChartRef if err := unmarshal(&refs); err != nil { if _, ok := err.(*yaml.TypeError); !ok { return err } } - c.Entries = refs + i.Entries = refs return nil } -func (c *CacheFile) insertChartEntry(name string, url string) ([]byte, error) { - if c.Entries == nil { - c.Entries = make(map[string]*ChartRef) +func (i *IndexFile) insertChartEntry(name string, url string) ([]byte, error) { + if i.Entries == nil { + i.Entries = make(map[string]*ChartRef) } entry := ChartRef{Name: name, URL: url} - c.Entries[name] = &entry - out, err := yaml.Marshal(&c.Entries) + i.Entries[name] = &entry + out, err := yaml.Marshal(&i.Entries) if err != nil { return nil, err } diff --git a/pkg/repo/local_test.go b/pkg/repo/local_test.go index 7649d4488..ac83f5cd4 100644 --- a/pkg/repo/local_test.go +++ b/pkg/repo/local_test.go @@ -4,15 +4,15 @@ import ( "testing" ) -const testfile = "testdata/local-cache.yaml" +const testfile = "testdata/local-index.yaml" -func TestLoadCacheFile(t *testing.T) { - cf, err := LoadCacheFile(testfile) +func TestLoadIndexFile(t *testing.T) { + cf, err := LoadIndexFile(testfile) if err != nil { - t.Errorf("Failed to load cachefile: %s", err) + t.Errorf("Failed to load index file: %s", err) } if len(cf.Entries) != 2 { - t.Errorf("Expected 2 entries in the cache file, but got %d", len(cf.Entries)) + t.Errorf("Expected 2 entries in the index file, but got %d", len(cf.Entries)) } nginx := false alpine := false diff --git a/pkg/repo/testdata/local-cache.yaml b/pkg/repo/testdata/local-index.yaml similarity index 100% rename from pkg/repo/testdata/local-cache.yaml rename to pkg/repo/testdata/local-index.yaml