Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tk export does not work with inline environments #809

Closed
irizzant opened this issue Feb 9, 2023 · 2 comments
Closed

tk export does not work with inline environments #809

irizzant opened this issue Feb 9, 2023 · 2 comments

Comments

@irizzant
Copy link

irizzant commented Feb 9, 2023

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.

@Duologic
Copy link
Member

Duologic commented Feb 22, 2023

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.

@irizzant
Copy link
Author

irizzant commented Feb 23, 2023

@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?

@zerok zerok closed this as completed May 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

No branches or pull requests

3 participants