Questions tagged [ytt]

For any questions related to YTT (YAML templating tool), a third-party extension to YAML, adding support for variables, functions, include by reference, and other features not found in standard YAML.

ytt - YAML Templating Tool

Given a set of YAML files, you want to:

  • inject variables, conditionally include parts, or loop over a list and generate chunks of YAML; and/or
  • apply a set of edits (like a patch) that are guaranteed to result in valid YAML.

and, you want it to be:

  • maintainable — even when templated, YAML files are human-readable
  • deterministic — given the same inputs, get the same output
  • scalable — as you wrangle more YAML, you can keep it sensibly organized
  • general-purpose — manage all your YAML (Kubernetes manifests, Docker Compose, Concourse Pipeline, Envoy config, Travis build config, etc.) with one tool

ytt does that:

  • templates are written using intuitive Python-like syntax
  • extract whole chunks of YAML into functions that can be invoked without thinking about escaping or indentation
  • group things into libraries to be reused and shared
  • ensures execution is deterministic by giving no access to the filesystem, network, time, randomness, or operating system interfaces

ytt is part of the Carvel suite (pronounced /ˈkɑr vəl/; rhymes with "marvel"), an Open Source project containing a set of small sharp tools that support packaging and deploying software on Kubernetes.

Example

(See this example and others in the online ytt Playground)

Given a ytt template:

config.yml

#@ load("@ytt:data", "data")

#@ def/end labels():
app: apple

kind: Pod
apiVersion: v1
metadata:
  name: apple-app
  labels: #@ labels()
spec:
  containers:
  - name: apple-app
    image: hashicorp/http-echo
    args:
    - #@ "-listen=:" + str(data.values.port)
    - #@ "-text=" + data.values.text
---
kind: Service
apiVersion: v1
metadata:
  name: apple-service
spec:
  selector: #@ labels()
  ports:
  - port: #@ data.values.port

... and a set of values ...

values.yml

#@data/values
---
port: 8080
#! note how text is quoted automatically in the result file
text: "Hello #ytt World!"

Running ytt...

$ ytt -f config.yml -f values.yml

...yields...

kind: Pod
apiVersion: v1
metadata:
  name: apple-app
  labels:
    app: apple
spec:
  containers:
  - name: apple-app
    image: hashicorp/http-echo
    args:
    - -listen=:8080
    - '-text=Hello #ytt World!'
---
kind: Service
apiVersion: v1
metadata:
  name: apple-service
spec:
  selector:
    app: apple
  ports:
  - port: 8080
10 questions
2
votes
1 answer

YTT overlays: modify arrays using data from that arrays

This question is about YTT. Is it possible to modify YAML list of items using the data from that items via overlays? For example we have a template: --- vlans: - vlan-id: 10 - vlan-id: 20 - vlan-id: 30 some_other_configuration: #! some other config…
Anton M.
  • 185
  • 1
  • 11
1
vote
1 answer

Carvel YTT module returns no match on simple replacement overlay when integrating with go

I am trying to integrate carvel ytt module with my app. So far I am trying some basic stuff I have previously tested in playground. When I try to do the same thing in code, it always returns no match. filesToProcess :=…
pepík
  • 11
  • 3
1
vote
1 answer

How can I replace map value of array item contained in a multi-line string with ytt?

I'm trying to use a ytt overlay to replace the objectName in my secret class following this gist example replacing only part of a multi-line string, but it ends up appending a new item instead of replacing the existing one. How can I get it to work…
Mai Lubega
  • 13
  • 2
1
vote
1 answer

how to connect zookeeper after deploying helm chart in gke?

we are creating a vmware carvel package, I need do a sanity check for zookeeper, how can i check the output in gke? Zookeeper output Curl and localhost is failing to connect.
Ram R
  • 21
  • 2
1
vote
1 answer

How to split ytt method definition from schema

I'm trying to split a method definition from the schema. This is a case loosely inspired by the official how-to. If the following code is present in the same file, it works well. However if I'm splitting the method definition into a separate file…
Bernard Halas
  • 972
  • 11
  • 24
1
vote
1 answer

How to use ytt to add a sidecar container to an existing Kubernetes Deployment?

I would like to add a fluent-bit agent as a sidecar container to an existing Istio Ingress Gateway Deployment that is generated via external tooling (istioctl). I figured using ytt and its overlays would be a good way to accomplish this since it…
tcdowney
  • 317
  • 2
  • 5
0
votes
1 answer

YTT: append array items together but remove duplicates

I have two documents: --- resources: - index: 1 - index: 2 and resources: - index: 2 - index: 3 - index: 4 My desired output is: resources: - index: 1 - index: 2 - index: 3 - index: 4 I tried #@ load("@ytt:overlay",…
Rakesh Adhikesavan
  • 11,966
  • 18
  • 51
  • 76
0
votes
2 answers

Helm + ytt + argo

I am a begginer developer. Please help to find my mistake I have a helm chart with ytt .yml files. I going to deploy the chart in argo. There are many links for helm+argo/kubernetes, but poor with helm+ytt+argo/kubernetes. My ytt files are in the…
0
votes
1 answer

Ytt: When do you need to match by name?

I recently realized that to get a YTT substitution to work properly, I had to add this: #@overlay/match by="name" like so: spec: template: spec: containers: #@overlay/match by="name" - name: php-redis …
jayunit100
  • 17,388
  • 22
  • 92
  • 167
0
votes
1 answer

How do I add a map to an array of maps in ytt?

I'm trying to add a map to an array of maps in ytt to modify a YAML doc. I tried the below but it errors out and says it expects a map but getting an array. https://gist.github.com/amalagaura/c8b5c7c92402120ed76dec95dfafb276 --- id: 1 type:…
Amala
  • 1,718
  • 1
  • 17
  • 29