@@ -35,21 +35,29 @@ import (
35
35
"github.com/fluxcd/source-controller/internal/helm/repository"
36
36
)
37
37
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
39
47
// 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 )
41
49
42
50
// DependencyManager manages dependencies for a Helm chart.
43
51
type DependencyManager struct {
44
- // repositories contains a map of repository.ChartRepository objects
52
+ // downloaders contains a map of Downloader objects
45
53
// indexed by their repository.NormalizeURL.
46
54
// It is consulted as a lookup table for missing dependencies, based on
47
55
// the (repository) URL the dependency refers to.
48
- repositories map [string ]* repository. ChartRepository
56
+ downloaders map [string ]CleanDownloader
49
57
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
53
61
54
62
// concurrent is the number of concurrent chart-add operations during
55
63
// Build. Defaults to 1 (non-concurrent).
@@ -64,16 +72,16 @@ type DependencyManagerOption interface {
64
72
applyToDependencyManager (dm * DependencyManager )
65
73
}
66
74
67
- type WithRepositories map [string ]* repository. ChartRepository
75
+ type WithRepositories map [string ]CleanDownloader
68
76
69
77
func (o WithRepositories ) applyToDependencyManager (dm * DependencyManager ) {
70
- dm .repositories = o
78
+ dm .downloaders = o
71
79
}
72
80
73
- type WithRepositoryCallback GetChartRepositoryCallback
81
+ type WithDownloaderCallback GetChartDownloaderCallback
74
82
75
- func (o WithRepositoryCallback ) applyToDependencyManager (dm * DependencyManager ) {
76
- dm .getRepositoryCallback = GetChartRepositoryCallback (o )
83
+ func (o WithDownloaderCallback ) applyToDependencyManager (dm * DependencyManager ) {
84
+ dm .getChartDownloaderCallback = GetChartDownloaderCallback (o )
77
85
}
78
86
79
87
type WithConcurrent int64
@@ -92,18 +100,12 @@ func NewDependencyManager(opts ...DependencyManagerOption) *DependencyManager {
92
100
return dm
93
101
}
94
102
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.
97
105
func (dm * DependencyManager ) Clear () []error {
98
106
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 ()... )
107
109
}
108
110
return errs
109
111
}
@@ -236,10 +238,6 @@ func (dm *DependencyManager) addRemoteDependency(chart *chartWithLock, dep *helm
236
238
return err
237
239
}
238
240
239
- if err = repo .StrategicallyLoadIndex (); err != nil {
240
- return fmt .Errorf ("failed to load index for '%s': %w" , dep .Name , err )
241
- }
242
-
243
241
ver , err := repo .GetChartVersion (dep .Name , dep .Version )
244
242
if err != nil {
245
243
return err
@@ -259,27 +257,27 @@ func (dm *DependencyManager) addRemoteDependency(chart *chartWithLock, dep *helm
259
257
return nil
260
258
}
261
259
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 ) {
265
263
dm .mu .Lock ()
266
264
defer dm .mu .Unlock ()
267
265
268
266
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 {
271
269
err = fmt .Errorf ("no chart repository for URL '%s'" , nUrl )
272
270
return
273
271
}
274
- if dm .repositories == nil {
275
- dm .repositories = map [string ]* repository. ChartRepository {}
272
+ if dm .downloaders == nil {
273
+ dm .downloaders = map [string ]CleanDownloader {}
276
274
}
277
- if dm .repositories [nUrl ], err = dm .getRepositoryCallback (nUrl ); err != nil {
275
+ if dm .downloaders [nUrl ], err = dm .getChartDownloaderCallback (nUrl ); err != nil {
278
276
err = fmt .Errorf ("failed to get chart repository for URL '%s': %w" , nUrl , err )
279
277
return
280
278
}
281
279
}
282
- return dm .repositories [nUrl ], nil
280
+ return dm .downloaders [nUrl ], nil
283
281
}
284
282
285
283
// secureLocalChartPath returns the secure absolute path of a local dependency.
0 commit comments