Repository: kubernetes-csi/csi-driver-nfs
Pull request #91 (2020-11-16 20:40:04)

test: add make verify
<!--  Thanks for sending a pull request!  Here are some tips for you:

1. If this is your first time, please read our contributor guidelines: https://git.k8s.io/community/contributors/guide#your-first-contribution and developer guide https://git.k8s.io/community/contributors/devel/development.md#development-guide
2. Follow the instructions for writing a release note: https://git.k8s.io/community/contributors/guide/release-notes.md
3. If the PR is unfinished, see how to mark it: https://git.k8s.io/community/contributors/guide/pull-requests.md#marking-unfinished-pull-requests
-->

**What type of PR is this?**
> Uncomment only one ` /kind <>` line, hit enter to put that in a new line, and remove leading whitespaces from that line:
>
> /kind api-change
> /kind bug
> /kind cleanup
> /kind design
> /kind documentation
> /kind failing-test
> /kind feature
> /kind flake

/kind failing-test

**What this PR does / why we need it**:
Add make verify.
Add tear down for unit tests.
Fix hack scripts.
**NOTE**: `make verify` will fail and they are not fixed in this PR because there are too many issues. I will address these issues in another PR.

**Which issue(s) this PR fixes**:
<!--
*Automatically closes linked issue when PR is merged.
Usage: `Fixes #<issue number>`, or `Fixes (paste link of issue)`.
_If PR is about `failing-tests or flakes`, please post the related issues/tests in a comment and do not use `Fixes`_*
-->
Fixes #

**Special notes for your reviewer**:

**Does this PR introduce a user-facing change?**:
<!--
If no, just write "NONE" in the release-note block below.
If yes, a release note is required:
Enter your extended release note in the block below. If the PR requires additional action from users switching to the new release, include the string "action required".
-->
```release-note
None
```



Patch:
diff --git a/.gitignore b/.gitignore
index 2626f83a..1a35a551 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,6 +1,72 @@
-/bin
-
-# This is where the result of the go build goes
-/output*/
-/_output*/
-/_output
\ No newline at end of file
+# OSX leaves these everywhere on SMB shares
+._*
+
+# OSX trash
+.DS_Store
+
+# Eclipse files
+.classpath
+.project
+.settings/**
+
+# Files generated by JetBrains IDEs, e.g. IntelliJ IDEA
+.idea/
+*.iml
+
+# Vscode files
+.vscode
+
+# This is where the result of the go build goes
+/output*/
+/_output*/
+/_output
+/bin
+
+# Emacs save files
+*~
+\#*\#
+.\#*
+
+# Vim-related files
+[._]*.s[a-w][a-z]
+[._]s[a-w][a-z]
+*.un~
+Session.vim
+.netrwhist
+
+# cscope-related files
+cscope.*
+
+# Go test binaries
+*.test
+
+# JUnit test output from ginkgo e2e tests
+/junit*.xml
+
+# Mercurial files
+**/.hg
+**/.hg*
+
+# Vagrant
+.vagrant
+
+.tags*
+
+# Test artifacts produced by Jenkins jobs
+/_artifacts/
+
+# Go dependencies installed on Jenkins
+/_gopath/
+
+# direnv .envrc files
+.envrc
+
+# This file used by some vendor repos (e.g. github.com/go-openapi/...) to store secret variables and should not be ignored
+!\.drone\.sec
+
+# Godeps or dep workspace
+/Godeps/_workspace
+
+/bazel-*
+*.pyc
+profile.cov
diff --git a/Makefile b/Makefile
index 82cea89a..8a49917d 100644
--- a/Makefile
+++ b/Makefile
@@ -39,6 +39,13 @@ LDFLAGS = "-X ${PKG}/pkg/nfs.driverVersion=${IMAGE_VERSION} -s -w -extldflags '-
 
 all: nfs
 
+.PHONY: verify
+verify: unit-test
+	hack/verify-all.sh
+
+.PHONY: unit-test
+unit-test:
+	go test -covermode=count -coverprofile=profile.cov ./pkg/... -v
 
 .PHONY: sanity-test
 sanity-test: nfs
