kube-api-rewriter
Description
Sometimes you need to use different versions of one controller (or operator) in one cluster.
This is problematic due to CRD differences. Or, you want to enable multitenancy on the CRD level.
The first solution is to rewrite CRD definitions and re-compile controller for each version (or tenant).
Often this is time-consuming and error-prone.
This project offers the proxy sidecar container that sits between the controller and a Kubernetes API and
rewrites CRDs on the fly.
Install
TODO Improve
- Create rules for your CRDs. Use loader package to add rules at runtime.
- Compile kube-api-rewriter with additional Go file in cmd/kube-api-rewriter.
- Re-compile controller with "only JSON payload" setting for go-client.
- Change webhook services.
- Add sidecar to the controller Pod
- Configure go-client to use localhost as a Kubernetes API address.
Features
It can rewrite:
- Discovery requests.
- CRDs.
- CRs.
- Internal Kubernetes resources (i.e. Pod, Deployments, etc.).
- References in resources (i.e. ownerReferences, etc.).
- Admission webhook payloads.
- GET/UPDATE payloads.
- Patches.
- Payloads in watch streams.
History
02.03.2026
Extracted from deckhouse/virtualization
repo into a separate project.
02.11.2024
Initially created to use KubeVirt as a part of Deckhouse Virtualization Platform without
interfering with the original KubeVirt installation.
Known limitations
- No rewrite for grpc payloads.
- Needs to write Go structures for configuring rewrites.
- Needs to re-compile target controller.
- Still needs more sophisticated logging.