Skip to content

Commit 47f7131

Browse files
committed
found another place we should ignore missing values, if necessary
1 parent 1fd4e89 commit 47f7131

File tree

2 files changed

+66
-5
lines changed

2 files changed

+66
-5
lines changed

pkg/argo_client/manifests.go

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,9 @@ func packageApp(ctx context.Context, source v1alpha1.ApplicationSource, refs []v
363363
src := filepath.Join(appPath, valueFile)
364364
dst := filepath.Join(tempAppDir, valueFile)
365365
if err = copyFile(src, dst); err != nil {
366-
return "", errors.Wrapf(err, "failed to copy file: %q", valueFile)
366+
if !ignoreValuesFileCopyError(source, valueFile, err) {
367+
return "", errors.Wrapf(err, "failed to copy file: %q", valueFile)
368+
}
367369
}
368370
}
369371
}
@@ -401,10 +403,7 @@ func processValueReference(
401403
src := filepath.Join(refRepo.Directory, refPath)
402404
dst := filepath.Join(tempDir, refPath)
403405
if err = copyFile(src, dst); err != nil {
404-
// handle source.spec.helm.ignoreMissingValues = true
405-
if errors.Is(err, os.ErrNotExist) && source.Helm.IgnoreMissingValueFiles {
406-
log.Debug().Str("valueFile", valueFile).Msg("ignore missing values file, because source.Helm.IgnoreMissingValueFiles is true")
407-
} else {
406+
if !ignoreValuesFileCopyError(source, valueFile, err) {
408407
return "", errors.Wrapf(err, "failed to copy referenced value file: %q", valueFile)
409408
}
410409
}
@@ -416,6 +415,15 @@ func processValueReference(
416415
return relPath, nil
417416
}
418417

418+
func ignoreValuesFileCopyError(source v1alpha1.ApplicationSource, valueFile string, err error) bool {
419+
if errors.Is(err, os.ErrNotExist) && source.Helm.IgnoreMissingValueFiles {
420+
log.Debug().Str("valueFile", valueFile).Msg("ignore missing values file, because source.Helm.IgnoreMissingValueFiles is true")
421+
return true
422+
}
423+
424+
return false
425+
}
426+
419427
var valueRef = regexp.MustCompile(`^\$([^/]+)/(.*)$`)
420428
var ErrInvalidSourceRef = errors.New("invalid value ref")
421429

pkg/argo_client/manifests_test.go

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,59 @@ func TestPackageApp(t *testing.T) {
205205
),
206206
},
207207

208+
"missing-values-can-be-accpetable": {
209+
pullRequest: vcs.PullRequest{
210+
CloneURL: "git@github.com:testuser/testrepo.git",
211+
BaseRef: "main",
212+
HeadRef: "update-code",
213+
},
214+
215+
app: v1alpha1.Application{
216+
Spec: v1alpha1.ApplicationSpec{
217+
Sources: []v1alpha1.ApplicationSource{
218+
{
219+
RepoURL: "git@github.com:testuser/testrepo.git",
220+
Path: "app1/",
221+
TargetRevision: "main",
222+
Helm: &v1alpha1.ApplicationSourceHelm{
223+
IgnoreMissingValueFiles: true,
224+
ValueFiles: []string{
225+
"./values.yaml",
226+
"missing.yaml",
227+
"$staging/base.yaml",
228+
"$staging/missing.yaml",
229+
},
230+
},
231+
},
232+
{
233+
Ref: "staging",
234+
RepoURL: "git@github.com:testuser/otherrepo.git",
235+
TargetRevision: "main",
236+
},
237+
},
238+
},
239+
},
240+
241+
filesByRepo: map[repoAndTarget][]string{
242+
repoAndTarget{"git@github.com:testuser/testrepo.git", "main"}: {
243+
"app1/Chart.yaml",
244+
"app1/values.yaml",
245+
"app2/Chart.yaml",
246+
"app2/values.yaml",
247+
},
248+
249+
repoAndTarget{"git@github.com:testuser/otherrepo.git", "main"}: {
250+
"base.yaml",
251+
},
252+
},
253+
254+
expectedFiles: newSet[string](
255+
"app1/Chart.yaml",
256+
"app1/values.yaml",
257+
"base.yaml",
258+
),
259+
},
260+
208261
"refs-are-copied": {
209262
pullRequest: vcs.PullRequest{
210263
CloneURL: "git@github.com:testuser/testrepo.git",

0 commit comments

Comments
 (0)