helm-values-gen
generates a YAML payload that contains all default values in
a given JSON schema. This is useful when maintaining a helm project with a
values.schema.json
that already contains the default values that are
expected in values.yaml
.
Currently, helm-values-gen
can be installed as Go binary.
In the future it will be (additionally) possible to install it as a helm plugin.
go install github.com/giantswarm/helm-values-gen@latest
$ helm-values-gen values.schema.json -o values.yaml
Wrote default values to values.yaml
Use --help
to learn about more options.
As JSON schemas can be nested deeply, we need to define which default values will be contained in the resulting payload. The tool follows these steps:
- Start in the root of the schema
- If there is a default value, add it to the payload.
- Recurse into all properties.
Note:
The tool does not recurse into the items
keyword of an array.
To specify default values for an array you have to set a default on the level
of the array.
Consider the following example:
values.schema.json
{
"type": "object",
"properties": {
"addresses": {
"type": "array",
"items": {
"type": "object",
"properties": {
"city": {
"type": "string",
"default": "New York"
}
}
},
},
"lastName": {
"type": "string",
"default": "Doe"
}
}
}
values.yaml
lastName: Doe
The default value addresses[].city = "New York"
is not reflected in
values.yaml
.
To specify a default value for an array consider the following example:
{
"type": "object",
"properties": {
"addresses": {
"type": "array",
"items": {
"type": "object"
"properties": {
"city": {
"type": "string",
"default": "New York"
}
}
},
"default": [
{
"city": "New York"
}
]
},
"lastName": {
"type": "string",
"default": "Doe"
}
}
}
values.yaml
addresses:
- city: New York
lastName: Doe
An action to run schemalint verify
on the values.schema.json
in app repositories in provided in actions/verify-helm-schema
.
Example workflow:
name: JSON schema validation
on:
push: {}
jobs:
generate:
name: Check that values.yaml is generated from values.schema.json with helm-values-gen
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Run helm-values-gen
id: run-helm-values-gen
uses: giantswarm/helm-values-gen/actions/ensure-generated@v1
This repository uses floating tags.
Other repositories that use helm-values-gen point to major floating tag versions,
like v1
. That means that all minor and patch releases will be automatically
rolled out to these repositories.
When doing a major release the following steps have to be completed:
- Create a new major floating tag under "Actions -> Ensure major version tags -> Run Workflow"
- Update all references to schemalint.
- devctl:
pkg/gen/input/workflows/internal/file/cluster_app_schema_validation.yaml.template
- devctl: