tanka
tanka copied to clipboard
tk export does not work with inline environments
I have the following jsonnet to produce inline environments:
function(apiServer, b, c={}, d=null, e=null) {
environment(cluster):: {
apiVersion: 'tanka.dev/v1alpha1',
kind: 'Environment',
metadata: {
name: 'environment/%s' % cluster.name,
},
spec: {
apiServer: apiServer,
namespace: 'monitoring',
},
**data: { /* something depending on the variables ... */ },**
},
clusters:: [
{ name: 'us-central1', apiServer: 'https://127.0.0.1:6433' },
{ name: 'europe-west2', apiServer: 'https://127.0.0.2:6433' },
],
envs: {
[cluster.name]: $.environment(cluster)
for cluster in $.clusters
},
}
With this setup it's not possible to use tk export to export the generated yaml, I think because as reported here tk env doesn't work either.
Also, I don't see another way to pass the apiServer dinamically as top level arg, because tk set doesn't work with inline environment.
The only workaround I found is to rely on tk show --dangerous-allow-redirect piped into kubectl which is obviously not recommended.
Only tk eval takes top-level arguments, that is by design. The environments should be a bit more hermetic.
This blogpost might inspire you for your use case: https://grafana.com/blog/2021/07/12/best-practices-for-consistent-configuration-management-at-scale-with-tanka/
The idea is that you sort out the inputs for each environment before applying them, store them in a file and read it from there in your loop.
@Duologic the article you linked is more or less what I have already put in place.
Anyway there are cases where the data cannot be just put statically in a file, or should I say that it's less convenient to do that. Think about CI environments for example.
I know that it's possible to circumvent this in different ways (exporting env vars into files is one on them) but I think it would be much easier if one could use tk export or tk env list without rethinking everything in term of static imports without tla .
After all, the code I put above is a perfectly valid jsonnet, isn't it?