Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/internal/packager/kustomize/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ func Build(path string, destination string, kustomizeAllowAnyDirectory bool, ena

if enableKustomizePlugins {
buildOptions.PluginConfig = krustytypes.MakePluginConfig(krustytypes.PluginRestrictionsNone, krustytypes.BploUseStaticallyLinked)
buildOptions.PluginConfig.HelmConfig.Enabled = true
buildOptions.PluginConfig.HelmConfig.Command = "helm"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I half wonder if after #4350 is merged we should update this to use zarf tools helm.

Not a blocker, but a potential follow-up pr.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, #4350 is close but blocked by a bug in Helm that will be fixed in the next Helm release.

I do think we should block this PR on that, the quasi Helm fork currently in Zarf is outdated, and I would like to avoid relying on the host binary, so that package builds are the same across devices

}

kustomizer := krusty.MakeKustomizer(buildOptions)
Expand Down
48 changes: 48 additions & 0 deletions src/internal/packager/kustomize/build_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// SPDX-License-Identifier: Apache-2.0
// SPDX-FileCopyrightText: 2021-Present The Zarf Authors

// Package template provides functions for templating yaml files.
package kustomize

import (
"os"
"path"
"testing"

"github.com/stretchr/testify/require"
)

func TestBuild(t *testing.T) {
tests := []struct {
path string
kustomizeAllowAnyDirectory bool
enableKustomizePlugins bool
}{
{
path: path.Join("testdata", "generators"),
kustomizeAllowAnyDirectory: false,
enableKustomizePlugins: false,
},
{
path: path.Join("testdata", "helm"),
kustomizeAllowAnyDirectory: true,
enableKustomizePlugins: true,
},
}

for _, test := range tests {
tmpdir := t.TempDir()

builtManifest := path.Join(tmpdir, "generated.yaml")

err := Build(test.path, builtManifest, test.kustomizeAllowAnyDirectory, test.enableKustomizePlugins)
require.NoError(t, err)
require.FileExists(t, builtManifest, "built manifest file should exist")

expectedContent, err := os.ReadFile(path.Join(test.path, "expected.yaml"))
buildContent, err := os.ReadFile(builtManifest)
require.NoError(t, err)

require.Equalf(t, expectedContent, buildContent, "Built kustomization should match expected")
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
apiVersion: v1
data:
key: value
kind: ConfigMap
metadata:
name: test-t757gk2bmf
---
apiVersion: v1
data:
password: cGFzc3dvcmQ=
username: dXNlcm5hbWU=
kind: Secret
metadata:
name: auth-m84m9g76mm
type: Opaque
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
configMapGenerator:
- name: test
literals:
- key=value
secretGenerator:
- name: auth
literals:
- username=username
- password=password
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
apiVersion: v2
name: chart
description: A Helm chart for Kubernetes
type: application
version: 0.0.0
appVersion: "0.0.0"
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
apiVersion: v1
kind: Pod
metadata:
name: pod
spec:
containers:
- name: busybox
image: {{ .Values.image.repository }}:{{ .Values.image.tag }}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
image:
repository: busybox
tag: 1.0.0
8 changes: 8 additions & 0 deletions src/internal/packager/kustomize/testdata/helm/expected.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
apiVersion: v1
kind: Pod
metadata:
name: pod
spec:
containers:
- image: busybox:1.0.0
name: busybox
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
helmGlobals:
chartHome: .
helmCharts:
- releaseName: chart
name: chart
repo: ./chart
Loading