Skip to content

Instantly share code, notes, and snippets.

@mamachanko
Created June 11, 2021 08:36
Show Gist options
  • Save mamachanko/a8cd505354e4041d55378d5b4329e8d8 to your computer and use it in GitHub Desktop.
Save mamachanko/a8cd505354e4041d55378d5b4329e8d8 to your computer and use it in GitHub Desktop.
Carvel, default images and optional preresolution

Render with latest or default:

ytt -f image-config.yaml | kbld -f - -f pod-template.yaml

Render with specific version:

ytt -f image-config.yaml -v nginxVersion=1.20 | kbld -f - -f pod-template.yaml
ytt -f image-config.yaml -v nginxVersion=1.21 | kbld -f - -f pod-template.yaml

Render but don't resolve images:

ytt -f image-config.yaml -v preresolved=true -v nginxVersion=1.21 | kbld -f - -f pod-template.yaml
#@ load("@ytt:data", "data")
#! there must be a better way to do this.
#@ def nginxImage():
#@ if data.values and hasattr(data.values, "nginxVersion"):
#@ return 'nginx:' + data.values.nginxVersion
#@ else:
#@ return 'nginx'
#@ end
#@ end
#@ def preresolved():
#@ if data.values and hasattr(data.values, "preresolved"):
#@ return data.values.preresolved == "true"
#@ else:
#@ return False
#@ end
#@ end
---
apiVersion: kbld.k14s.io/v1alpha1
kind: Config
overrides:
- image: nginx
newImage: #@ nginxImage()
preresolved: #@ preresolved()
#@ load("@ytt:data", "data")
---
apiVersion: v1
kind: Pod
metadata:
labels:
run: nginx
templatedLabel: #@ data.values.label
name: nginx
spec:
containers:
- image: nginx
name: nginx
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment