Convert Kubernetes CRDs into openapi specifications
This template can be used to convert Kubernetes Custom Resource Definitions (CRDs) to openapi specifications. It can be used for generating client APIs for different programming languages.
Usually, the process to create a go-lang specific client to access CRDs is as suggested in [kubernetes/kube-openapi#13]
- Create the objects in go lang with specific annotations
- Generate the openapi using a kubernetes instance
- Generate a client based on the generated openapi specification
This process is not valid for the different programming languages, as the code generation and routes are only based on go-lang. This templates allows to invert the process and create the client based on an openapi specification, generated using the crd.
The template is based on jinja2 template engine. It is tested using the j2cli
command line tool and needs to be installed.
Using pip:
pip install j2cli
Example:
j2 crd-openapi.json.j2 [path/to/crd.yaml] > openapi.json
- The template not handle properly
status
andscale
subresources - It can only generate the specification for one CRD. In order to generate multiple a manual merge is needed.
The api generated is based on the file [https://github.com/kubernetes-client/gen/blob/master/openapi/custom_objects_spec.json]