Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
92 commits
Select commit Hold shift + click to select a range
355d0f5
add feature flag for values
mkcp Aug 28, 2025
a6fb3eb
add internal/values with file validation and parsing and add --value …
mkcp Aug 28, 2025
1d9d728
add value.Values to packager create, deploy, and partially to inpect …
mkcp Aug 28, 2025
3df0a2c
stub out examples and e2e tests
mkcp Aug 28, 2025
4d2c610
rewrite ParseFiles to properly deepmerge values yaml and test it
mkcp Aug 29, 2025
23a8027
update package CLI commands to use ctx ParseFiles
mkcp Aug 29, 2025
b2db2a3
make improvements to value pkg and tests for linting and ctx cancella…
mkcp Aug 29, 2025
eb2453f
make docs-and-schema
mkcp Aug 29, 2025
96eec5d
add values to v1beta1 schema
mkcp Aug 29, 2025
6aeb2cd
convert default internal variables over to values
mkcp Aug 29, 2025
9b9c5ad
undo edits to alpha schema
mkcp Sep 3, 2025
6ab0bc3
testing chart value overrides on v1alpha1, this doesn't get into main
mkcp Sep 3, 2025
3ec1b20
update comments on v1beta1 schema
mkcp Sep 3, 2025
1b76f5b
add values as optional field in packager API and proof of concept hel…
mkcp Sep 3, 2025
2e98fa9
make docs-and-schema
mkcp Sep 3, 2025
f542021
WIP: example chart for zarf values overriding helm values
mkcp Sep 5, 2025
061858d
implement helm overrides in deploy
mkcp Sep 5, 2025
d5fb32d
simplify values example to just a configmap
mkcp Sep 5, 2025
d802aa7
fix bug with everything being stored under a map with emptystring whe…
mkcp Sep 5, 2025
f2cdbca
include package-level value files
mkcp Sep 8, 2025
65e93db
when assembling a package, copy values files that are referenced by URL
mkcp Sep 8, 2025
dd33519
cleanup url handling
mkcp Sep 8, 2025
8bba1af
don't actually handle URLs yet, it affects the current dataflow more …
mkcp Sep 8, 2025
6b6d81e
go templating example, files, manifests, and packageconfig
mkcp Sep 8, 2025
92e1eb7
add setvariables to schema and example declaration, not implemented yet
mkcp Sep 8, 2025
b42120b
update examples to reflect Values go-templating syntax
mkcp Sep 8, 2025
a1dc7ec
add zarf.yaml version to overrides exampel
mkcp Sep 9, 2025
909ab23
fix some rough edges in the templating example
mkcp Sep 9, 2025
9a9c849
working on packagedefinition templating. failing linting for some reason
mkcp Sep 9, 2025
766974c
add templating funcs
mkcp Sep 10, 2025
ba4701e
add repeat templating funct
mkcp Sep 10, 2025
e29a11f
update schema
mkcp Sep 18, 2025
536caa2
iterate on values templating in files/manifests. attempt to import sp…
mkcp Sep 18, 2025
c740a31
update example cases, stub out readmes
mkcp Sep 18, 2025
b5d9a0f
resolve some fixmes
mkcp Sep 24, 2025
2fe95bd
remove package templating for now, and iterate on template objects
mkcp Sep 24, 2025
740749f
clean up some dangling packagetemplating values in examples
mkcp Sep 24, 2025
87259bc
Constants and Variables is handled withing go-templating objects now
mkcp Sep 24, 2025
219b504
update action.Run signature to incorpoate values. Make template objec…
mkcp Sep 24, 2025
a6f467d
update template.Objects flow into actions.Run. build objects as late …
mkcp Sep 24, 2025
7f4228f
add setValues back into examples
mkcp Sep 24, 2025
2b380a3
make docs-and-schema
mkcp Sep 24, 2025
d938db7
update values templates-example
mkcp Sep 24, 2025
4a256ee
apply templates to cmds and enable setValues
mkcp Sep 24, 2025
ceb8cfb
move examples to a directory structure the website can parse. update …
mkcp Sep 24, 2025
ac88a4a
remove create flags from early pkgtemplating. fix some deploy variabl…
mkcp Sep 24, 2025
cc0e2c1
clean up value package and fix a panic from DeepMerge
mkcp Sep 25, 2025
2a3ac66
clean up values-helm-overrides example
mkcp Sep 25, 2025
75e7546
clean up package schema
mkcp Sep 25, 2025
7a7a8c9
more cleanup - fix linter issues
mkcp Sep 25, 2025
07c665e
fix functions in templates, both files and cmds, and produce unit tes…
mkcp Sep 29, 2025
6e02a3e
add README to templating example, add sprig function examples, fix te…
mkcp Sep 29, 2025
234b46d
remove modified-terraform.tf
mkcp Sep 29, 2025
587f7bd
add simple e2e smoke test for values templating
mkcp Sep 29, 2025
8eb1283
revert v1beta1 changes and revert out of scope vars change
mkcp Sep 29, 2025
e1328db
cleanup fixmes
mkcp Sep 29, 2025
79b9075
add yaml and json parsing to setValues
mkcp Sep 29, 2025
9fbb27c
make the linter happy by being less specific about the type of error …
mkcp Sep 29, 2025
57f6a8a
This should fix the setVariables regression - make sure cobra is sett…
mkcp Sep 30, 2025
1d841e0
flag dashes for features in 42 e2e test
mkcp Sep 30, 2025
b25defa
clean up helm-overrides example, accidentally checked in a pkg create…
mkcp Sep 30, 2025
9a37372
true up example/values-templating readme
mkcp Sep 30, 2025
f34bc2e
load pkg.Values.Files relative to the package path not cwd
mkcp Sep 30, 2025
b13eab6
fix values-templating nginx styling
mkcp Sep 30, 2025
8669d72
use relative filename when copying values files dst not absolute path…
mkcp Sep 30, 2025
174e494
fix e2e test, make sure we're templating with the correct key
mkcp Sep 30, 2025
b3f1588
clean up some out-of-scope changes to package inspect manifests and v…
mkcp Oct 1, 2025
23a60c9
Update src/api/v1alpha1/component.go
mkcp Oct 2, 2025
de4a808
make docs-and-schema and don't check an empty ctx
mkcp Oct 2, 2025
2c18659
rename internal/template.ApplyToCmd to Apply and clean up internal/te…
mkcp Oct 2, 2025
ab14746
update e2e values test to check setValues and yaml/json parsing
mkcp Oct 2, 2025
2c53189
don't store the e2e example in json.json.etc and yaml.yaml.etc
mkcp Oct 2, 2025
89de456
helm install broke on dashes, may actually be an action parsing bug
mkcp Oct 2, 2025
3de01ab
clean up assemble.go
mkcp Oct 2, 2025
c48dd07
fix . for sourcePath (extract now returns all values on root path) an…
mkcp Oct 2, 2025
b542964
rework value.Set to handle path to root '.' and add tests. extract an…
mkcp Oct 2, 2025
473c41d
change DeepMerge to a variadic method and add unit tests
mkcp Oct 2, 2025
1f0f715
cleanup and make linter happy
mkcp Oct 2, 2025
1c648b9
bump feature flag version to release version
mkcp Oct 2, 2025
095fbfd
remove extra file-exists check, and make sure we error if not given a…
mkcp Oct 3, 2025
26eed44
rework component file and manifest template field to boolptr with IsT…
mkcp Oct 3, 2025
e062bce
condense examples and remove terraform templating
mkcp Oct 3, 2025
2d77714
ensure relative values.yaml paths don't munge the destination directory
mkcp Oct 3, 2025
d71a493
block values files imports that come from outside the directory
mkcp Oct 3, 2025
4669c88
error if missing key in template. use sprig default func instead
mkcp Oct 6, 2025
2fe037f
fix todos and stub comment
mkcp Oct 6, 2025
ded9820
remove unncessary valuesfile load in packagedefinition
mkcp Oct 7, 2025
f42c346
use local reference to logger.From
mkcp Oct 7, 2025
6bb81a6
add Objects.{WithState,WithAgentState,WithSeedRegistryState}
mkcp Oct 10, 2025
4aa6761
add .State.cluster, .State.artifact, and various available fields fro…
mkcp Oct 10, 2025
430e4dc
make linter happy
mkcp Oct 10, 2025
e2c5ca8
make sure WithAgent and WithSeedRegistry call WithState internally. c…
mkcp Oct 10, 2025
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
6 changes: 6 additions & 0 deletions examples/values-templating/charts/example-chart/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
apiVersion: v2
name: example-chart
version: 0.1.0
appVersion: "0.1.0"
description: A simple example chart for overriding helm values with zarf values.
type: application
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ .Values.appName }}-config
namespace: {{ .Release.Namespace }}
labels:
app: {{ .Values.appName }}
chart: {{ .Chart.Name }}-{{ .Chart.Version }}
release: {{ .Release.Name }}
replicas: "{{ .Values.replicaCount }}"
data:
# Test basic mappings
app-name: "{{ .Values.appName }}"
replica-count: "{{ .Values.replicaCount }}"
image-tag: "{{ .Values.image.tag }}"

