Developer Guide
March 23, 2022 ยท View on GitHub
Prerequisites
- a well prepared kubernetes cluster. Follow the instructions to create a kubernetes cluster, or create a local kubernetes node referring to kind or minikube
- kustomize. Installed by the following command
curl -s "https://raw.githubusercontent.com/\
kubernetes-sigs/kustomize/master/hack/install_kustomize.sh" | bash
CRD Design
Update codes in dijob_types.go with your requirements, and generate deepcopy functions.
make generate
Generate new CRD files with the following command.
make manifests
New CRD files will be generated in ./config/crd/bases
Controller Logic
Referenced to controllers
DI Server Logic
Referenced to server
Installation
Run the following command in the project root directory.
# build images.
make docker-build
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:
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:
kustomize build config/crd | kubectl create -f -
di-operator and di-server will be installed in di-system namespace.
$ 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
Programming Specification
- Logger: logger should use
github.com/go-logr/logr.Logger, created fromsigs.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 debugging 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.
- Logger used in each function should be defined as: