@@ -28,14 +28,14 @@ type ChartInfo struct {
28
28
}
29
29
type HelmUpdater struct {
30
30
registryHelper * RegistryHelper
31
- config * HelmUpdateConfig
31
+ config * HelmUpdateConfig
32
32
}
33
33
34
34
type HelmUpdateConfig struct {
35
- SkipRepoOverwrite bool // ENV: HELM_DEPS_SKIP_REPO_OVERWRITE
36
- SkipDepdencyRefresh bool // ENV: HELM_DEPS_SKIP_REFRESH
35
+ SkipRepoOverwrite bool // ENV: HELM_DEPS_SKIP_REPO_OVERWRITE
36
+ SkipDepdencyRefresh bool // ENV: HELM_DEPS_SKIP_REFRESH
37
37
FetchArgocdRepoSecrets bool // ENV: HELM_DEPS_FETCH_ARGOCD_REPO_SECRETS
38
- UseRandomHelmCacheDir bool // ENV: HELM_DEPS_RANDOM_CACHE_DIR
38
+ UseRandomHelmCacheDir bool // ENV: HELM_DEPS_RANDOM_CACHE_DIR
39
39
}
40
40
41
41
func (c * ChartInfo ) AddDependencyUrl (depdencyUrl string ) error {
@@ -80,10 +80,16 @@ func (updater *HelmUpdater) UpdateChart(chartPath string) error {
80
80
}
81
81
}
82
82
// update helm repo after adding all registries
83
- err := runHelmCommand ( "repo" , "update" )
83
+ _ , reposAvailable , err := helmRepoExists ( & RegistryInfo { Hostname : "" }, updater . config )
84
84
if err != nil {
85
85
return err
86
86
}
87
+ if reposAvailable {
88
+ err := runHelmCommand ("repo" , "update" )
89
+ if err != nil {
90
+ return err
91
+ }
92
+ }
87
93
}
88
94
return updater .updateDependencies (chartInfo )
89
95
}
@@ -177,30 +183,30 @@ func runHelmCommand(args ...string) error {
177
183
}
178
184
179
185
// helmRepoExists checks if a helm repository already exists with helm repo ls command
180
- func helmRepoExists (registry * RegistryInfo , config * HelmUpdateConfig ) (bool , error ) {
186
+ func helmRepoExists (registry * RegistryInfo , config * HelmUpdateConfig ) (bool , bool , error ) {
181
187
if ! config .SkipRepoOverwrite {
182
- return false , nil
188
+ return false , false , nil
183
189
}
184
190
cmd := exec .Command ("helm" , "repo" , "ls" )
185
191
var out bytes.Buffer
186
192
cmd .Stdout = & out
187
193
cmd .Stderr = & out
188
194
err := cmd .Run ()
189
- if err != nil {
190
- // Check if the error is due to no repositories existing
191
- if strings .Contains (out .String (), "no repositories to show" ) {
192
- return false , nil
193
- }
194
- return false , fmt .Errorf ("failed to run helm repo ls: %w" , err )
195
- }
196
- output := out .String ()
197
- lines := strings .Split (output , "\n " )
198
- for _ , line := range lines {
199
- if strings .Contains (line , registry .Hostname ) {
200
- return true , nil
201
- }
202
- }
203
- return false , nil
195
+ if err != nil {
196
+ // Check if the error is due to no repositories existing
197
+ if strings .Contains (out .String (), "no repositories to show" ) {
198
+ return false , false , nil
199
+ }
200
+ return false , false , fmt .Errorf ("failed to run helm repo ls: %w" , err )
201
+ }
202
+ output := out .String ()
203
+ lines := strings .Split (output , "\n " )
204
+ for _ , line := range lines {
205
+ if strings .Contains (line , registry .Hostname ) {
206
+ return true , true , nil
207
+ }
208
+ }
209
+ return false , true , nil
204
210
}
205
211
206
212
func (updater * HelmUpdater ) helmDepUpdate (chartPath string ) error {
0 commit comments