Skip to content

Commit

Permalink
internal/helm: del deprecated ChartRepo#Revision
Browse files Browse the repository at this point in the history
Signed-off-by: Hidde Beydals <[email protected]>
  • Loading branch information
hiddeco committed Feb 22, 2023
1 parent 76c4bb7 commit c712fed
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 78 deletions.
2 changes: 1 addition & 1 deletion controllers/helmrepository_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -775,7 +775,7 @@ func TestHelmRepositoryReconciler_reconcileSource(t *testing.T) {
checksum = newChartRepo.Digest(intdigest.Canonical)

g.Expect(newChartRepo.LoadFromPath()).To(Succeed())
revision = newChartRepo.Revision(intdigest.Canonical)
revision = newChartRepo.Digest(intdigest.Canonical)
}
if tt.beforeFunc != nil {
tt.beforeFunc(g, obj, revision, checksum)
Expand Down
34 changes: 5 additions & 29 deletions internal/helm/repository/chart_repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,8 @@ type ChartRepository struct {

tlsConfig *tls.Config

cached bool
revisions map[digest.Algorithm]digest.Digest
digests map[digest.Algorithm]digest.Digest
cached bool
digests map[digest.Algorithm]digest.Digest

*sync.RWMutex
}
Expand Down Expand Up @@ -155,9 +154,8 @@ func NewChartRepository(URL, path string, providers getter.Providers, tlsConfig

func newChartRepository() *ChartRepository {
return &ChartRepository{
revisions: make(map[digest.Algorithm]digest.Digest, 0),
digests: make(map[digest.Algorithm]digest.Digest, 0),
RWMutex: &sync.RWMutex{},
digests: make(map[digest.Algorithm]digest.Digest, 0),
RWMutex: &sync.RWMutex{},
}
}

Expand Down Expand Up @@ -351,7 +349,6 @@ func (r *ChartRepository) LoadFromPath() error {
}

r.Index = i
r.revisions = make(map[digest.Algorithm]digest.Digest, 0)
return nil
}

Expand Down Expand Up @@ -384,26 +381,6 @@ func (r *ChartRepository) DownloadIndex(w io.Writer) (err error) {
return nil
}

// Revision returns the revision of the ChartRepository's Index. It assumes
// the Index is stable sorted.
// Deprecated: because of expensive memory usage of (YAML) marshal operations.
// We only use Digest now.
func (r *ChartRepository) Revision(algorithm digest.Algorithm) digest.Digest {
if !r.HasIndex() {
return ""
}

r.Lock()
defer r.Unlock()

if _, ok := r.revisions[algorithm]; !ok {
if b, _ := yaml.Marshal(r.Index); len(b) > 0 {
r.revisions[algorithm] = algorithm.FromBytes(b)
}
}
return r.revisions[algorithm]
}

// Digest returns the digest of the file at the ChartRepository's Path.
func (r *ChartRepository) Digest(algorithm digest.Algorithm) digest.Digest {
if !r.HasFile() {
Expand Down Expand Up @@ -465,7 +442,7 @@ func (r *ChartRepository) Clear() error {
return nil
}

// Invalidate clears any cached digests and revisions.
// Invalidate clears any cached digests.
func (r *ChartRepository) Invalidate() {
r.Lock()
defer r.Unlock()
Expand All @@ -475,7 +452,6 @@ func (r *ChartRepository) Invalidate() {

func (r *ChartRepository) invalidate() {
r.digests = make(map[digest.Algorithm]digest.Digest, 0)
r.revisions = make(map[digest.Algorithm]digest.Digest, 0)
}

// VerifyChart verifies the chart against a signature.
Expand Down
48 changes: 0 additions & 48 deletions internal/helm/repository/chart_repository_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,6 @@ func TestChartRepository_CacheIndex(t *testing.T) {
r := newChartRepository()
r.URL = "https://example.com"
r.Client = &mg
r.revisions["key"] = "value"
r.digests["key"] = "value"

err := r.CacheIndex()
Expand All @@ -405,7 +404,6 @@ func TestChartRepository_CacheIndex(t *testing.T) {
b, _ := os.ReadFile(r.Path)
g.Expect(b).To(Equal(mg.Response))

g.Expect(r.revisions).To(BeEmpty())
g.Expect(r.digests).To(BeEmpty())
}

Expand Down Expand Up @@ -480,11 +478,9 @@ func TestChartRepository_LoadFromPath(t *testing.T) {

r := newChartRepository()
r.Path = i
r.revisions["key"] = "value"

g.Expect(r.LoadFromPath()).To(Succeed())
g.Expect(r.Index).ToNot(BeNil())
g.Expect(r.revisions).To(BeEmpty())
})

t.Run("no cache path", func(t *testing.T) {
Expand All @@ -507,44 +503,6 @@ func TestChartRepository_LoadFromPath(t *testing.T) {
})
}

func TestChartRepository_Revision(t *testing.T) {
t.Run("with algorithm", func(t *testing.T) {
r := newChartRepository()
r.Index = repo.NewIndexFile()

for _, algo := range []digest.Algorithm{digest.SHA256, digest.SHA512} {
t.Run(algo.String(), func(t *testing.T) {
g := NewWithT(t)

d := r.Revision(algo)
g.Expect(d).ToNot(BeEmpty())
g.Expect(d.Algorithm()).To(Equal(algo))
g.Expect(r.revisions[algo]).To(Equal(d))
})
}
})

t.Run("without index", func(t *testing.T) {
g := NewWithT(t)

r := newChartRepository()
g.Expect(r.Revision(digest.SHA256)).To(BeEmpty())
})

t.Run("from cache", func(t *testing.T) {
g := NewWithT(t)

algo := digest.SHA256
expect := digest.Digest("sha256:fake")

r := newChartRepository()
r.Index = repo.NewIndexFile()
r.revisions[algo] = expect

g.Expect(r.Revision(algo)).To(Equal(expect))
})
}

func TestChartRepository_Digest(t *testing.T) {
t.Run("with algorithm", func(t *testing.T) {
g := NewWithT(t)
Expand Down Expand Up @@ -625,11 +583,9 @@ func TestChartRepository_Clear(t *testing.T) {

r := newChartRepository()
r.Index = repo.NewIndexFile()
r.revisions["key"] = "value"

g.Expect(r.Clear()).To(Succeed())
g.Expect(r.Index).To(BeNil())
g.Expect(r.revisions).To(BeEmpty())
})

t.Run("with index and cached path", func(t *testing.T) {
Expand All @@ -643,14 +599,12 @@ func TestChartRepository_Clear(t *testing.T) {
r.Path = f.Name()
r.Index = repo.NewIndexFile()
r.digests["key"] = "value"
r.revisions["key"] = "value"
r.cached = true

g.Expect(r.Clear()).To(Succeed())
g.Expect(r.Index).To(BeNil())
g.Expect(r.Path).To(BeEmpty())
g.Expect(r.digests).To(BeEmpty())
g.Expect(r.revisions).To(BeEmpty())
g.Expect(r.cached).To(BeFalse())
})

Expand All @@ -677,11 +631,9 @@ func TestChartRepository_Invalidate(t *testing.T) {

r := newChartRepository()
r.digests["key"] = "value"
r.revisions["key"] = "value"

r.Invalidate()
g.Expect(r.digests).To(BeEmpty())
g.Expect(r.revisions).To(BeEmpty())
}

func verifyLocalIndex(t *testing.T, i *repo.IndexFile) {
Expand Down

0 comments on commit c712fed

Please sign in to comment.