Kube code generator

December 20, 2025 ยท View on GitHub

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

  • You don't like, need or use kubebuilder for your CRDs.
  • You want simple tooling to generate Kubernetes CRD Go clients and manifests.
  • You like safe standards and simple things.
  • You use CRDs for more/other things than operators (e.g: generating CLIs, storing state on k8s as APIs...).
  • You don't want to do hacky and ugly stuff to start creating Kubernetes tooling.

Features

  • Small API/configuration.
  • Safe standards
  • Ready to use Docker images.
  • Generates CR client Go code (Used in controllers and operators).
  • Generates CR informers Go code (Used in controllers and operators).
  • Generates CR listers Go code (Used in controllers and operators).
  • Generates CR "apply configurations" Go code (Used in controllers and operators).
  • Generates CRD manifests (Used for API registration on k8s clusters).

How to use it

The easiest way is to use the provided 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.

Optional features

These are the list of features that can be enabled when generating Go code or CRDs:

Kubernetes versions

It's suggested that if you kind-of up to date Kubernetes version, you try the latest kube-code-generator:

docker pull ghcr.io/slok/kube-code-generator:latest

However the ones described on the table here are known to work correctly on the specific version.

KubernetesDocker image
v1.35docker pull ghcr.io/slok/kube-code-generator:v0.9.0
v1.34docker pull ghcr.io/slok/kube-code-generator:v0.8.0
v1.33docker pull ghcr.io/slok/kube-code-generator:v0.7.0
v1.32docker pull ghcr.io/slok/kube-code-generator:v0.6.0
v1.31docker pull ghcr.io/slok/kube-code-generator:v0.3.2
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