From d4e4b79b555f5dcd83e621e87a2cee84a3468faa Mon Sep 17 00:00:00 2001 From: Sergey Aksenov Date: Fri, 13 Oct 2023 13:56:49 +0200 Subject: [PATCH] Running `make test` locally using `minio` & `minikube` fixed (#2379) * fix for running tests locally Signed-off-by: Sergey Aksenov * A `ERROR: Cannot connect to the Docker daemon at unix:///path_to_socket. Is the docker daemon running?` error fixed Signed-off-by: Sergey Aksenov * fixed failing of some test after running `make test` within local environment Signed-off-by: Sergey Aksenov * review comments fixed Signed-off-by: Sergey Aksenov --------- Signed-off-by: Sergey Aksenov --- build/local_kubernetes.sh | 48 ++++++++++++++++++++++++++++++++------- build/run_container.sh | 11 ++++++++- build/test.sh | 11 +++++++++ 3 files changed, 61 insertions(+), 9 deletions(-) diff --git a/build/local_kubernetes.sh b/build/local_kubernetes.sh index 97cc28c9d2..933ef22100 100755 --- a/build/local_kubernetes.sh +++ b/build/local_kubernetes.sh @@ -73,14 +73,43 @@ install_csi_hostpath_driver() { kubectl apply -fhttps://raw.githubusercontent.com/kubernetes-csi/external-snapshotter/${SNAPSHOTTER_VERSION}/deploy/kubernetes/snapshot-controller/{rbac-snapshot-controller.yaml,setup-snapshot-controller.yaml} # Deploy the CSI Hostpath Driver - cd /tmp - git clone https://github.com/kubernetes-csi/csi-driver-host-path.git - cd csi-driver-host-path - sed -i 's/mountPropagation: Bidirectional/\#mountPropagation: Bidirectional/g' deploy/kubernetes-latest/hostpath/csi-hostpath-plugin.yaml - ./deploy/kubernetes-latest/deploy.sh - - # Create StorageClass - kubectl apply -f ./examples/csi-storageclass.yaml + pushd /tmp + git clone https://github.com/kubernetes-csi/csi-driver-host-path.git + pushd csi-driver-host-path + sed -i 's/mountPropagation: Bidirectional/\#mountPropagation: Bidirectional/g' deploy/kubernetes-latest/hostpath/csi-hostpath-plugin.yaml + + ./deploy/kubernetes-latest/deploy.sh + + # Create StorageClass + kubectl apply -f ./examples/csi-storageclass.yaml + popd + popd +} + +check_csi_hostpath_driver_installed() { + # Check VolumeSnapshot CRDs are installed + if ! kubectl diff -fhttps://raw.githubusercontent.com/kubernetes-csi/external-snapshotter/${SNAPSHOTTER_VERSION}/client/config/crd/snapshot.storage.k8s.io_{volumesnapshots.yaml,volumesnapshotclasses.yaml,volumesnapshotcontents.yaml} 2>&1 > /dev/null ; then + echo "VolumeSnapshot CRDs are not installed." + exit 1 + fi + + # Check snapshot controller created + if ! kubectl diff -fhttps://raw.githubusercontent.com/kubernetes-csi/external-snapshotter/${SNAPSHOTTER_VERSION}/deploy/kubernetes/snapshot-controller/{rbac-snapshot-controller.yaml,setup-snapshot-controller.yaml} 2>&1 > /dev/null ; then + echo "Snapshot controller is not created." + exit 1 + fi + + # Deploy the CSI Hostpath Driver + pushd /tmp + git clone https://github.com/kubernetes-csi/csi-driver-host-path.git + pushd csi-driver-host-path + # Check StorageClass created + if ! kubectl diff -f ./examples/csi-storageclass.yaml 2>&1 > /dev/null ; then + echo "StorageClass is not created." + exit 1 + fi + popd + popd } stop_localkube() { @@ -158,6 +187,9 @@ EOM check_or_get_dependencies case "${1}" in # Alphabetically sorted + check_csi_hostpath_driver_installed) + time -p check_csi_hostpath_driver_installed + ;; get_localkube) time -p get_localkube ;; diff --git a/build/run_container.sh b/build/run_container.sh index 10b8142bb9..2bb1212b04 100755 --- a/build/run_container.sh +++ b/build/run_container.sh @@ -49,19 +49,28 @@ run_build_container() { cmd=(/bin/bash) fi + # In case of `minikube`, kube config stores full path to a certificates, + # thus the simples way to get working minikube in the build container is + # to bind original path to minikube settings to the container. + local minikube_dir_path="${HOME}/.minikube" + local minikube_dir_binding="-v ${minikube_dir_path}:${minikube_dir_path}" + if [ ! -d "${minikube_dir_path}" ]; then + minikube_dir_binding="" + fi + docker run \ --platform ${PLATFORM} \ ${extra_params} \ --rm \ --net host \ -e GITHUB_TOKEN="${github_token}" \ + ${minikube_dir_binding} \ -v "${HOME}/.kube:/root/.kube" \ -v "${PWD}/.go/pkg:/go/pkg" \ -v "${PWD}/.go/cache:/go/.cache" \ -v "${PWD}:/go/src/${PKG}" \ -v "${PWD}/bin/${ARCH}:/go/bin" \ -v "${PWD}/.go/std/${ARCH}:/usr/local/go/pkg/linux_${ARCH}" \ - -v "${HOME}/.docker:/root/.docker" \ -v /var/run/docker.sock:/var/run/docker.sock \ -w /go/src/${PKG} \ ${BUILD_IMAGE} \ diff --git a/build/test.sh b/build/test.sh index ebdaa39e45..8938956d27 100755 --- a/build/test.sh +++ b/build/test.sh @@ -19,6 +19,7 @@ set -o errexit set -o nounset +SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" export CGO_ENABLED=0 export GO111MODULE=on @@ -63,9 +64,19 @@ check_dependencies() { echo "Please install MinIO using 'make install-minio' and try again." exit 1 fi + + # A test (CRDSuite) that runs as part of `make test` requires at least one CRD to + # be present on the cluster. That's why we are checking that `csi-hostpath-driver` + # installed before running tests. + if ! ${SCRIPT_DIR}/local_kubernetes.sh check_csi_hostpath_driver_installed ; then + echo "CRDs are not installed on the cluster but a test (CRDSuite) requires at least one CRD to be available on the cluster."\ + " One can be installed by running 'make install-csi-hostpath-driver' command." + exit 1 + fi } check_dependencies + echo "Running tests:" go test -v -installsuffix "static" -i ${TARGETS} go test -v ${TARGETS} -list .