Skip to content

Commit

Permalink
fix: issue where kustomization files are empty (#3094)
Browse files Browse the repository at this point in the history
Co-authored-by: Austin Abro <[email protected]>
  • Loading branch information
a1994sc and AustinAbro321 authored Oct 30, 2024
1 parent 0e63358 commit 1234b72
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/pkg/packager/prepare.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
14 changes: 14 additions & 0 deletions src/pkg/packager/prepare_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
16 changes: 16 additions & 0 deletions src/pkg/packager/testdata/find-images/kustomize/deployment.yaml
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
- deployment.yaml
12 changes: 12 additions & 0 deletions src/pkg/packager/testdata/find-images/kustomize/zarf.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
kind: ZarfPackageConfig
metadata:
name: agent
version: 1.0.0
components:
- name: baseline
required: true
manifests:
- name: agent
namespace: default
kustomizations:
- ./.

0 comments on commit 1234b72

Please sign in to comment.