@@ -35,21 +35,29 @@ import (
3535 "github.com/fluxcd/source-controller/internal/helm/repository"
3636)
3737
38- // GetChartRepositoryCallback must return a repository.ChartRepository for the
38+ // CleanDownloader is a Downloader that cleans temporary files created by the downloader,
39+ // caching the files if the cache is configured,
40+ // and calling gc to remove unused files.
41+ type CleanDownloader interface {
42+ Clean () []error
43+ Downloader
44+ }
45+
46+ // GetChartDownloaderCallback must return a Downloader for the
3947// URL, or an error describing why it could not be returned.
40- type GetChartRepositoryCallback func (url string ) (* repository. ChartRepository , error )
48+ type GetChartDownloaderCallback func (url string ) (CleanDownloader , error )
4149
4250// DependencyManager manages dependencies for a Helm chart.
4351type DependencyManager struct {
44- // repositories contains a map of repository.ChartRepository objects
52+ // downloaders contains a map of Downloader objects
4553 // indexed by their repository.NormalizeURL.
4654 // It is consulted as a lookup table for missing dependencies, based on
4755 // the (repository) URL the dependency refers to.
48- repositories map [string ]* repository. ChartRepository
56+ downloaders map [string ]CleanDownloader
4957
50- // getRepositoryCallback can be set to an on-demand GetChartRepositoryCallback
51- // whose returned result is cached to repositories .
52- getRepositoryCallback GetChartRepositoryCallback
58+ // getChartDownloaderCallback can be set to an on-demand GetChartDownloaderCallback
59+ // whose returned result is cached to downloaders .
60+ getChartDownloaderCallback GetChartDownloaderCallback
5361
5462 // concurrent is the number of concurrent chart-add operations during
5563 // Build. Defaults to 1 (non-concurrent).
@@ -64,16 +72,16 @@ type DependencyManagerOption interface {
6472 applyToDependencyManager (dm * DependencyManager )
6573}
6674
67- type WithRepositories map [string ]* repository. ChartRepository
75+ type WithRepositories map [string ]CleanDownloader
6876
6977func (o WithRepositories ) applyToDependencyManager (dm * DependencyManager ) {
70- dm .repositories = o
78+ dm .downloaders = o
7179}
7280
73- type WithRepositoryCallback GetChartRepositoryCallback
81+ type WithDownloaderCallback GetChartDownloaderCallback
7482
75- func (o WithRepositoryCallback ) applyToDependencyManager (dm * DependencyManager ) {
76- dm .getRepositoryCallback = GetChartRepositoryCallback (o )
83+ func (o WithDownloaderCallback ) applyToDependencyManager (dm * DependencyManager ) {
84+ dm .getChartDownloaderCallback = GetChartDownloaderCallback (o )
7785}
7886
7987type WithConcurrent int64
@@ -92,18 +100,12 @@ func NewDependencyManager(opts ...DependencyManagerOption) *DependencyManager {
92100 return dm
93101}
94102
95- // Clear iterates over the repositories , calling Unload and RemoveCache on all
96- // items. It returns a collection of (cache removal) errors.
103+ // Clear iterates over the downloaders , calling Clean on all
104+ // items. It returns a collection of errors.
97105func (dm * DependencyManager ) Clear () []error {
98106 var errs []error
99- for _ , v := range dm .repositories {
100- if err := v .CacheIndexInMemory (); err != nil {
101- errs = append (errs , err )
102- }
103- v .Unload ()
104- if err := v .RemoveCache (); err != nil {
105- errs = append (errs , err )
106- }
107+ for _ , v := range dm .downloaders {
108+ errs = append (errs , v .Clean ()... )
107109 }
108110 return errs
109111}
@@ -236,10 +238,6 @@ func (dm *DependencyManager) addRemoteDependency(chart *chartWithLock, dep *helm
236238 return err
237239 }
238240
239- if err = repo .StrategicallyLoadIndex (); err != nil {
240- return fmt .Errorf ("failed to load index for '%s': %w" , dep .Name , err )
241- }
242-
243241 ver , err := repo .GetChartVersion (dep .Name , dep .Version )
244242 if err != nil {
245243 return err
@@ -259,27 +257,27 @@ func (dm *DependencyManager) addRemoteDependency(chart *chartWithLock, dep *helm
259257 return nil
260258}
261259
262- // resolveRepository first attempts to resolve the url from the repositories , falling back
263- // to getRepositoryCallback if set. It returns the resolved Index, or an error.
264- func (dm * DependencyManager ) resolveRepository (url string ) (_ * repository. ChartRepository , err error ) {
260+ // resolveRepository first attempts to resolve the url from the downloaders , falling back
261+ // to getDownloaderCallback if set. It returns the resolved Index, or an error.
262+ func (dm * DependencyManager ) resolveRepository (url string ) (_ Downloader , err error ) {
265263 dm .mu .Lock ()
266264 defer dm .mu .Unlock ()
267265
268266 nUrl := repository .NormalizeURL (url )
269- if _ , ok := dm .repositories [nUrl ]; ! ok {
270- if dm .getRepositoryCallback == nil {
267+ if _ , ok := dm .downloaders [nUrl ]; ! ok {
268+ if dm .getChartDownloaderCallback == nil {
271269 err = fmt .Errorf ("no chart repository for URL '%s'" , nUrl )
272270 return
273271 }
274- if dm .repositories == nil {
275- dm .repositories = map [string ]* repository. ChartRepository {}
272+ if dm .downloaders == nil {
273+ dm .downloaders = map [string ]CleanDownloader {}
276274 }
277- if dm .repositories [nUrl ], err = dm .getRepositoryCallback (nUrl ); err != nil {
275+ if dm .downloaders [nUrl ], err = dm .getChartDownloaderCallback (nUrl ); err != nil {
278276 err = fmt .Errorf ("failed to get chart repository for URL '%s': %w" , nUrl , err )
279277 return
280278 }
281279 }
282- return dm .repositories [nUrl ], nil
280+ return dm .downloaders [nUrl ], nil
283281}
284282
285283// secureLocalChartPath returns the secure absolute path of a local dependency.
0 commit comments