ref(helm): rename cache file to index file

* also change additional references to cache to index
* see issue #665
pull/685/head
Michelle Noorali 9 years ago
parent 613ce7e1a9
commit 9b732da719

@ -100,18 +100,18 @@ func ensureHome() error {
return fmt.Errorf("%s must be a file, not a directory", repoFile) return fmt.Errorf("%s must be a file, not a directory", repoFile)
} }
localRepoCacheFile := localRepoDirectory(localRepoCacheFilePath) localRepoIndexFile := localRepoDirectory(localRepoIndexFilePath)
if fi, err := os.Stat(localRepoCacheFile); err != nil { if fi, err := os.Stat(localRepoIndexFile); err != nil {
fmt.Printf("Creating %s \n", localRepoCacheFile) fmt.Printf("Creating %s \n", localRepoIndexFile)
_, err := os.Create(localRepoCacheFile) _, err := os.Create(localRepoIndexFile)
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(localRepoCacheFile, cacheDirectory("local-cache.yaml")) os.Symlink(localRepoIndexFile, cacheDirectory("local-index.yaml"))
} else if fi.IsDir() { } 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) fmt.Printf("$HELM_HOME has been configured at %s.\n", helmHome)

@ -28,7 +28,7 @@ func TestEnsureHome(t *testing.T) {
t.Errorf("%s should not be a directory", fi) 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) 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)

@ -47,7 +47,7 @@ func runRepoAdd(cmd *cobra.Command, args []string) error {
} }
name, url := args[0], args[1] 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") return errors.New("Oops! Looks like " + url + " is not a valid chart repository or cannot be reached\n")
} }

