Skip to content

Commit

Permalink
Running make test locally using minio & minikube fixed (#2379)
Browse files Browse the repository at this point in the history
* fix for running tests locally

Signed-off-by: Sergey Aksenov <sergey.aksenov@veeam.com>

* 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 <sergey.aksenov@veeam.com>

* fixed failing of some test after running `make test` within local environment

Signed-off-by: Sergey Aksenov <sergey.aksenov@veeam.com>

* review comments fixed

Signed-off-by: Sergey Aksenov <sergey.aksenov@veeam.com>

---------

Signed-off-by: Sergey Aksenov <sergey.aksenov@veeam.com>
  • Loading branch information
k0taperk0t committed Oct 13, 2023
1 parent 6232108 commit d4e4b79
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 9 deletions.
48 changes: 40 additions & 8 deletions build/local_kubernetes.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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
;;
Expand Down
11 changes: 10 additions & 1 deletion build/run_container.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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} \
Expand Down
11 changes: 11 additions & 0 deletions build/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 .
Expand Down

0 comments on commit d4e4b79

Please sign in to comment.