Config Structural Validation using a declarative JSON Schema Part 0: Scripts, Global#1862
Config Structural Validation using a declarative JSON Schema Part 0: Scripts, Global#1862
Conversation
robinAwallace
left a comment
There was a problem hiding this comment.
As the schema very long I have not really gone though it. But it looks promising 🙂 I will try to try it out next week.
robinAwallace
left a comment
There was a problem hiding this comment.
I have manged to try it out now and it is very nice to get error on specific values when they are "wrong" 👍
But I have some thoughts. 🙂
|
In the pipeline, where does this |
ad0978c to
d5ffa16
Compare
06eb73a to
9d74eab
Compare
|
Please add |
|
I've created a PR with a helper to regenerate the full diff that is used for the update-ips tests. |
thoughts on split vs single schema filesplit schema into multiple filespro:
con:
single schemapro:
con:
conclusiontools vs tools tradeoff? I prefer single file. can always switch later. |
Yeah, the single schema sounds better in this case.
And this I especially like 😁 I assume the idea is to still have a separate one for secrets, as we don't merge that in? |
Very nice summary of the pros and cons. 👍 I agree stick with a single file. |
Yeah, assuming secrets is its own thing. Different kind of thing having its own schema seems sensible. And given the sensitive nature, keeping them separate as long as possible to minimize exposure is probably good. |
🎉 Now to add more tests specifically for schema... |
|
Gonna rebase, reorder and squash a bit. |
robinAwallace
left a comment
There was a problem hiding this comment.
LGTM 🥳 Im happy to merge this. Just one thought, could you mention some were how to setup vscode to work with the validator? 🙂
As in, enabling it here or enabling it somewhere else where you have config? I can write some extra words about it in |
Yeah, I think it is worth mentioning that, that plugin would enable validation/help in vscode. As you basically already done in this PR description. |
JSON Schema is a format for describing the structure of a JSON value, meant to support validation of data. This makes it usable for validating the structure of the cluster config files since JSON and YAML have overlapping data models. Being an open standard, there are multiple tools and libraries available for doing validation, as well as generating documentation or boilerplate code for type-aware languages. The initial schema only covers the top level 'global' entry for easier review, additional entries will be added in subsequent PRs Schema validation for secrets.yaml currently acts on the sops-encrypted file and thus only sees the basic structure. Includes a tool to generate basic json (but yaml) schemas, although it requires some post-processing so it is mostly useful to get a starting point. To validate, run `./bin/ck8s validate sc|wc`. If something is wrong it should print the path and value that violates the schema to make it easy to fix. Would have been nice if yajsv could output the the values that fail validation itself. suggestions from code review Co-authored-by: André Arnqvist <58822152+aarnq@users.noreply.github.com>
|
The remaining parts of
Each one adds a few more or less related sections to the config schema. Five is a good number. |
Warning
This is public repository, ensure not to disclose:
What kind of PR is this?
Required: Mark one of the following that is applicable:
Optional: Mark one or more of the following that are applicable:
Important
Breaking changes should be marked
kind/admin-changeorkind/dev-changedepending on typeCritical security fixes should be marked with
kind/securityRelease notes
The configuration files are now validated against a JSON Schema.
Platform Administrator notice
When validating config against the schema you may encounter cases where they disagree on what type a field should be and it may be necessary to tweak either the config or the schema to match the intent.
What does this PR do / why do we need this PR?
...
Additional information to reviewers
This adds a huge JSON Schema file (in YAML format) that describes the structure of the config. Feel free to ignore it when reviewing, it does not need to be perfect immediately but can be incrementally perfected over time.
A new tool, yajsv, written in Go, is added as requirement which needs to be installed (
bin/install-requirements.bash). Since JSON Schema is an an open specification with multiple implementations, it could be replaced in the future. We could even write our own using one of the available libraries.To try this, run e.g.:
Information about JSON schema can be found at https://json-schema.org/
The specifications themselves are found at
Notes about certain common schema fields:
defaultcan be used to describe a default value, which could be used in future tooling to actually fill in default values, but for now serves as documentation.exampleandexamplescan contain one or many example values. This could be shown in future tooling to improve UX.formatallows specifying what kind of string to expect. Common usable values includehostname,uri(for URLs etc),email. Unknown values are ignored by the validator, so common formats could be described and potentially implemented in future tooling.additionalPropertiesdefines schema for a property of an object that is not covered byproperties, setting this tofalserejects unknown values, and thus detects things that might have been missed.Screenshots
Can provide validation and help messages in e.g. VS Code:
Could also be used to generate documentation:
Checklist
NetworkPolicy Dashboard