From 1b98e1694019605f767daa79da2ca6e9f28d9466 Mon Sep 17 00:00:00 2001 From: niveau0 Date: Wed, 26 Feb 2025 13:28:50 +0100 Subject: [PATCH] fix: allow recursive dry-run over local sources Signed-off-by: niveau0 --- cmd/flux/build_kustomization_test.go | 6 ++++++ internal/build/build.go | 8 ++++++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/cmd/flux/build_kustomization_test.go b/cmd/flux/build_kustomization_test.go index f5635977..2f8036bb 100644 --- a/cmd/flux/build_kustomization_test.go +++ b/cmd/flux/build_kustomization_test.go @@ -169,6 +169,12 @@ spec: resultFile: "./testdata/build-kustomization/podinfo-with-my-app-result.yaml", assertFunc: "assertGoldenTemplateFile", }, + { + name: "build with recursive in dry-run mode", + 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", + resultFile: "./testdata/build-kustomization/podinfo-with-my-app-result.yaml", + assertFunc: "assertGoldenTemplateFile", + }, } tmpl := map[string]string{ diff --git a/internal/build/build.go b/internal/build/build.go index 9e408193..aa041955 100644 --- a/internal/build/build.go +++ b/internal/build/build.go @@ -258,7 +258,7 @@ func NewBuilder(name, resources string, opts ...BuilderOptionFunc) (*Builder, er b.timeout = defaultTimeout } - if b.dryRun && b.kustomizationFile == "" { + if b.dryRun && b.kustomizationFile == "" && b.kustomization == nil { return nil, fmt.Errorf("kustomization file is required for dry-run") } @@ -355,7 +355,9 @@ func (b *Builder) build() (m resmap.ResMap, err error) { // Get the kustomization object liveKus := &kustomizev1.Kustomization{} - if !b.dryRun { + if b.dryRun { + liveKus = b.kustomization + } else { liveKus, err = b.getKustomization(ctx) if err != nil { if !apierrors.IsNotFound(err) || b.kustomization == nil { @@ -365,6 +367,7 @@ func (b *Builder) build() (m resmap.ResMap, err error) { liveKus = b.kustomization } } + k, err := b.resolveKustomization(liveKus) if err != nil { err = fmt.Errorf("failed to get kustomization object: %w", err) @@ -432,6 +435,7 @@ func (b *Builder) kustomizationBuild(k *kustomizev1.Kustomization) ([]*unstructu WithStrictSubstitute(b.strictSubst), WithRecursive(b.recursive), WithLocalSources(b.localSources), + WithDryRun(b.dryRun), ) if err != nil { return nil, err