Pre-commit is used to enforce code quality and style. You should install
python and pip using your package manager. To install pre-commit, run:
pip install pre-commitThen, install the pre-commit hooks:
pre-commit installYou can run pre-commit manually on all files with:
pre-commit run --all-filespre-commit will automatically run on every commit, ensuring that your code
adheres to the specified style and quality checks.
To add additional hooks, you can modify the .pre-commit-config.yaml file.
For more details on configuring pre-commit hooks, refer to the
official pre-commit documentation.
The most important hook for our project is the golangci-lint hook. It enforces
the Go code style and checks for common mistakes. It is configured in the
.golangci.yml file. To see the available linters, refer to the golangci-lint
documentation.
If you receive a comment on a PR that could have been caught by a linter and
fixed automatically, consider searching for a pre-commit hook or golangci-lint
linter that could have caught the issue. If you find one, please add it to the
.pre-commit-config.yaml file and the .golangci.yml file. This will help ensure
that the issue is caught in the future and that the code adheres to the
specified style and quality checks.
- Go 1.24 or later
- Docker
- Make
The rest of the utilities are installed automatically by the Makefile.
To build the project, run:
make buildThis will compile the project and place the binary in the bin directory.
./bin/local-csi-driver --versionTo build the Docker image, run:
REGISTRY=<your registry> make docker-buildSubstitute <your registry> with the desired Docker registry. This will build the
Docker image and tag it with the specified registry.
REGISTRY=<your registry> make docker-pushThis will push the Docker image to the specified registry. You will often run these two commands together, so you can combine them into one command:
REGISTRY=<your registry> make docker-build docker-pushTo build the Helm chart, run:
make helm-buildThis will package a helm chart for the project and place it in the dist
directory.
Some development can be done in a local Kubernetes cluster. To create a local Kubernetes cluster, you can use kind. To create a local cluster, run:
make singleThis will create a local Kubernetes cluster using kind. You can then use this cluster to test the project. To delete the cluster, run:
make cleanMost of the development is done in an AKS cluster. To create an AKS cluster,
you can use the make target aks. The AKS cluster is created using bicep.
To create a cluster, run:
make aksFor more details on the bicep template and available parameters, refer to the deploy/README.md file.
Build and push the Docker image and Helm chart to your registry and Helm repository, respectively. You can do this with:
REGISTRY=<registry> make docker-build helm-build docker-push helm-pushTo deploy the project to your Kubernetes cluster, you can call all the make targets in one command:
REGISTRY=<registry> make docker-build helm-build docker-push helm-push helm-installThis will build the Docker image, push it to the specified registry, build the Helm chart, push it to the specified Helm repository, and install the project to your Kubernetes cluster.
To uninstall the project from your Kubernetes cluster, run:
make helm-uninstallThis will remove the project from your cluster.
The project has a number of tests that can be run to ensure that the project is working correctly. The tests are divided into categories: unit tests, E2E tests, External E2E tests, and sanity tests. The tests are written in Go.
Generally, if something can be tested with a unit test, it should be. If
something is too complex to test with a unit test, it should be tested with an
E2E test. The sanity and external E2E tests are conformance tests provided by
the Kubernetes community to test CSI drivers. For more details on the tests,
refer to the test/README.md file. Unit tests can be found throughout
the project, but other tests are located in the test directory.
To run the unit tests, run:
make testThis will run all the unit tests in the project.
These tests are run in a Kubernetes cluster. To run the E2E tests, you need to set up a Kubernetes cluster and install the project in it. You can do this with:
REGISTRY=<registry>.azurecr.io make docker-build helm-build docker-push helm-push test-e2eThose tests that are part of e2e suite are run in the cluster. The tests are
written in Go and use the Ginkgo testing framework. The tests are located in the
test/e2e directory. By default, the test-e2e test target will include tests
that we can run in a kind cluster. If you have a real AKS cluster, you can run
the tests
REGISTRY=<registry>.azurecr.io make docker-build helm-build docker-push helm-push test-e2e-aksThis will run the E2E tests in the AKS cluster. The tests are written in Go and are chosen with the "aks" and "e2e" label selectors.
You can also run the E2E tests in a local Kubernetes cluster using kind. To do
this, you need to install kind and create a local cluster. You can do this
with:
make singleNote: Most of the tests are skipped in this mode, as they require a real aks cluster to run.
To run the external E2E tests, you need to set up a Kubernetes cluster and install the project in it. You can do this with:
REGISTRY=<registry>.azurecr.io make docker-build helm-build docker-push helm-push test-e2e-aksThis will run the external E2E tests in the cluster using the AKS cluster. The
tests are written in Go and use the Ginkgo testing framework. There are two
kinds of tests, the lvm and lvm-annotation tests.
The lvm tests only run the generic ephemeral volume tests, which is the only
kind of volume permitted by default by the driver. The lvm-annotation tests
run all the tests specified by the external tests.
It uses kyverno to add the
localdisk.csi.acstor.io/accept-ephemeral-storage: "true" annotation to the
persistent volume claim. This allows the tests to test the
"accept-ephemeral-storage" mode of the driver. The tests are located in the
test/e2e/external directory.
To run the sanity tests, run:
REGISTRY=<registry>.azurecr.io make docker-build helm-build docker-push helm-push test-sanityThe sanity tests are conformance tests that checks if the driver adheres to the
csi spec. The tests are written in Go and use the Ginkgo testing framework. The
implementation can be found in the kubernetes-csi/csi-test repo.
The tests are located in the test/sanity directory.
The tests are run on an AKS cluster. If you find a change that you made that
breaks the tests, please refer to the
container-storage-interface/spec repo to review the spec.