refactor: Remove ChartRepository Load() function

Signed-off-by: George Jenkins <gvjenkins@gmail.com>
pull/13578/head
George Jenkins 9 months ago
parent 3a94215585
commit 17bc0b3845

@ -79,40 +79,6 @@ func NewChartRepository(cfg *Entry, getters getter.Providers) (*ChartRepository,
}, nil }, nil
} }
// Load loads a directory of charts as if it were a repository.
//
// It requires the presence of an index.yaml file in the directory.
//
// Deprecated: remove in Helm 4.
func (r *ChartRepository) Load() error {
dirInfo, err := os.Stat(r.Config.Name)
if err != nil {
return err
}
if !dirInfo.IsDir() {
return errors.Errorf("%q is not a directory", r.Config.Name)
}
// FIXME: Why are we recursively walking directories?
// FIXME: Why are we not reading the repositories.yaml to figure out
// what repos to use?
filepath.Walk(r.Config.Name, func(path string, f os.FileInfo, _ error) error {
if !f.IsDir() {
if strings.Contains(f.Name(), "-index.yaml") {
i, err := LoadIndexFile(path)
if err != nil {
return err
}
r.IndexFile = i
} else if strings.HasSuffix(f.Name(), ".tgz") {
r.ChartPaths = append(r.ChartPaths, path)
}
}
return nil
})
return nil
}
// DownloadIndexFile fetches the index from a repository. // DownloadIndexFile fetches the index from a repository.
func (r *ChartRepository) DownloadIndexFile() (string, error) { func (r *ChartRepository) DownloadIndexFile() (string, error) {
indexURL, err := ResolveReferenceURL(r.Config.URL, "index.yaml") indexURL, err := ResolveReferenceURL(r.Config.URL, "index.yaml")

@ -22,12 +22,12 @@ import (
"net/http/httptest" "net/http/httptest"
"os" "os"
"path/filepath" "path/filepath"
"reflect"
"runtime" "runtime"
"strings" "strings"
"testing" "testing"
"time" "time"
"github.com/stretchr/testify/require"
"sigs.k8s.io/yaml" "sigs.k8s.io/yaml"
"helm.sh/helm/v4/pkg/chart" "helm.sh/helm/v4/pkg/chart"
@ -40,37 +40,22 @@ const (
testURL = "http://example-charts.com" testURL = "http://example-charts.com"
) )
func TestLoadChartRepository(t *testing.T) { // loadFromDir a directory of charts archives (including sub-directories),
r, err := NewChartRepository(&Entry{ // appending to the repositores ChartPath
Name: testRepository, func loadFromDir(t *testing.T, r *ChartRepository, dir string) {
URL: testURL, dirInfo, err := os.Stat(dir)
}, getter.All(&cli.EnvSettings{})) require.Nil(t, err)
if err != nil { require.True(t, dirInfo.IsDir())
t.Errorf("Problem creating chart repository from %s: %v", testRepository, err)
}
if err := r.Load(); err != nil { globArchives := func(pattern string) []string {
t.Errorf("Problem loading chart repository from %s: %v", testRepository, err) archives, err := filepath.Glob(filepath.Join(dir, pattern))
} require.Nil(t, err)
paths := []string{
filepath.Join(testRepository, "frobnitz-1.2.3.tgz"),
filepath.Join(testRepository, "sprocket-1.1.0.tgz"),
filepath.Join(testRepository, "sprocket-1.2.0.tgz"),
filepath.Join(testRepository, "universe/zarthal-1.0.0.tgz"),
}
if r.Config.Name != testRepository { return archives
t.Errorf("Expected %s as Name but got %s", testRepository, r.Config.Name)
} }
if !reflect.DeepEqual(r.ChartPaths, paths) { r.ChartPaths = append(r.ChartPaths, globArchives("*.tgz")...)
t.Errorf("Expected %#v but got %#v\n", paths, r.ChartPaths) r.ChartPaths = append(r.ChartPaths, globArchives("**/*.tgz")...)
}
if r.Config.URL != testURL {
t.Errorf("Expected url for chart repository to be %s but got %s", testURL, r.Config.URL)
}
} }
func TestIndex(t *testing.T) { func TestIndex(t *testing.T) {
@ -82,9 +67,7 @@ func TestIndex(t *testing.T) {
t.Errorf("Problem creating chart repository from %s: %v", testRepository, err) t.Errorf("Problem creating chart repository from %s: %v", testRepository, err)
} }
if err := r.Load(); err != nil { loadFromDir(t, r, testRepository)
t.Errorf("Problem loading chart repository from %s: %v", testRepository, err)
}
err = r.Index() err = r.Index()
if err != nil { if err != nil {

Loading…
Cancel
Save