# Test nested object mapping
database-host: "{{ .Values.config.database.host }}"
database-port: "{{ .Values.config.database.port }}"

# Test default values (not mapped)
log-level: "{{ .Values.config.app.logLevel }}"
debug-mode: "{{ .Values.config.app.debug }}"

# Test resource values
cpu-limit: "{{ .Values.resources.limits.cpu }}"
memory-limit: "{{ .Values.resources.limits.memory }}"
24 changes: 24 additions & 0 deletions examples/values-templating/charts/example-chart/values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Chart default values - these will be overridden by Zarf value mappings on the chart definition
appName: "default-app"
replicaCount: 1

image:
repository: nginx
tag: "latest"
pullPolicy: IfNotPresent

config:
database:
host: "localhost"
port: 3306
app:
debug: false
logLevel: "info"

resources:
limits:
cpu: 100m
memory: 128Mi
requests:
cpu: 50m
memory: 64Mi
77 changes: 77 additions & 0 deletions examples/values-templating/nginx-configmap.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: nginx-configmap
namespace: nginx
labels:
app: nginx
data:
01_http.conf: |
add_header X-Kubernetes-Pod $hostname;
index.html: |
<!DOCTYPE html>
<html>
<head>
<title>Welcome to {{ .Values.site.name }}!</title>
<style>
{{ .Values.site.styles }}
</style>
</head>
<body>
<!-- Test two separate values on the same line -->
<h1>Welcome to the {{ .Values.site.name }}!</h1><h2>Brought to you by {{ .Values.site.organization }}.</h2>

