Skip to content

Commit 2c6ac18

Browse files
committed
fix: allow recursive dry-run over local sources
Signed-off-by: niveau0 <[email protected]>
1 parent 9127181 commit 2c6ac18

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

cmd/flux/build_kustomization_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,12 @@ spec:
169169
resultFile: "./testdata/build-kustomization/podinfo-with-my-app-result.yaml",
170170
assertFunc: "assertGoldenTemplateFile",
171171
},
172+
{
173+
name: "build with recursive in dry-run mode",
174+
args: "build kustomization podinfo --kustomization-file " + tmpFile + " --path ./testdata/build-kustomization/podinfo-with-my-app --recursive --local-sources GitRepository/default/podinfo=./testdata/build-kustomization --dry-run",
175+
resultFile: "./testdata/build-kustomization/podinfo-with-my-app-result.yaml",
176+
assertFunc: "assertGoldenTemplateFile",
177+
},
172178
}
173179

174180
tmpl := map[string]string{

internal/build/build.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ func NewBuilder(name, resources string, opts ...BuilderOptionFunc) (*Builder, er
258258
b.timeout = defaultTimeout
259259
}
260260

261-
if b.dryRun && b.kustomizationFile == "" {
261+
if b.dryRun && b.kustomizationFile == "" && b.kustomization == nil {
262262
return nil, fmt.Errorf("kustomization file is required for dry-run")
263263
}
264264

@@ -355,7 +355,9 @@ func (b *Builder) build() (m resmap.ResMap, err error) {
355355

356356
// Get the kustomization object
357357
liveKus := &kustomizev1.Kustomization{}
358-
if !b.dryRun {
358+
if b.dryRun {
359+
liveKus = b.kustomization
360+
} else {
359361
liveKus, err = b.getKustomization(ctx)
360362
if err != nil {
361363
if !apierrors.IsNotFound(err) || b.kustomization == nil {
@@ -365,6 +367,7 @@ func (b *Builder) build() (m resmap.ResMap, err error) {
365367
liveKus = b.kustomization
366368
}
367369
}
370+
368371
k, err := b.resolveKustomization(liveKus)
369372
if err != nil {
370373
err = fmt.Errorf("failed to get kustomization object: %w", err)
@@ -432,6 +435,7 @@ func (b *Builder) kustomizationBuild(k *kustomizev1.Kustomization) ([]*unstructu
432435
WithStrictSubstitute(b.strictSubst),
433436
WithRecursive(b.recursive),
434437
WithLocalSources(b.localSources),
438+
WithDryRun(b.dryRun),
435439
)
436440
if err != nil {
437441
return nil, err

0 commit comments

Comments
 (0)