You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Generate Pydantic models from Kubernetes OpenAPI specifications.
25
+
26
+
Overview
27
+
--------
28
+
29
+
Kubedantic provides a way to automatically generate Pydantic models using your Kubernetes cluster OpenAPI specifications and `datamodel-code-generator <https://github.com/koxudaxi/datamodel-code-generator>`_.
30
+
31
+
Usage
32
+
-----
33
+
34
+
1. Make sure you have a Kubernetes cluster running and `kubectl` is configured to access it.
35
+
2. Run `kubedantic` to generate the models.
36
+
37
+
.. code-block:: bash
38
+
39
+
$ kubedantic --output-path <destination>
40
+
41
+
How it works
42
+
------------
43
+
44
+
Kubedantic does the following:
45
+
46
+
1. Uses the `kubernetes <https://github.com/kubernetes-client/python>`_ library to fetch the openapi specifications from the cluster.
47
+
2. Merges the specifications extracted from the openapi specifications into a single schema file (one for the native types and one for the custom resources).
48
+
3. Uses `datamodel-code-generator <https://github.com/koxudaxi/datamodel-code-generator>`_ to generate the Pydantic models from each schema file.
49
+
50
+
Schema files will be cached locally in the `kubedantic_specs/` directory, e.g.:
51
+
52
+
.. code-block:: bash
53
+
54
+
kubedantic_specs/
55
+
├── k8s.json # Kubernetes native types
56
+
└── crd.json # Custom resource definitions
57
+
58
+
You can control the cache location by using the `--specs-path` option.
0 commit comments