Parameterizing
Deploying using Tanka worked well, but it did not really improve the situation in terms of maintainability and readability.
To do so, the following sections will explore some ways Jsonnet provides us with.
Functions parameters
Defining our deployment in a single block is not the best solution. Luckily with Jsonnet we can split our configuration into smaller, self-contained chunks.
Let’s start by creating a new function in main.jsonnet
responsible for creating a Grafana deployment:
and let’s use it in our main configuration:
We can then replace hardcoded values by adding parameters to our function:
and update the usage accordingly:
Now we do not only have a single place to change tunables, but also won’t suffer from mismatching labels and selectors anymore, as they are defined in a single place and all changed at once.