- Git
- Golang (version >= 1.13)
- Docker (version >= 19.03)
- Kubernetes (version >= 1.14)
- GNU Make
For installation of Golang, please refer to Install Golang
make
is usually in a build-essential
package in your distribution's package manager of choice. Make sure you have make
on your machine.
There're great chances that you may want to run your implementation in a real Kubernetes cluster, so probably a Docker is needed for some necessary operations like building images. See Install Docker for more information.
$ mkdir -p $GOPATH/src/github.com/fluid-cloudnative/
$ cd $GOPATH/src/github.com/fluid-cloudnative
$ git clone https://github.com/fluid-cloudnative/fluid.git
NOTE: In this document, we build, run and debug under non-module environment.
See Go Modules for more information if some issue occurs to you.
Makefile
under project directory provides many tasks you may want to use including Test, Build, Debug, Deploy etc.
You can simply get a binary by running:
# build controller manager
$ make manager
# build fluid CSI plugin
$ make csi
By default, the binary would be put under <fluid-path>/bin
.
-
Set tags for images
# image name for controller manager $ export IMG=<registry>/<namespace>/<img-repo> # image name for CSI plugin $ export CSI_IMG=<registry>/<namespace>/<csi-img-repo>
Image tag will be automatically injected with SHA1 value of current git revision.
-
Login to a image registry
Make sure you've login to a docker image registry that you'd like to push your image to:
$ sudo docker login <docker-registry>
-
Build your image and push:
# build and push image for controller manager $ make docker-push # build and push image for CSI plugin $ make docker-push-csi
Alternatively, it makes no difference that you build your images first and then manually push them:
$ make docker-build $ make docker-build-csi $ docker push <IMG>:<IMG_TAG>
In the following steps, we assume you have properly configured KUBECONFIG
environment variable or set up ~/.kube/config
. See Kubeconfig docs for more information.
-
Push your images to a image registry accessible to your Kubernetes cluster
If your images are pushed to some private repositories, make sure your Kubernetes cluster hold credentials for accessing those repositories.
-
Change image in the samples we provide:
# <fluid-path>/config/fluid/patches/image_in_manager.yaml ... ... containers: - name: manager image: <registry>/<namespace>/<img-repo>:<img-tag>
# <fluid-path>/config/fluid/patches/image_in_csi-plugin.yaml ... ... containers: - name: plugins image: <registry>/<namespace>/<csi-img-name>:<csi-img-tag>
-
Install CRDs
$ kubectl apply -k config/crd
Check CRD with:
$ kubectl get crd | grep fluid alluxiodataloads.data.fluid.io 2020-08-22T03:53:46Z alluxioruntimes.data.fluid.io 2020-08-22T03:53:46Z datasets.data.fluid.io 2020-08-22T03:53:46Z
-
Install your implementation
$ kubectl apply -k config/fluid
Check Fluid system with:
$ kubectl get pod -n fluid-system NAME READY STATUS RESTARTS AGE controller-manager-7fd6457ccf-p7j2x 1/1 Running 0 84s csi-nodeplugin-fluid-pj9tv 2/2 Running 0 84s csi-nodeplugin-fluid-t8ctj 2/2 Running 0 84s
-
Run samples to verify your implementation
Here is a sample provided by us, you may want to rewrite it according to your implementation.
$ kubectl apply -k config/samples
Check sample pods:
$ kubectl get pod NAME READY STATUS RESTARTS AGE cifar10-fuse-vb6l4 1/1 Running 0 6m15s cifar10-fuse-vtqpx 1/1 Running 0 6m15s cifar10-master-0 2/2 Running 0 8m24s cifar10-worker-729xz 2/2 Running 0 6m15s cifar10-worker-d6kmd 2/2 Running 0 6m15s nginx-0 1/1 Running 0 8m30s nginx-1 1/1 Running 0 8m30s
-
Check logs to verify your implementation
$ kubectl logs -n fluid-system <controller_manager_name>
-
Clean up
$ kubectl delete -k config/samples $ kubectl delete -k config/fluid $ kubectl delete -k config/crd
Execute following command from project root to run basic unit tests:
$ make unit-test
kubebuilder
provided a integration test framework based on envtest package. You must install kubebuilder
before running integration tests:
$ os=$(go env GOOS)
$ arch=$(go env GOARCH)
$ curl -L https://go.kubebuilder.io/dl/2.3.1/${os}/${arch} | tar -xz -C /tmp/
$ sudo mv /tmp/kubebuilder_2.3.1_${os}_${arch} /usr/local/kubebuilder
$ export PATH=$PATH:/usr/local/kubebuilder/bin
Next, run all unit tests (integration tests included) with:
$ make test
NOTE: When running unit tests on a non-linux system such as macOS, if testing failed and says
exec format error
, you may need to check whetherGOOS
is consistent with your actual OS.
You can debug your program in multiple ways, here is just a brief guide for how to debug with go-delve
Prerequisites
Make sure you have go-delve
installed. See go-delve installation guide for more information
Debug locally
# build & debug in one line
$ dlv debug <fluid-path>/cmd/controller/main.go
# debug binary
$ make manager
$ dlv exec bin/manager
Debug remotely
On remote host:
$ dlv debug --headless --listen ":12345" --log --api-version=2 cmd/controller/main.go
The command above will make go-delve
start a debug service and listen for port 12345.
On local host, connect to the debug service:
$ dlv connect "<remote-address>:12345" --api-version=2
Note: To debug remotely, make sure the specified port is not occupied and the firewall has been properly configured.