carvel-dev / ytt

YAML templating tool that works on YAML structure instead of text
https://carvel.dev/ytt
Apache License 2.0
1.65k stars 135 forks source link

ytt should have a functionality to generate value file skeletons #253

Open dherbrich opened 3 years ago

dherbrich commented 3 years ago

Describe the problem/challenge you have I was parameterizing a k8s yaml file and added a bunch of data values into it, e.g.:

apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
  name: #@ data.values.meta.appname if data.values.meta.appname else assert.fail("missing data.values.meta.appname ")
  namespace: #@ data.values.meta.appnamespace or "argocd"

The needed _values-skeleton.yml looks like this:

#@data/values
---
meta:
  appname: 
  appnamespace: 

Currently this needs to be done by hand/manually. This is especially challenging if you need to merge multiple yaml snippets to compose an application/deployment unit and want to create a data values file for it. It would also be nice to validate/annotate unused data values in a value file when applied to a set of input files.

Describe the solution you'd like Given the first snippet of a prepared yaml file/template, I would like to have a functionality that I can invoke via cli to generate the output as described in the second snippet above: ytt values generate -f application.yml -o values.yml For validation and checking for unused values I would propose something like this:

ytt values validate -f application.yml -f values.yml
-----
VALID 
[INFO] data.values.projectname is unused
-----
INVALID
[ERR] data.values.meta.appname is not provided but required
[INFO] data.values.meta.namespace is not provided
...

Anything else you would like to add: [Additional information that will assist in solving the issue.]

danielhelfand commented 3 years ago

@dherbrich Thanks for opening this issue. What I am seeing here is two requests:

  1. A way to start by defining values in YAML as opposed to a data values file, which is maybe the preferred user experience of a lot of folks. I think it's really interesting and think it would be worthwhile to discuss this idea further.

  2. A validation approach for requiring data values. We do support workarounds for this now, such as assertions. Example of its use shown here. But we do realize the UX is not the best for this right now, which is why we are developing ideas around ytt schemas to potentially address issues such as this. This is admittedly still undergoing refinement, but we are hoping it will be the long term solution for this.

github-actions[bot] commented 3 years ago

This issue is being marked as stale due to a long period of inactivity and will be closed in 5 days if there is no response.

cari-lynn commented 3 years ago

Generating data values files is a great idea. This would be a nice feature to add to our schema proposal. We could generate a data values file from a schema.

We will update the schema proposal to include this feature. You can find the proposal here.

Adding a command for validation is also an interesting idea. I opened a separate issue to track it. #278