Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: add make verify #91

Merged
merged 1 commit into from
Nov 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 72 additions & 6 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,72 @@
/bin

# This is where the result of the go build goes
/output*/
/_output*/
/_output
# 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
7 changes: 7 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion hack/boilerplate/boilerplate.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
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)
Expand Down
7 changes: 3 additions & 4 deletions hack/release-image.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
12 changes: 10 additions & 2 deletions hack/verify-boilerplate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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)"
Expand All @@ -40,4 +46,6 @@ if [[ ${#files_need_boilerplate[@]} -gt 0 ]]; then
done

exit 1
fi
fi

echo "Done"
3 changes: 3 additions & 0 deletions hack/verify-golint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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."
1 change: 1 addition & 0 deletions hack/verify-gomod.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

set -euo pipefail

echo "Verifying gomod"
export GO111MODULE=on
echo "go mod tidy"
go mod tidy
Expand Down
37 changes: 24 additions & 13 deletions hack/verify-helm-chart.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
}

Expand All @@ -37,33 +37,44 @@ 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}"

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."
20 changes: 19 additions & 1 deletion hack/verify-yamllint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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."
19 changes: 19 additions & 0 deletions pkg/nfs/controllerserver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
Expand Down