Skip to content

Commit 4543bfd

Browse files
authored
Document code generation (zalando#370)
* Document code generation
1 parent 5ed1096 commit 4543bfd

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

docs/developer.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,20 @@ minikube. The following steps will get you the docker image built and deployed.
151151
$ sed -e "s/\(image\:.*\:\).*$/\1$TAG/" manifests/postgres-operator.yaml|kubectl --context minikube create -f -
152152
```
153153

154+
# Code generation
155+
156+
The operator employs k8s-provided code generation to obtain deep copy methods and Kubernetes-like APIs for its custom resource definitons, namely the Postgres CRD and the operator CRD. The usage of the code generation follows conventions from the k8s community. Relevant scripts live in the `hack` directory: the `update-codegen.sh` triggers code generation for the APIs defined in `pkg/apis/acid.zalan.do/`,
157+
the `verify-codegen.sh` checks if the generated code is up-to-date (to be used within CI). The `/pkg/generated/` contains the resultant code. To make these scripts work, you may need to `export GOPATH=$(go env GOPATH)`
158+
159+
References for code generation are:
160+
* [Relevant pull request](https://github.com/zalando-incubator/postgres-operator/pull/369)
161+
See comments there for minor issues that can sometimes broke the generation process.
162+
* [Code generator source code](https://github.com/kubernetes/code-generator)
163+
* [Code Generation for CustomResources](https://blog.openshift.com/kubernetes-deep-dive-code-generation-customresources/) - intro post on the topic
164+
* Code generation in [Prometheus](https://github.com/coreos/prometheus-operator) and [etcd](https://github.com/coreos/etcd-operator) operators
165+
166+
To debug the generated API locally, use the [kubectl proxy](https://kubernetes.io/docs/tasks/access-kubernetes-api/http-proxy-access-api/) and `kubectl --v=8` log level to display contents of HTTP requests (run the operator itself with `--v=8` to log all REST API requests). To attach a debugger to the operator, use the `-outofcluster` option to run the operator locally on the developer's laptop (and not in a docker container).
167+
154168
# Debugging the operator
155169

156170
There is a web interface in the operator to observe its internal state. The

0 commit comments

Comments
 (0)