HULL depends on the usage of the Kubernetes API JSON schema which can be generated by the Open API to JSON schema tool. This tool can generate a variety of JSON schema files when run against a particular Kubernetes API version, out of the tool results two things are required for a HULL release:
-
a full set of created JSON schemas which is used for validating the output of the internal tests against the Kubernetes API schema. This must be of the
standalone-strict
variety. These files are used to validate the test results against the API schemes. -
a self-contained
_definition.json
with all the Kubernetes API objects of a particular version. This is the basis for HULL'svalues.schema.json
The first can best be obtained by cloning the following repository with up-to-date Kubernetes JSON schemas:
https://github.com/yannh/kubernetes-json-schema
This is an autoupated fork of the original project that provided the Kubernetes API JSON schemas but seems to be updated anymore. The fork creates new schemas on a regular schedule.
from this it is required to get the standalone-strict
version of the relevant API version, for Kubenetes API version 1.32 this would be:
https://github.com/yannh/kubernetes-json-schema/tree/master/v1.32.0-standalone-strict
and all files therein need to be copied to the hull/files/test/HULL/schema
folder.
The Git Repository is really big, if you don't want to clone the whole thing there is a helper site which lets you just download the needed folder:
https://download-directory.github.io/
The _definition.json
may be taken from the https://github.com/yannh/kubernetes-json-schema projects output but the produced file lacks some enumeration values which are nice to have in the schema.
An alternative method to obtain a slightly better _definition.json
is to produce it with the original tooling as such:
From https://github.com/instrumenta/kubernetes-json-schema/issues/26
repository holding Kubernetes JSON schemas, build according to: instrumenta/kubernetes-json-schema#26:
I worked around missing schemas for 1.19 by generating them on my own. This seems to work at first glance, although I don't have much prior experience with kubeval:
In Linux (or WSL):
# install tooling to generate the schemas sudo apt install python-pip export PYTHONHTTPSVERIFY=0 # this is only because I had cert issues pip install openapi2jsonschema
# generate a folder with schema files for a specific version (1.19.3 in this case) openapi2jsonschema -o "v1.19.3-standalone-strict" --kubernetes --stand-alone --strict https://raw.githubusercontent.com/kubernetes/kubernetes/v1.19.3/api/openapi-spec/swagger.json
# now fork this repo, add the generated files, commit, push
First install openapi2jsonschema with pip install openapi2jsonschema
.
Then run the command with added --expanded switch to create all relevant files for the release (here v1.20.0):
openapi2jsonschema -o "v1.20.0-standalone-strict" --expanded --kubernetes --stand-alone --strict https://raw.githubusercontent.com/kubernetes/kubernetes/v1.20.0/api/openapi-spec/swagger.json
Note that this command might produce many errors like:
An error occured processing mutatingwebhook: URLError: <urlopen error [WinError 3] Das System kann den angegebenen Pfad nicht finden: '\\v1.22.0-standalone-strict\\_definitions.json'>
The created _definition.json
cam now be used as source of the new hull/values.schema.json
.