|
1 | 1 | # Kube code generator
|
2 | 2 |
|
3 |
| - |
| 3 | + |
4 | 4 |
|
5 |
| -A kubernetes code generator container that makes easier to generate CRD manifests and its Go clients. |
| 5 | +## Introduction |
6 | 6 |
|
7 |
| -Uses [official code-generator](https://github.com/kubernetes/code-generator) created by Kubernetes to autogenerate the code required for the CRDs. |
| 7 | +When we speak about Kubernetes operators or controllers, normally Go code, CR, CRDs... are required. To create all the autogenerated Kubernetes Go code (Clients, helpers...) and manifests (CRD), the process is a bit painful. |
8 | 8 |
|
9 |
| -## Generation targets |
| 9 | +This small project tries making easy this process, by creating a small layer between Kubernetes official tooling that are used to get all this autogenerated stuff, and abstract options and infer some others, making a better UX for the user. |
10 | 10 |
|
11 |
| -- CRD based Go code (clients, lib...). |
12 |
| -- CRD manifest YAMLs to register your CRs on the cluster. |
| 11 | +The projects that are used under the hood are: |
13 | 12 |
|
14 |
| -## Docker image versions |
| 13 | +- [code-generator](https://github.com/kubernetes/code-generator) for Go code autogeneration. |
| 14 | +- [controller-tools](https://github.com/kubernetes-sigs/controller-tools) for CRD autogeneration. |
15 | 15 |
|
16 |
| -| | Docker image | |
17 |
| -| ---------------- | ------------------------------------------------------- | |
18 |
| -| Kubernetes v1.27 | `docker pull ghcr.io/slok/kube-code-generator:v1.27.0` | |
19 |
| -| Kubernetes v1.26 | `docker pull ghcr.io/slok/kube-code-generator:v1.26.0` | |
20 |
| -| Kubernetes v1.25 | `docker pull ghcr.io/slok/kube-code-generator:v1.25.0` | |
21 |
| -| Kubernetes v1.24 | `docker pull ghcr.io/slok/kube-code-generator:v1.24.0` | |
22 |
| -| Kubernetes v1.23 | `docker pull ghcr.io/slok/kube-code-generator:v1.23.0` | |
23 |
| -| Kubernetes v1.22 | `docker pull ghcr.io/slok/kube-code-generator:v1.22.0` | |
24 |
| -| Kubernetes v1.21 | `docker pull ghcr.io/slok/kube-code-generator:v1.21.1` | |
25 |
| -| Kubernetes v1.20 | `docker pull ghcr.io/slok/kube-code-generator:v1.20.1` | |
26 |
| -| Kubernetes v1.19 | `docker pull ghcr.io/slok/kube-code-generator:v1.19.2` | |
27 |
| -| Kubernetes v1.18 | `docker pull ghcr.io/slok/kube-code-generator:v1.18.0` | |
28 |
| -| Kubernetes v1.17 | `docker pull ghcr.io/slok/kube-code-generator:v1.17.3` | |
29 |
| -| Kubernetes v1.16 | `docker pull ghcr.io/slok/kube-code-generator:v1.16.7` | |
30 |
| -| Kubernetes v1.15 | `docker pull ghcr.io/slok/kube-code-generator:v1.15.10` | |
31 |
| -| Kubernetes v1.14 | `docker pull ghcr.io/slok/kube-code-generator:v1.14.2` | |
32 |
| -| Kubernetes v1.13 | `docker pull ghcr.io/slok/kube-code-generator:v1.13.5` | |
33 |
| -| Kubernetes v1.12 | `docker pull ghcr.io/slok/kube-code-generator:v1.12.4` | |
34 |
| -| Kubernetes v1.11 | `docker pull ghcr.io/slok/kube-code-generator:v1.11.3` | |
35 |
| -| Kubernetes v1.10 | `docker pull ghcr.io/slok/kube-code-generator:v1.10.0` | |
36 |
| -| Kubernetes v1.9 | `docker pull ghcr.io/slok/kube-code-generator:v1.9.1` | |
| 16 | +## Why and when use this |
37 | 17 |
|
38 |
| -## Getting started |
| 18 | +- You don't like, need or use kubebuilder for your CRDs. |
| 19 | +- You want simple tooling to generate Kubernetes CRD Go clients and manifests. |
| 20 | +- You like safe standards and simple things. |
| 21 | +- You use CRDs for more/other things than operators (e.g: generating CLIs, storing state on k8s as APIs...). |
| 22 | +- You don't want to do hacky and ugly stuff to start creating Kubernetes tooling. |
39 | 23 |
|
40 |
| -The best way to know how to use it is by checking the [example](example/) that will generate the required clients and CRD manifests. |
| 24 | +## Features |
41 | 25 |
|
42 |
| -### Optional settings |
| 26 | +- Small API/configuration. |
| 27 | +- Safe standards |
| 28 | +- Ready to use Docker images. |
| 29 | +- Generates Go code like clients and informers (Used to implement operators, CLIs...). |
| 30 | +- Generates CRD manifests (Used for API registration on k8s clusters). |
43 | 31 |
|
44 |
| -Some settings are optional so you can customize special cases: |
| 32 | +## How to use it |
45 | 33 |
|
46 |
| -- On CRD manifest YAML generation: |
47 |
| - - `CRD_FLAG` env var to overwrite CRD flag with a custom one. (E.g: Use `allowDangerousTypes=true` to allow `float64` on generation, [more info here][unsecure-float64]) |
| 34 | +The easiest way is to use the provided Docker image as it has all the required upstream dependencies. |
48 | 35 |
|
49 |
| -[unsecure-float64]: https://github.com/kubernetes-sigs/controller-tools/issues/245 |
| 36 | +Here is an example that mounts the current directory (a Go project) and generates the Go code and the CRDs by providing the APIs input directory and the generation output directories: |
| 37 | + |
| 38 | +```bash |
| 39 | +docker run -it --rm -v ${PWD}:/app ghcr.io/slok/kube-code-generator \ |
| 40 | + --apis-in ./apis \ |
| 41 | + --go-gen-out ./gen \ |
| 42 | + --crd-gen-out ./gen/manifests |
| 43 | +``` |
| 44 | + |
| 45 | +However, the best way to know how to use it is with a full example, you have it in [_example](_example/) dir. |
| 46 | + |
| 47 | +## Kubernetes versions |
| 48 | + |
| 49 | +| Kubernetes | Docker image | |
| 50 | +| ---------- | ------------------------------------------------------- | |
| 51 | +| v1.29 | `docker pull ghcr.io/slok/kube-code-generator:v1.29.0` | |
| 52 | + |
| 53 | +### Versions <v1.29 |
| 54 | + |
| 55 | +With the release of Kubernetes v1.30, this app was rewritten from bash hacky scripts into a proper Go application, that is easier, more extendable and safer to use. This new refactor of the app works with Kubernetes `>=v1.29` and changes the usage of the app, so for other versions you will need to check the previous implementation I would suggest that you check the [Readme of `<v1.27`](https://github.com/slok/kube-code-generator/tree/v1.27.0). |
0 commit comments