<!-- Import Variables and Constants into new go-templates, to help with migrating over to the new Values feature
and templating syntax -->
<pre>Imported variable from .Variables.EXAMPLE_VAR {{ .Variables.EXAMPLE_VAR }}</pre>
<pre>Imported constant from .Constants.EXAMPLE_CONST {{ .Constants.EXAMPLE_CONST }}</pre>

<!-- Sprig Function Examples -->
<h3>Sprig Function Examples</h3>

<!-- String manipulation functions -->
<h4>String Functions:</h4>
<pre>Original: {{ .Values.site.message | quote }}</pre>
<pre>Upper: {{ .Values.site.message | upper | quote }}</pre>
<pre>Title: {{ .Values.site.message | title | quote }}</pre>
<pre>Kebab: {{ .Values.site.title | kebabcase | quote }}</pre>
<pre>Snake: {{ .Values.site.title | snakecase | quote }}</pre>

<!-- List/array functions -->
<h4>List Functions:</h4>
<pre>Items: {{ .Values.app.features | join ", " | quote }}</pre>
<pre>Count: {{ .Values.app.features | len }}</pre>
<pre>First: {{ .Values.app.features | first | quote }}</pre>
<pre>Last: {{ .Values.app.features | last | quote }}</pre>
<pre>Sorted: {{ .Values.app.features | sortAlpha | join ", " | quote }}</pre>
<pre>Reversed: {{ .Values.app.features | reverse | join ", " | quote }}</pre>

<!-- Default value functions -->
<h4>Default & Conditional Functions:</h4>
<pre>Required Field: {{ .Values.app.required_setting | default "fallback value" | quote }}</pre>
<pre>Optional Field (empty): {{ .Values.app.optional_setting | default "default value" | quote }}</pre>
<pre>Environment: {{ .Values.app.environment | upper | quote }}</pre>

<!-- Math functions -->
<h4>Math Functions:</h4>
<pre>Replicas: {{ .Values.app.replicas }}</pre>
<pre>Add 2: {{ add .Values.app.replicas 2 }}</pre>
<pre>Multiply: {{ mul .Values.app.replicas 10 }}</pre>
<pre>Max Port: {{ max .Values.app.port1 .Values.app.port2 .Values.app.port3 }}</pre>
<pre>Min Port: {{ min .Values.app.port1 .Values.app.port2 .Values.app.port3 }}</pre>

