Home

Awesome

Kube code generator

Kubernetes release

Introduction

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.

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.

The projects that are used under the hood are:

Why and when use this

Features

How to use it

The easiest way is to use the prov[v0.3.0]: https://github.com/slok/kube-code-generator/compare/v0.2.0...v0.3.0ided Docker image as it has all the required upstream dependencies.

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:

docker run -it --rm -v ${PWD}:/app ghcr.io/slok/kube-code-generator \
 --apis-in ./apis \
 --go-gen-out ./gen \
 --crd-gen-out ./gen/manifests

However, the best way to know how to use it is with a full example, you have it in _example dir.

Kubernetes versions

It's suggested that if you don't have an old Kubenretes version, you try the latest kube-code-generator (latest), however the ones described on the table here are known to work correctly on the specific version.

KubernetesDocker image
v1.31docker pull ghcr.io/slok/kube-code-generator:v0.3.1
v1.30docker pull ghcr.io/slok/kube-code-generator:v0.2.0
v1.29docker pull ghcr.io/slok/kube-code-generator:v0.2.0
v1.28docker pull ghcr.io/slok/kube-code-generator:v0.2.0
v1.27docker pull ghcr.io/slok/kube-code-generator:v0.2.0

Versions <v1.27

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.

In case you tested this new refactor and isn't working for you, Inwould suggest to try the previous versions, check the previous Readme.