NDB Operator 8.0 Manual  /  Installation of NDB Operator  /  Building an NDB Operator Image from Source

2.5 Building an NDB Operator Image from Source

This section describes how to compile, install, and test NDB Operator from source. If you do not already have the source code, see Section 2.2, “Obtaining NDB Operator”'.

The following prerequisites must be installed on the system to build and test NDB Operator:

Golang 1.16 or newer to compile the operator.

Docker to build the NDB Operator and other container images. Docker is also used to run the E2E testcases.

Minikube or KinD to deploy and test the NDB Operator. Kubernetes 1.19 or later is also required.

The Makefile included with the source code contains all targets needed to build the operator; this can done using the command shown here:

> make build

The Custom Resource Definition and other manifest files are regenerated by the build target.

By default, NDB Operator is built in release mode. To build it in debug mode for use in development instead, set the WITH_DEBUG environment variable to 1 when invoking the build, like this:

> WITH_DEBUG=1 make build

To generate the NDB Operator Docker image, run the command shown here:

> make operator-image

Once the image is built, it must be made accessible to the Kubernetes Cluster. For KinD, you can use kind load docker_image command to load the image. For Minikube, it depends on the container runtime used; see Pushing images into minikube clusters. See Chapter 3, Deploying NDB Cluster with NDB Operator, for information about setting up NDB Operator and deploying an NDB Cluster using the operator.

When using Minikube, the default memory allocation might not be adequate for running NDB Operator; you can increase it using minikube config set memory_limit. To deploy the example at docs/examples/example-ndb.yaml, Minikube requires at least 5GB memory; you can set this as shown here:

> minikube config set memory 5GB

Making changes to the NdbCluster type.  If any change is made to the NdbCluster type in pkg/apis/ndbcontroller/v1/types.go, you must renegerate the client set, informers, and listers. You can do this by executing the following command in pkg/generated:

> make generate
Warning

Do not attempt to modify the NdbCluster type while an upgrade of NDB Operator is in progress. See Section 2.7, “Upgrading NDB Operator”, for more information.

Testing NDB Operator.  The NDB Operator project comes with unit tests that are developed using the go testing package and a more elaborate End-To-End (E2E) test suite that is built on top of the Ginkgo/Gomega testing framework.

Most of the unit tests are colocated with the packages, and test the methods within those packages. They sometimes use a simulated Kubernetes client to verify whether requests sent by NDB Operator match expectations.

The E2E testcases are a collection of integration tests that make changes to an NdbCluster resource object and verify whether the NDB Cluster configuration controlled by the object changes accordingly. The testcases use a E2E framework developed internally and built on top of the Ginkgo testing framework. The tests should be run using e2e-tests/run-e2e-test.go; options for this testing tool can be found in e2e-tests/README.md. The tests can be run either in an existing Kubernetes cluster or a new one using KinD.

To generate the E2E testing image, run make e2e-tests on the command line.

To run the E2E tests in an existing Kubernetes cluster, pass the path to the kubeconfig file for this cluster to the run-e2e-test.go tool, like this:

> go run e2e-tests/run-e2e-test.go -kubeconfig=path/to/file

Both the mysql/ndb-operator and the e2e-tests images must be accessible to the Kubernetes Cluster.

The test tool can also start its own KinD cluster and then run the E2E tests in it. A Docker instance with both the mysql/ndb-operator and e2e-tests images must be accessible from the terminal in which the test is being run. The KinD cluster is started inside Docker as part of this process. You can do this running either one of the commands shown here:

> go run e2e-tests/run-e2e-test.go -use-kind

> make e2e-kind