Templating similar to kustomize but with multiple overlays
This requires yq
and yaml-patch
docker build --tag kastemais .
XXX
An application describes the minimum to deploy a service
An overlay contains YAML patches that modify an application with a specific purpose, e.g.
- Adding namespace
- Adding labels and annotations
- Adding resources
- Adding sidecars
Stored in a subdirectory of /app
, e.g. /app/nginx
Contains one or more YAML documents in one or more files - multiple documents per file a allowed
All files must have a leading document separator ---
Stored in a subdirectory if /overlay
, e.g. /overlay/sidecar-monitoring
Overlays can be applied to all documents
Overlays can be applied to specific documents using filters
cat app/nginx/deployment.yaml | docker run -i kastemais yq r - metadata.name
cat app/nginx/deployment.yaml | docker run -i kastemais yaml-patch -o overlay/ci-annotations/patch-all.yaml
This also works for multiple documents:
cat app/nginx/*.yaml | docker run -i kastemais yaml-patch -o overlay/ci-annotations/patch-all.yaml
NAME=$(./yq r app/nginx/deployment.yaml metadata.name)
cat app/nginx/deployment.yaml | docker run -i kastemais yq w - metadata.name ${NAME}-qa
TODO: How to filter?
Merge into one YAML document in the form (see merge_documents()
in functions.sh
):
apiVersion: v1
kind: List
items:
- ...
- ...
This is also valid:
apiVersion: v1
kind: List
items:
-
...
-
...
yq
can only operate on numerically indexed documents in a file:
$ cat app/nginx/*.yaml | yq3 -d'*' r - kind
ConfigMap
Deployment
Service
yq
can also merge multiple documents within a file when in the correct order (see merge_documents()
in functions.sh
)
Workaround: Split documents into separate files
$ cat app/nginx/*.yaml | csplit --prefix=document- --suffix-format=%02d.yaml --elide-empty-files --quiet - /---/ '{*}'
$ ls -l document-*.yaml
document-00.yaml document-01.yaml document-02.yaml
TODO: Description which application from /app
and which overlays from /overlay
to apply.
TODO: Is this in scope? If so...
- Support substitution from environment variables
- Explicit list of variables to substitute
- Support
.env
file?
Workaround: envsubst