提交 bad812a6 编写于 作者: L liqingping

docs: update developer guide

上级 905b6bf8
# Developer Guide
## Prerequisites
- a well prepared kubernetes cluster. Follow the [instructions](https://kubernetes.io/docs/setup/production-environment/tools/kubeadm/create-cluster-kubeadm/) to create a kubernetes cluster, or create a local kubernetes node referring to [kind](https://kind.sigs.k8s.io/docs/user/quick-start/) or [minikube](https://minikube.sigs.k8s.io/docs/start/)
- a well prepared kubernetes cluster. Follow the[instructions](https://kubernetes.io/docs/setup/production-environment/tools/kubeadm/create-cluster-kubeadm/) to create a kubernetes cluster, or create a local kubernetes node referring to[kind](https://kind.sigs.k8s.io/docs/user/quick-start/) or[minikube](https://minikube.sigs.k8s.io/docs/start/)
- kustomize. Installed by the following command
```bash
curl -s "https://raw.githubusercontent.com/\
kubernetes-sigs/kustomize/master/hack/install_kustomize.sh" | bash
```
- cert-manager. Installation on kubernetes referenced to [cert-manager docs](https://cert-manager.io/docs/installation/kubernetes/). Or you can install by the following command.
```bash
kubectl create -f ./config/certmanager/cert-manager.yaml
```
## Project Initialization
This project is based on [kubebuilder v3](https://github.com/kubernetes-sigs/kubebuilder/releases/download/v3.0.0/kubebuilder_linux_amd64), since CRDs generated by kubebuilder v2 is not compatible in kubernetes v1.20.
```bash
kubebuilder init --domain opendilab.org --license apache2 --owner "The OpenDILab authors"
kubebuilder create api --group diengine --version v1alpha2 --kind DIJob
## CRD Design
kubebuilder create api --group diengine --version v1alpha2 --kind AggregatorConfig
```
Update codes in [dijob_types.go](./api/v1alpha2/dijob_types.go) with your requirements, and generate deepcopy functions.
## CRD Design
Make codes in [dijob_types.go](./api/v1alpha2/dijob_types.go) and [aggregatorconfig_types.go](./api/v1alpha2/aggregatorconfig.go) with your requirements, and generate deepcopy functions.
```bash
make generate
```
Generate new CRD files with the following command.
```bash
make manifests
```
New CRD files will be generated in [./config/crd/bases](./config/crd/bases)
## Controller Logic
Referenced to [controllers](./controllers)
## DI Server Logic
Referenced to [server](./server)
## Installation
Run the following command in the project root directory.
```bash
# build images.
make docker-build
......@@ -48,26 +45,31 @@ make docker-push
# deploy di-operator and server to cluster
make dev-deploy
```
Since the CustomResourceDefinitions are too long, you will probably find the following error:
```bash
The CustomResourceDefinition "dijobs.diengine.opendilab.org" is invalid: metadata.annotations: Too long: must have at most 262144 bytes
```
Then running the following command will solve the problem:
```bash
kustomize build config/crd | kubectl create -f -
```
`di-operator`, `di-webhook` and `di-server` will be installed in `di-system` namespace.
`di-operator` and `di-server` will be installed in `di-system` namespace.
```bash
$ kubectl get pod -n di-system
NAME READY STATUS RESTARTS AGE
di-operator-57cc65d5c9-5vnvn 1/1 Running 0 59s
di-server-7b86ff8df4-jfgmp 1/1 Running 0 59s
di-webhook-45jgi23fhc-9yght 1/1 Running 0 59s
```
Install global components of DIJob defined in AggregatorConfig:
```bash
kubectl create -f config/samples/agconfig.yaml -n di-system
```
## Programming Specification
- Logger: logger should use`github.com/go-logr/logr.Logger`, created from`sigs.k8s.io/controller-runtime/pkg/log.DelegatingLogger`. We have the following specifications
- Logger used in each function should be defined as:`logger := ctx.Log.WithName(function-name).WithValues("job", job-namespace-name))`. It's helpful for debuging since we can easily locate where the log message is from and what the DIJob is. Then, DIJob related information is not needed in log message.
- All the log message should start with lower case letter.
-
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册