From 1234b72f96acbc6a682e022c45b5f0ed25659d96 Mon Sep 17 00:00:00 2001 From: Allen Conlon Date: Wed, 30 Oct 2024 12:07:15 -0400 Subject: [PATCH] fix: issue where kustomization files are empty (#3094) Co-authored-by: Austin Abro <37223396+AustinAbro321@users.noreply.github.com> --- src/pkg/packager/prepare.go | 3 ++- src/pkg/packager/prepare_test.go | 14 ++++++++++++++ .../find-images/kustomize/deployment.yaml | 16 ++++++++++++++++ .../find-images/kustomize/kustomization.yaml | 5 +++++ .../testdata/find-images/kustomize/zarf.yaml | 12 ++++++++++++ 5 files changed, 49 insertions(+), 1 deletion(-) create mode 100644 src/pkg/packager/testdata/find-images/kustomize/deployment.yaml create mode 100644 src/pkg/packager/testdata/find-images/kustomize/kustomization.yaml create mode 100644 src/pkg/packager/testdata/find-images/kustomize/zarf.yaml diff --git a/src/pkg/packager/prepare.go b/src/pkg/packager/prepare.go index 1e43335898..9dd4f0edf0 100644 --- a/src/pkg/packager/prepare.go +++ b/src/pkg/packager/prepare.go @@ -209,7 +209,8 @@ func (p *Packager) findImages(ctx context.Context) (map[string][]string, error) for idx, k := range manifest.Kustomizations { // Generate manifests from kustomizations and place in the package kname := fmt.Sprintf("kustomization-%s-%d.yaml", manifest.Name, idx) - destination := filepath.Join(componentPaths.Manifests, kname) + // Use the temp folder because if "helpers.CreatePathAndCopy" is provider with the same path it will result in the file being empty + destination := filepath.Join(componentPaths.Temp, kname) if err := kustomize.Build(k, destination, manifest.KustomizeAllowAnyDirectory); err != nil { return nil, fmt.Errorf("unable to build the kustomization for %s: %w", k, err) } diff --git a/src/pkg/packager/prepare_test.go b/src/pkg/packager/prepare_test.go index f2fb760534..ea244d8a52 100644 --- a/src/pkg/packager/prepare_test.go +++ b/src/pkg/packager/prepare_test.go @@ -55,6 +55,20 @@ func TestFindImages(t *testing.T) { }, }, }, + { + name: "kustomization", + cfg: &types.PackagerConfig{ + CreateOpts: types.ZarfCreateOptions{ + BaseDir: "./testdata/find-images/kustomize", + }, + }, + expectedImages: map[string][]string{ + "baseline": { + "ghcr.io/zarf-dev/zarf/agent:v0.38.1", + "ghcr.io/zarf-dev/zarf/agent:sha256-f8b1c2f99349516ae1bd0711a19697abcc41555076b0ae90f1a70ca6b50dcbd8.sig", + }, + }, + }, { name: "image not found", cfg: &types.PackagerConfig{ diff --git a/src/pkg/packager/testdata/find-images/kustomize/deployment.yaml b/src/pkg/packager/testdata/find-images/kustomize/deployment.yaml new file mode 100644 index 0000000000..d307843973 --- /dev/null +++ b/src/pkg/packager/testdata/find-images/kustomize/deployment.yaml @@ -0,0 +1,16 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: agent +spec: + selector: + matchLabels: + app: agent + template: + metadata: + labels: + app: agent + spec: + containers: + - name: agent + image: ghcr.io/zarf-dev/zarf/agent:v0.38.1 diff --git a/src/pkg/packager/testdata/find-images/kustomize/kustomization.yaml b/src/pkg/packager/testdata/find-images/kustomize/kustomization.yaml new file mode 100644 index 0000000000..2492e870ce --- /dev/null +++ b/src/pkg/packager/testdata/find-images/kustomize/kustomization.yaml @@ -0,0 +1,5 @@ +--- +apiVersion: kustomize.config.k8s.io/v1beta1 +kind: Kustomization +resources: +- deployment.yaml diff --git a/src/pkg/packager/testdata/find-images/kustomize/zarf.yaml b/src/pkg/packager/testdata/find-images/kustomize/zarf.yaml new file mode 100644 index 0000000000..0d3fec188a --- /dev/null +++ b/src/pkg/packager/testdata/find-images/kustomize/zarf.yaml @@ -0,0 +1,12 @@ +kind: ZarfPackageConfig +metadata: + name: agent + version: 1.0.0 +components: + - name: baseline + required: true + manifests: + - name: agent + namespace: default + kustomizations: + - ./.