losisin / helm-values-schema-json Goto Github PK
View Code? Open in Web Editor NEWHelm plugin for generating values.schema.json from multiple values files
License: MIT License
Helm plugin for generating values.schema.json from multiple values files
License: MIT License
Hi,
Can I set items in the array to a certain type, like string? I have a helm chart values where I need to set something like this (those should be the default values in the chart):
app: settings: writeNamespace: &writeNamespace app1 watchNamespaces: - *writeNamespace
And as a result of schema generation I get:
`
"writeNamespace": {
"type": [
"string"
]
}
"watchNamespaces": {
"items": {
"type": null
},
"type": "array"
},
`
It seems that the type is not detected. And this off course fails when I try to run helm template command. If I correct the type of the items manually, it works.
I went through the repo docs but I couldn't find the solution.
It could be also nice to have to be able to add a default annotation in the schema coming from the comment
I dont seem to be able to figure out how properly declare that items within an array have a type unless my array object in values.yaml has an array with those objects declared. But I want the default to be [].
For example:
domains: []
# - domain.com
# - domain.co
results in domain: { type: array }
I want to be able to make this become domain: { type: array, items: { type: string }}
Could be useful if you manage to add a parsing in the comments to allow for specifying that the element is readonly
Currently the generated JSON Schema does not take into account when values are set which are not defined a values.yaml.
In JSON schema, we can set additionalProperties: false
to properties (see Documentation), which then causes e.g. helm lint
to error when there are values set which are for example incorrectly indented.
This helps debugging wrongly indented values, which can be hard to spot or even cause other side effects like removing resources via gitOps (when pruning is enabled) if values are just missing some spaces.
Example:
values.yaml:
onevalue:
secondvalue:
test: 123
With the currently generated JSON Schema, the following option values would not cause any errors:
values-test.yaml:
onevalue:
test: 123
Generated schema:
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"properties": {
"onevalue": {
"properties": {
"secondvalue": {
"properties": {
"test": {
"type": "integer"
}
},
"type": "object"
}
},
"type": "object"
}
},
"type": "object"
}
Running helm lint
:
helm lint --strict . -f values-test.yaml
==> Linting .
[INFO] Chart.yaml: icon is recommended
1 chart(s) linted, 0 chart(s) failed
But when additionalProperties: false
is added to all properties in the JSON schema like this:
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"additionalProperties": false,
"properties": {
"onevalue": {
"additionalProperties": false,
"properties": {
"secondvalue": {
"additionalProperties": false,
"properties": {
"test": {
"type": "integer"
}
},
"type": "object"
}
},
"type": "object"
}
},
"type": "object"
}
then running helm lint
fails:
helm lint --strict . -f values-test.yaml
==> Linting .
[INFO] Chart.yaml: icon is recommended
[ERROR] values.yaml: - onevalue: Additional property test is not allowed
[ERROR] templates/: values don't meet the specifications of the schema(s) in the following chart(s):
test:
- onevalue: Additional property test is not allowed
Error: 1 chart(s) linted, 1 chart(s) failed
Our use-case is as follows:
In the chart we have various optional values, e.g. defined with an empty value in the values.yaml:
# -- replica count
replicaCount:
In the Helm chart template:
{{- if $values.replicaCount }}
replicas: {{ $values.replicaCount }}
{{- end }}
The requirement is to have the value listed in the values.yaml
, so that we can document it with helm-docs, but we want the value to be optional and not set per default.
This now generates the following schema:
"replicaCount": {
"type": "null"
}
This results in an Invalid type error.
Maybe it would be possible to specify the type as a comment on the property similar to the requirement in #21
Do you have any plans to implement something like this?
BTW: Nice plugin ๐
Adding the option to write a title can help with the generation of pretty looking forms from the schema.
Having it in the # schema
comment section could help
Hi,
Thanks for this nice plugin. We started using it the other day for our internal Helm charts. Do you have any plans to implement required fields somehow like from comments/annotations or any other way?
Thanks,
Milos
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.