<!-- Encoding/hashing functions -->
<h4>Encoding & Hashing Functions:</h4>
<pre>Base64: {{ .Values.app.config_data | b64enc }}</pre>
<pre>SHA256: {{ .Values.app.config_data | sha256sum }}</pre>

<!-- Type conversion and formatting -->
<h4>Type & Format Functions:</h4>
<pre>Ports as String: {{ .Values.app.ports | join "," | quote }}</pre>
<pre>Items Count: {{ .Values.app.features | len | toString }}</pre>
<pre>Repeat and Indent Example:</pre>
<pre>{{ .Values.site.message | repeat 3 | indent 4 }}</pre>

{{ .Values.site.footer }}
</body>
</html>
55 changes: 55 additions & 0 deletions examples/values-templating/nginx-deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx
namespace: nginx
labels:
app: nginx
# Sprig example: Convert environment to lowercase and kebab-case
environment: {{ .Values.app.environment | lower }}
# Sprig example: Create a hash-based identifier
config-hash: {{ .Values.app.config_data | sha256sum | trunc 8 }}
annotations:
# Sprig example: Base64 encode sensitive data references
config.zarf.dev/data-hash: {{ .Values.app.config_data | b64enc }}
spec:
selector:
matchLabels:
app: nginx
# Sprig example: Use configured replica count with a sensible default
replicas: {{ .Values.app.replicas | default 1 }}
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:latest
ports:
- containerPort: 80
name: http
env:
# Sprig example: Environment variables with transformations
- name: ENVIRONMENT
value: {{ .Values.app.environment | upper | quote }}
- name: APP_NAME
value: {{ .Values.site.title | kebabcase | quote }}
- name: CONFIG_HASH
value: {{ .Values.app.config_data | sha256sum | trunc 16 | quote }}
resources:
limits:
# Sprig example: Calculate CPU based on replica count
cpu: {{ mul .Values.app.replicas 100 }}m
memory: 512Mi
volumeMounts:
- name: nginx-config
mountPath: /etc/nginx/conf.d/01_http.conf
subPath: 01_http.conf
- name: nginx-config
mountPath: /usr/share/nginx/html/index.html
subPath: index.html
volumes:
- name: nginx-config
configMap:
name: nginx-configmap
19 changes: 19 additions & 0 deletions examples/values-templating/nginx-service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
apiVersion: v1
kind: Service
metadata:
name: nginx-connect
namespace: nginx
annotations:
zarf.dev/connect-description: "Launch the nginx static site."
labels:
zarf.dev/connect-name: nginx
zarf.dev/example-var: {{ .Variables.EXAMPLE_VAR }}
zarf.dev/example-const: {{ .Constants.EXAMPLE_CONST }}
spec:
ports:
- port: 8080
name: http
protocol: TCP
targetPort: 80
selector:
app: nginx
47 changes: 47 additions & 0 deletions examples/values-templating/values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# Constants are defined on package create and do not change on deploy
# This demonstrates setting the nginx version to bake into the package using a package variable (PKG_TMPL)
site:
# The name of the site you are deploying
name: "Zarf Values Example Website"
# Sets the CSS styles for the site, and provides an example of a multi-line value
styles: >-
body { font-family: sans-serif; color: white; background: #0a0e2e; }
pre { color: white; background: black; }
# The organization providing the site
organization: "Zarf-Dev"
# The footer to be added to the site, overrides the default with whatever you want.
footer: ""
# Additional metadata for sprig examples
title: "my awesome app"
message: "hello world from zarf"

# Application deployment configuration
app:
environment: "production"
replicas: 3
# Configuration data that can be hashed for integrity checks
config_data: "important application configuration data"
# Optional field to demonstrate default values
optional_setting: "" # Will use default value in templates
required_setting: "configured value"
# List of supported features for list function examples
features:
- "templating"
- "sprig-functions"
- "kubernetes-deployment"
- "value-substitution"
# Network ports for the application
ports: [80, 443, 8080]
port1: 80
port2: 443
port3: 8080
# Helm chart overrides
name: "helm-overrides-app" # Maps to .appName in helm chart
image:
tag: "v2.1.0" # Maps to .image.tag in helm chart

# Database configuration for helm chart
database:
host: "postgres.zarf.local-schmocal" # Maps to .config.database.host in helm chart
host2: "postgres.zarf.local" # Also maps to .config.database.host, but takes priority because it's mapped afterwards

95 changes: 95 additions & 0 deletions examples/values-templating/zarf.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
kind: ZarfPackageConfig
metadata:
name: values-templating
description: Example nginx package to demonstrate Zarf Values templating
values:
files:
- values.yaml

# Until Consts and Vars are fully deprecated, they'll be available in go-templates
constants:
- name: EXAMPLE_CONST
value: "foo"
variables:
- name: EXAMPLE_VAR
default: "bar"

components:
- name: values-with-manifest
description: This component demonstrates templating manifest files by deploying an nginx page to the cluster
required: true
images:
# NOTE: Pkgtemplates aren't yet available with value and go-templates.
- "nginx:latest"
manifests:
- name: values-with-nginx
# Enables go-templating within the files.
template: true
files:
- nginx-deployment.yaml
- nginx-service.yaml
- nginx-configmap.yaml

- name: values-with-helm-chart
description: This component demonstrates helm chart value overrides using Zarf values
required: true
charts:
- name: example-chart
version: 0.1.0
localPath: "charts/example-chart"
namespace: "helm-overrides"
values:
- sourcePath: ".app.name"
targetPath: ".appName"
- sourcePath: ".app.replicas"
targetPath: ".replicaCount"
- sourcePath: ".app.image.tag"
targetPath: ".image.tag"
- sourcePath: ".database.host"
targetPath: ".config.database.host"
# Multiple mappings are ok. They are evaluated first to last, so the latest mapping will take priority.
- sourcePath: ".database.host2"
targetPath: ".config.database.host"


# YAML keys starting with `x-` are custom keys that are ignored by the Zarf CLI
# The `x-mdx` key is used to render the markdown content for https://docs.zarf.dev/ref/examples
x-mdx: |
# [ALPHA] Values & Templates Example

This example demonstrates the pre-release alpha version of Zarf's values templating system, including support for **Sprig functions** for advanced template processing and **Helm chart value overrides**.

## Features Demonstrated

- **Basic templating** with `{{ .Values.* }}`, `{{ .Build.* }}`, `{{ .Metadata.* }}`, `{{ .Constants.* }}`, and `{{ .Variables.* }}`
- **Sprig functions** for string manipulation, lists, math, encoding, and more
- **File templating** with both simple substitution and complex transformations
- **Dynamic configuration** using template functions for practical Kubernetes deployments
- **Helm chart value overrides** mapping Zarf values to Helm chart values

## Sprig Functions Showcased

The example includes demonstrations of popular Sprig functions:
- **String functions**: `upper`, `lower`, `title`, `kebabcase`, `snakecase`, `quote`
- **List functions**: `join`, `len`, `first`, `last`, `sortAlpha`, `reverse`
- **Default functions**: `default` for fallback values
- **Math functions**: `add`, `mul`, `max`, `min`
- **Encoding functions**: `b64enc`, `sha256sum`
- **Utility functions**: `repeat`, `indent`, `trunc`, `toString`

## Try It Out

Deploy this example to see values and templates in action:

```bash
# Create and deploy the package (features="values=true" flag required until general release of values)
zarf package create . --confirm --features="values=true"
zarf package deploy zarf-package-values-templating-*.tar.zst --confirm --features="values=true"

# View the nginx results
kubectl get configmap nginx-configmap -n nginx -o yaml
zarf connect nginx

# View the helm chart results
kubectl get configmap -n helm-overrides
```
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ require (
github.com/DataDog/zstd v1.5.5 // indirect
github.com/MakeNowJust/heredoc v1.0.0 // indirect
github.com/Masterminds/goutils v1.1.1 // indirect
github.com/Masterminds/sprig/v3 v3.3.0 // indirect
github.com/Masterminds/sprig/v3 v3.3.0
github.com/Masterminds/squirrel v1.5.4 // indirect
github.com/Microsoft/go-winio v0.6.2 // indirect
github.com/Microsoft/hcsshim v0.11.7 // indirect
Expand Down
1 change: 1 addition & 0 deletions site/src/content/docs/commands/zarf_package_deploy.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ zarf package deploy [ PACKAGE_SOURCE ] [flags]
--shasum string Shasum of the package to deploy. Required if deploying a remote https package.
--skip-signature-validation Skip validating the signature of the Zarf package
--timeout duration Timeout for health checks and Helm operations such as installs and rollbacks (default 15m0s)
-v, --values strings [alpha] Values files to use for templating and Helm overrides. Multiple files can be passed in as a comma separated list, and the flag can be provided multiple times.
```

### Options inherited from parent commands
Expand Down
Loading