diff --git a/hack/boilerplate/boilerplate.py b/hack/boilerplate/boilerplate.py
index 07373f70..63f74963 100755
--- a/hack/boilerplate/boilerplate.py
+++ b/hack/boilerplate/boilerplate.py
@@ -38,7 +38,7 @@ rootdir = os.path.abspath(rootdir)
 parser.add_argument(
     "--rootdir", default=rootdir, help="root directory to examine")
 
-default_boilerplate_dir = os.path.join(rootdir, "csi-driver-smb/hack/boilerplate")
+default_boilerplate_dir = os.path.join(rootdir, "csi-driver-nfs/hack/boilerplate")
 
 parser.add_argument(
     "--boilerplate-dir", default=default_boilerplate_dir)
diff --git a/hack/release-image.sh b/hack/release-image.sh
index 8b0e9686..a272656d 100755
--- a/hack/release-image.sh
+++ b/hack/release-image.sh
@@ -23,16 +23,15 @@ fi
 
 export REGISTRY_NAME="$1"
 export REGISTRY=$REGISTRY_NAME.azurecr.io
-export IMAGE_NAME=public/k8s/csi/smb-csi
+export IMAGE_NAME=gcr.io/k8s-staging-sig-storage/nfsplugin
 export CI=1
 export PUBLISH=1
 az acr login --name $REGISTRY_NAME
-make smb-container
+make container
 make push
-make push-latest
 
 echo "sleep 60s ..."
 sleep 60
-image="mcr.microsoft.com/k8s/csi/smb-csi:latest"
+image="gcr.io/k8s-staging-sig-storage/nfsplugin:latest"
 docker pull $image
 docker inspect $image | grep Created
diff --git a/hack/verify-boilerplate.sh b/hack/verify-boilerplate.sh
index 8e14b35d..70aa0d22 100755
--- a/hack/verify-boilerplate.sh
+++ b/hack/verify-boilerplate.sh
@@ -18,13 +18,19 @@ set -o errexit
 set -o nounset
 set -o pipefail
 
+echo "Verifying boilerplate"
+
+if [[ -z "$(command -v python)" ]]; then
+  echo "Cannot find python. Make link to python3..."
+  update-alternatives --install /usr/bin/python python /usr/bin/python3 1
+fi
 
 REPO_ROOT=$(dirname "${BASH_SOURCE}")/..
 
 boilerDir="${REPO_ROOT}/hack/boilerplate"
 boiler="${boilerDir}/boilerplate.py"
 
-files_need_boilerplate=($(${boiler} --rootdir=${REPO_ROOT}))
+files_need_boilerplate=($(${boiler} --rootdir=${REPO_ROOT} --verbose))
 
 # Run boilerplate.py unit tests
 unitTestOut="$(mktemp)"
