1
0
Fork 0
mirror of https://github.com/kyverno/kyverno.git synced 2024-12-14 11:57:48 +00:00

docs: add section for generated code (#4465)

Signed-off-by: Charles-Edouard Brétéché <charled.breteche@gmail.com>

Signed-off-by: Charles-Edouard Brétéché <charled.breteche@gmail.com>
This commit is contained in:
Charles-Edouard Brétéché 2022-08-31 16:19:37 +02:00 committed by GitHub
parent 891ab41bef
commit f503be1b23
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 86 additions and 1 deletions

View file

@ -5,7 +5,6 @@ This document covers basic needs to work with Kyverno codebase.
It contains instructions to build, run, and test Kyverno.
- [Tools](#tools)
- [Building and publishing an image locally](#building-and-publishing-an-image-locally)
- [Building local binaries](#building-local-binaries)
- [Building local images](#building-local-images)
- [Building local images with docker](#building-local-images-with-docker)
@ -17,6 +16,10 @@ It contains instructions to build, run, and test Kyverno.
- [Create a local cluster](#create-a-local-cluster)
- [Build and load local images](#build-and-load-local-images)
- [Deploy with helm](#deploy-with-helm)
- [Code generation](#code-generation)
- [Generating kubernetes API client](#generating-kubernetes-api-client)
- [Generating API deep copy functions](#generating-api-deep-copy-functions)
- [Generating CRD definitions](#generating-crd-definitions)
## Tools
@ -348,6 +351,59 @@ This will build local images, load built images in every node of the KinD cluste
You can override the KinD cluster name by setting the `KIND_NAME` environment variable (default value is `kind`).
## Code generation
We are using code generation tools to create the following portions of code:
- [Generating kubernetes API client](#generating-kubernetes-api-client)
- [Generating API deep copy functions](#generating-api-deep-copy-functions)
- [Generating CRD definitions](#generating-crd-definitions)
> **Note**: You can run `make codegen-all` to build all generated code at once.
### Generating kubernetes API client
TODO
### Generating API deep copy functions
Based on the [APIs golang code definitions](./api), you can generate the corresponding deep copy functions by running:
```console
# generate all deep copy functions
make codegen-deepcopy-all
```
or
```console
# generate kyverno deep copy functions
make codegen-deepcopy-kyverno
```
or
```console
# generate policy reports deep copy functions
make codegen-deepcopy-report
```
This will output files named `zz_generated.deepcopy.go` in every API package.
### Generating CRD definitions
Based on the [APIs golang code definitions](./api), you can generate the corresponding CRDs manifests by running:
```console
# generate all CRDs
make codegen-crds-all
```
or
```console
# generate Kyverno CRDs
make codegen-crds-kyverno
```
or
```console
# generate policy reports CRDs
make codegen-crds-report
```
This will output CRDs manifests [/config/crds](./config/crds).
## Building and publishing an image locally
First, make sure you [install `ko`](https://github.com/google/ko#install)

View file

@ -283,6 +283,35 @@ docker-publish-all: docker-publish-kyvernopre docker-publish-kyverno docker-publ
.PHONY: docker-publish-all-dev
docker-publish-all-dev: docker-publish-kyvernopre-dev docker-publish-kyverno-dev docker-publish-cli-dev
###########
# CODEGEN #
###########
.PHONY: codegen-crds-kyverno
codegen-crds-kyverno: $(CONTROLLER_GEN) ## Generate Kyverno CRDs
@$(CONTROLLER_GEN) crd paths=./api/kyverno/... crd:crdVersions=v1 output:dir=./config/crds
.PHONY: codegen-crds-report
codegen-crds-report: $(CONTROLLER_GEN) ## Generate policy reports CRDs
@$(CONTROLLER_GEN) crd paths=./api/policyreport/... crd:crdVersions=v1 output:dir=./config/crds
.PHONY: codegen-crds-all
codegen-crds-all: codegen-crds-kyverno codegen-crds-report ## Generate all CRDs
.PHONY: codegen-deepcopy-kyverno
codegen-deepcopy-kyverno: $(CONTROLLER_GEN) $(GOIMPORTS) ## Generate Kyverno deep copy functions
@$(CONTROLLER_GEN) object:headerFile="scripts/boilerplate.go.txt" paths="./api/kyverno/..." && $(GOIMPORTS) -w ./api/kyverno
.PHONY: codegen-deepcopy-report
codegen-deepcopy-report: $(CONTROLLER_GEN) $(GOIMPORTS) ## Generate policy reports deep copy functions
@$(CONTROLLER_GEN) object:headerFile="scripts/boilerplate.go.txt" paths="./api/policyreport/..." && $(GOIMPORTS) -w ./api/policyreport
.PHONY: codegen-deepcopy-all
codegen-deepcopy-all: codegen-deepcopy-kyverno codegen-deepcopy-report ## Generate all deep copy functions
.PHONY: codegen-all
codegen-all: codegen-deepcopy-all codegen-crds-all ## Generate all CRDs and deep copy functions
##################################
# KYVERNO
##################################