From bad812a61c4df5ae1af27943976d0cfae14cb624 Mon Sep 17 00:00:00 2001 From: liqingping Date: Fri, 14 Jan 2022 19:54:06 +0800 Subject: [PATCH] docs: update developer guide --- docs/developer-guide.md | 42 +++++++++++++++++++++-------------------- 1 file changed, 22 insertions(+), 20 deletions(-) diff --git a/docs/developer-guide.md b/docs/developer-guide.md index c254353..86af154 100644 --- a/docs/developer-guide.md +++ b/docs/developer-guide.md @@ -1,46 +1,43 @@ # 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. + - -- GitLab