@@ -40,4 +46,6 @@ if [[ ${#files_need_boilerplate[@]} -gt 0 ]]; then
   done
 
   exit 1
-fi
\ No newline at end of file
+fi
+
+echo "Done"
diff --git a/hack/verify-golint.sh b/hack/verify-golint.sh
index 11d791fc..81fc83fb 100755
--- a/hack/verify-golint.sh
+++ b/hack/verify-golint.sh
@@ -19,8 +19,11 @@ set -euo pipefail
 if [[ -z "$(command -v golangci-lint)" ]]; then
   echo "Cannot find golangci-lint. Installing golangci-lint..."
   curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.31.0
+  export PATH=$PATH:$(go env GOPATH)/bin
 fi
 
+echo "Verifying golint"
+
 golangci-lint run --no-config --enable=golint --disable=typecheck --deadline=10m
 
 echo "Congratulations! Lint check completed for all Go source files."
diff --git a/hack/verify-gomod.sh b/hack/verify-gomod.sh
index 6a0b7dbb..d45a265d 100755
--- a/hack/verify-gomod.sh
+++ b/hack/verify-gomod.sh
@@ -16,6 +16,7 @@
 
 set -euo pipefail
 
+echo "Verifying gomod"
 export GO111MODULE=on
 echo "go mod tidy"
 go mod tidy
diff --git a/hack/verify-helm-chart.sh b/hack/verify-helm-chart.sh
index b8478682..cf066834 100755
--- a/hack/verify-helm-chart.sh
+++ b/hack/verify-helm-chart.sh
@@ -20,8 +20,8 @@ readonly PKG_ROOT="$(git rev-parse --show-toplevel)"
 
 function get_image_from_helm_chart() {
   local -r image_name="${1}"
-  image_repository="$(cat ${PKG_ROOT}/charts/latest/csi-driver-smb/values.yaml | yq -r .image.${image_name}.repository)"
-  image_tag="$(cat ${PKG_ROOT}/charts/latest/csi-driver-smb/values.yaml | yq -r .image.${image_name}.tag)"
+  image_repository="$(cat ${PKG_ROOT}/charts/latest/csi-driver-nfs/values.yaml | yq -r .image.${image_name}.repository)"
+  image_tag="$(cat ${PKG_ROOT}/charts/latest/csi-driver-nfs/values.yaml | yq -r .image.${image_name}.tag)"
   echo "${image_repository}:${image_tag}"
 }
 
@@ -37,13 +37,24 @@ function validate_image() {
 
 echo "Comparing image version between helm chart and manifests in deploy folder"
 
+if [[ -z "$(command -v pip)" ]]; then
+  echo "Cannot find pip. Installing pip3..."
+  apt install python3-pip -y
+  update-alternatives --install /usr/bin/pip pip /usr/bin/pip3 1
+fi
+
+if [[ -z "$(command -v jq)" ]]; then
+  echo "Cannot find jq. Installing yq..."
+  apt install jq -y
+fi
+
 # jq-equivalent for yaml
 pip install yq
 
-# Extract images from csi-smb-controller.yaml
-expected_csi_provisioner_image="$(cat ${PKG_ROOT}/deploy/csi-smb-controller.yaml | yq -r .spec.template.spec.containers[0].image | head -n 1)"
-expected_liveness_probe_image="$(cat ${PKG_ROOT}/deploy/csi-smb-controller.yaml | yq -r .spec.template.spec.containers[1].image | head -n 1)"
-expected_smb_image="$(cat ${PKG_ROOT}/deploy/csi-smb-controller.yaml | yq -r .spec.template.spec.containers[2].image | head -n 1)"
+# Extract images from csi-nfs-controller.yaml
+expected_csi_provisioner_image="$(cat ${PKG_ROOT}/deploy/csi-nfs-controller.yaml | yq -r .spec.template.spec.containers[0].image | head -n 1)"
+expected_liveness_probe_image="$(cat ${PKG_ROOT}/deploy/csi-nfs-controller.yaml | yq -r .spec.template.spec.containers[1].image | head -n 1)"
+expected_nfs_image="$(cat ${PKG_ROOT}/deploy/csi-nfs-controller.yaml | yq -r .spec.template.spec.containers[2].image | head -n 1)"
 
 csi_provisioner_image="$(get_image_from_helm_chart "csiProvisioner")"
 validate_image "${expected_csi_provisioner_image}" "${csi_provisioner_image}"
@@ -51,19 +62,19 @@ validate_image "${expected_csi_provisioner_image}" "${csi_provisioner_image}"
 liveness_probe_image="$(get_image_from_helm_chart "livenessProbe")"
 validate_image "${expected_liveness_probe_image}" "${liveness_probe_image}"
 
-smb_image="$(get_image_from_helm_chart "smb")"
-validate_image "${expected_smb_image}" "${smb_image}"
+nfs_image="$(get_image_from_helm_chart "nfs")"
+validate_image "${expected_nfs_image}" "${nfs_image}"
 
-# Extract images from csi-smb-node.yaml
-expected_liveness_probe_image="$(cat ${PKG_ROOT}/deploy/csi-smb-node.yaml | yq -r .spec.template.spec.containers[0].image | head -n 1)"
-expected_node_driver_registrar="$(cat ${PKG_ROOT}/deploy/csi-smb-node.yaml | yq -r .spec.template.spec.containers[1].image | head -n 1)"
-expected_smb_image="$(cat ${PKG_ROOT}/deploy/csi-smb-node.yaml | yq -r .spec.template.spec.containers[2].image | head -n 1)"
+# Extract images from csi-nfs-node.yaml
+expected_liveness_probe_image="$(cat ${PKG_ROOT}/deploy/csi-nfs-node.yaml | yq -r .spec.template.spec.containers[0].image | head -n 1)"
+expected_node_driver_registrar="$(cat ${PKG_ROOT}/deploy/csi-nfs-node.yaml | yq -r .spec.template.spec.containers[1].image | head -n 1)"
+expected_nfs_image="$(cat ${PKG_ROOT}/deploy/csi-nfs-node.yaml | yq -r .spec.template.spec.containers[2].image | head -n 1)"
 
 validate_image "${expected_liveness_probe_image}" "${liveness_probe_image}"
 
 node_driver_registrar="$(get_image_from_helm_chart "nodeDriverRegistrar")"
 validate_image "${expected_node_driver_registrar}" "${node_driver_registrar}"
 
-validate_image "${expected_smb_image}" "${smb_image}"
+validate_image "${expected_nfs_image}" "${nfs_image}"
 
 echo "Images in deploy/ matches those in the latest helm chart."
diff --git a/hack/verify-yamllint.sh b/hack/verify-yamllint.sh
index 324c7619..2f64bcc2 100755
--- a/hack/verify-yamllint.sh
+++ b/hack/verify-yamllint.sh
@@ -19,8 +19,17 @@ if [[ -z "$(command -v yamllint)" ]]; then
 fi
 
 LOG=/tmp/yamllint.log
+helmPath=charts/latest/csi-driver-nfs/templates
 
-for path in "deploy/*.yaml" "deploy/example/*.yaml" "deploy/example/windows/*.yaml" "deploy/example/smb-provisioner/*.yaml" "deploy/example/metrics/*.yaml"
+echo "checking yaml files num ..."
+deployDirNum=`ls deploy/*.yaml | wc -l`
+helmDirNum=`ls $helmPath/*.yaml | grep -v serviceaccount | wc -l`
+if [[ "${deployDirNum}" != "${helmDirNum}" ]]; then
+  echo "yaml file num($deployDirNum) under deploy/ not equal to num($helmDirNum) under $helmPath"
+  exit 1
+fi
+
+for path in "deploy/*.yaml"
 do
     echo "checking yamllint under path: $path ..."
     yamllint -f parsable $path | grep -v "line too long" > $LOG
@@ -33,4 +42,13 @@ do
     fi
 done
 
+echo "checking yamllint under path: $helmPath ..."
+yamllint -f parsable $helmPath/*.yaml | grep -v "line too long" | grep -v "too many spaces inside braces" | grep -v "missing document start" | grep -v "syntax error" > $LOG
+linecount=`cat $LOG | wc -l`
+if [ $linecount -gt 0 ]; then
+	echo "yaml files under $helmPath/ are not linted, failed with: "
+	cat $LOG
+	exit 1
+fi
+
 echo "Congratulations! All Yaml files have been linted."


Test patch:
diff --git a/pkg/nfs/controllerserver_test.go b/pkg/nfs/controllerserver_test.go
index 4a74e054..de946e7a 100644
--- a/pkg/nfs/controllerserver_test.go
+++ b/pkg/nfs/controllerserver_test.go
@@ -6,6 +6,7 @@ import (
 	"reflect"
 	"testing"
 
+	"fmt"
 	"github.com/container-storage-interface/spec/lib/go/csi"
 	"golang.org/x/net/context"
 	"k8s.io/utils/mount"
@@ -31,6 +32,24 @@ func initTestController(t *testing.T) *ControllerServer {
 	return NewControllerServer(driver)
 }
 
+func teardown() {
+	err := os.RemoveAll("/tmp/" + testCSIVolume)
+
+	if err != nil {
+		fmt.Printf(err.Error())
+		fmt.Printf("\n")
+		fmt.Printf("\033[1;91m%s\033[0m\n", "> Teardown failed")
+	} else {
+		fmt.Printf("\033[1;36m%s\033[0m\n", "> Teardown completed")
+	}
+}
+
+func TestMain(m *testing.M) {
+	code := m.Run()
+	teardown()
+	os.Exit(code)
+}
+
 func TestCreateVolume(t *testing.T) {
 	cases := []struct {
 		name      string