@ -64,9 +64,9 @@ func searchCacheForPattern(dir string, search string) ([]string, error) {
}) })
matches := []string{} matches := []string{}
for _, f := range fileList { for _, f := range fileList {
cache, _ := repo.LoadCacheFile(f) index, _ := repo.LoadIndexFile(f)
m := searchChartRefsForPattern(search, cache.Entries) m := searchChartRefsForPattern(search, index.Entries)
repoName := strings.TrimSuffix(filepath.Base(f), "-cache.yaml") repoName := strings.TrimSuffix(filepath.Base(f), "-index.yaml")
for _, c := range m { for _, c := range m {
matches = append(matches, repoName+"/"+c) matches = append(matches, repoName+"/"+c)
} }

@ -7,7 +7,7 @@ import (
) )
const testDir = "testdata/" const testDir = "testdata/"
const testFile = "testdata/local-cache.yaml" const testFile = "testdata/local-index.yaml"
type searchTestCase struct { type searchTestCase struct {
in string in string
@ -49,9 +49,9 @@ func validateEntries(t *testing.T, in string, found []string, expected []string)
} }
func searchTestRunner(t *testing.T, tc searchTestCase) { func searchTestRunner(t *testing.T, tc searchTestCase) {
cf, err := repo.LoadCacheFile(testFile) cf, err := repo.LoadIndexFile(testFile)
if err != nil { 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) u := searchChartRefsForPattern(tc.in, cf.Entries)

@ -9,7 +9,7 @@ const (
repositoriesFilePath string = "repositories.yaml" repositoriesFilePath string = "repositories.yaml"
cachePath string = "cache" cachePath string = "cache"
localRepoPath string = "local" localRepoPath string = "local"
localRepoCacheFilePath string = "cache.yaml" localRepoIndexFilePath string = "index.yaml"
) )
func homePath() string { func homePath() string {

@ -46,7 +46,7 @@ func updateCharts(repos map[string]string, verbose bool) {
wg.Add(1) wg.Add(1)
go func(n, u string) { go func(n, u string) {
defer wg.Done() defer wg.Done()
err := downloadCacheFile(n, u) err := downloadIndexFile(n, u)
if err != nil { if err != nil {
updateErr := "...Unable to get an update from the " + n + " chart repository" updateErr := "...Unable to get an update from the " + n + " chart repository"
if verbose { if verbose {
@ -62,17 +62,17 @@ func updateCharts(repos map[string]string, verbose bool) {
fmt.Println("Update Complete. Happy Helming!") fmt.Println("Update Complete. Happy Helming!")
} }
func downloadCacheFile(name, url string) error { func downloadIndexFile(name, url string) error {
var cacheURL string var indexURL string
cacheURL = strings.TrimSuffix(url, "/") + "/cache.yaml" indexURL = strings.TrimSuffix(url, "/") + "/index.yaml"
resp, err := http.Get(cacheURL) resp, err := http.Get(indexURL)
if err != nil { if err != nil {
return err return err
} }
defer resp.Body.Close() defer resp.Body.Close()
var cacheFile *os.File var indexFile *os.File
var r repo.RepoFile var r repo.RepoFile
b, err := ioutil.ReadAll(resp.Body) b, err := ioutil.ReadAll(resp.Body)
@ -84,12 +84,12 @@ func downloadCacheFile(name, url string) error {
return err return err
} }
cacheFile, err = os.Create(cacheDirectory(name + "-cache.yaml")) indexFile, err = os.Create(cacheDirectory(name + "-index.yaml"))
if err != nil { if err != nil {
return err return err
} }
if _, err := io.Copy(cacheFile, resp.Body); err != nil { if _, err := io.Copy(indexFile, resp.Body); err != nil {
return err return err
} }

@ -13,12 +13,12 @@ import (
var localRepoPath string var localRepoPath string
// CacheFile represents the cache file in a chart repository // IndexFile represents the index file in a chart repository
type CacheFile struct { type IndexFile struct {
Entries map[string]*ChartRef Entries map[string]*ChartRef
} }
// ChartRef represents a chart entry in the CacheFile // ChartRef represents a chart entry in the IndexFile
type ChartRef struct { type ChartRef struct {
Name string `yaml:"name"` Name string `yaml:"name"`
URL string `yaml:"url"` URL string `yaml:"url"`
@ -43,8 +43,8 @@ func indexHandler(w http.ResponseWriter, r *http.Request) {
serveFile(w, r, file) serveFile(w, r, file)
} else if file == "" { } else if file == "" {
fmt.Fprintf(w, "list of charts should be here at some point") fmt.Fprintf(w, "list of charts should be here at some point")
} else if file == "cache" { } else if file == "index" {
fmt.Fprintf(w, "cache file data should be here at some point") fmt.Fprintf(w, "index file data should be here at some point")
} else { } else {
fmt.Fprintf(w, "Ummm... Nothing to see here folks") 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)) 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 { func AddChartToLocalRepo(ch *chart.Chart, path string) error {
name, err := chart.Save(ch, path) name, err := chart.Save(ch, path)
if err != nil { if err != nil {
return err return err
} }
err = ReindexCacheFile(ch, path+"/cache.yaml") err = Reindex(ch, path+"/index.yaml")
if err != nil { if err != nil {
return err return err
} }
@ -68,15 +68,15 @@ func AddChartToLocalRepo(ch *chart.Chart, path string) error {
return nil return nil
} }
// LoadCacheFile takes a file at the given path and returns a CacheFile object // LoadIndexFile takes a file at the given path and returns an IndexFile object
func LoadCacheFile(path string) (*CacheFile, error) { func LoadIndexFile(path string) (*IndexFile, error) {
b, err := ioutil.ReadFile(path) b, err := ioutil.ReadFile(path)
if err != nil { if err != nil {
return nil, err return nil, err
} }
//TODO: change variable name - y is not helpful :P //TODO: change variable name - y is not helpful :P
var y CacheFile var y IndexFile
err = yaml.Unmarshal(b, &y) err = yaml.Unmarshal(b, &y)
if err != nil { if err != nil {
return nil, err return nil, err
@ -84,10 +84,10 @@ func LoadCacheFile(path string) (*CacheFile, error) {
return &y, nil return &y, nil
} }
// ReindexCacheFile adds an entry to the cache file at the given path // Reindex adds an entry to the index file at the given path
func ReindexCacheFile(ch *chart.Chart, path string) error { func Reindex(ch *chart.Chart, path string) error {
name := ch.Chartfile().Name + "-" + ch.Chartfile().Version name := ch.Chartfile().Name + "-" + ch.Chartfile().Version
y, err := LoadCacheFile(path) y, err := LoadIndexFile(path)
if err != nil { if err != nil {
return err return err
} }
@ -111,25 +111,25 @@ func ReindexCacheFile(ch *chart.Chart, path string) error {
return nil return nil
} }
// UnmarshalYAML unmarshals the cache file // UnmarshalYAML unmarshals the index file
func (c *CacheFile) UnmarshalYAML(unmarshal func(interface{}) error) error { func (i *IndexFile) UnmarshalYAML(unmarshal func(interface{}) error) error {
var refs map[string]*ChartRef var refs map[string]*ChartRef
if err := unmarshal(&refs); err != nil { if err := unmarshal(&refs); err != nil {
if _, ok := err.(*yaml.TypeError); !ok { if _, ok := err.(*yaml.TypeError); !ok {
return err return err
} }
} }
c.Entries = refs i.Entries = refs
return nil return nil
} }
func (c *CacheFile) insertChartEntry(name string, url string) ([]byte, error) { func (i *IndexFile) insertChartEntry(name string, url string) ([]byte, error) {
if c.Entries == nil { if i.Entries == nil {
c.Entries = make(map[string]*ChartRef) i.Entries = make(map[string]*ChartRef)
} }
entry := ChartRef{Name: name, URL: url} entry := ChartRef{Name: name, URL: url}
c.Entries[name] = &entry i.Entries[name] = &entry
out, err := yaml.Marshal(&c.Entries) out, err := yaml.Marshal(&i.Entries)
if err != nil { if err != nil {
return nil, err return nil, err
} }

@ -4,15 +4,15 @@ import (
"testing" "testing"
) )
const testfile = "testdata/local-cache.yaml" const testfile = "testdata/local-index.yaml"
func TestLoadCacheFile(t *testing.T) { func TestLoadIndexFile(t *testing.T) {
cf, err := LoadCacheFile(testfile) cf, err := LoadIndexFile(testfile)
if err != nil { 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 { 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 nginx := false
alpine := false alpine := false

Loading…
Cancel
Save