diff --git a/Makefile b/Makefile index 2894d434c..7151d1f02 100644 --- a/Makefile +++ b/Makefile @@ -204,11 +204,15 @@ k8s_codegen: k8s_codegen_operator: cd operator && $(MAKE) k8s_codegen +.git/hooks: + mkdir -p $@ + +.PHONY: install-lint lint-precommit lint-prepush install-lint: curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(shell go env GOPATH)/bin ${GOLANGCI-LINT_VERSION} -lint-precommit: install-lint +lint-precommit: .git/hooks install-lint cp hooks/golangci-lint.sh .git/hooks/pre-commit -lint-prepush: install-lint .git/hooks/pre-push +lint-prepush: .git/hooks install-lint .git/hooks/pre-push cp hooks/golangci-lint.sh .git/hooks/pre-push diff --git a/hooks/golangci-lint.sh b/hooks/golangci-lint.sh index 0990a716f..5fc771769 100755 --- a/hooks/golangci-lint.sh +++ b/hooks/golangci-lint.sh @@ -1,18 +1,19 @@ #!/bin/sh # find staged files that end in .go -STAGED_GO_FILES=$(git diff --cached --name-only | grep ".go$") +STAGED_GO_DIRS=$(git diff --cached --name-only | grep ".go$" | xargs dirname) +GO_PACKAGE_DIRS=($(echo "${STAGED_GO_DIRS}" | tr ' ' '\n' | sort -u | tr '\n' ' ')) # if nothing, don't lint. hook successful. -if [ "$STAGED_GO_FILES" = "" ]; then +if [ "$STAGED_GO_DIRS" = "" ]; then exit 0 fi PASS=true -for FILE in $STAGED_GO_FILES +for DIR in $GO_PACKAGE_DIRS do # This is where we will be testing each of our files. - golangci-lint run -E goimports --fix $FILE + golangci-lint run -E goimports $DIR if [ $? != 0 ]; then PASS=false fi diff --git a/scripts/delete.sh b/scripts/delete.sh deleted file mode 100755 index f0e6b3bdd..000000000 --- a/scripts/delete.sh +++ /dev/null @@ -1,29 +0,0 @@ -#!/bin/bash - -TRIDENT_PORT=8000 - -if [ -z "$TRIDENT_IP" ] -then - export TRIDENT_IP=`kubectl describe pod --selector=app=trident.netapp.io 2>/dev/null | grep ^IP | awk -F' ' '{print $NF}'` -fi -if [ -z "$TRIDENT_IP" ] -then - TRIDENT_IP=$(docker ps -a 2>/dev/null | awk '{print $1,$2}' | grep trident | awk '{print $1}' | xargs -I {} docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' {}) -fi -if [ -z "$TRIDENT_IP" ] -then - >&2 echo "Unable to discover Trident IP. Either Trident is not running or its IP address must be manually set at \$TRIDENT_IP." - exit 1 -fi - -if [ $# -ne 2 ] -then - >&2 echo "Usage: $0 " - >&2 echo "resource-type: Type of resource; either 'volume', 'backend', or 'storageclass'. Required." - >&2 echo "resource-name: Specific resource to delete. Required." - exit 1 -fi - -echo "curl -XDELETE -s -S -D - ${TRIDENT_IP}:${TRIDENT_PORT}/trident/v1/${1}/${2}" -echo -curl -XDELETE -s -S -D - ${TRIDENT_IP}:${TRIDENT_PORT}/trident/v1/${1}/${2} diff --git a/scripts/get.sh b/scripts/get.sh deleted file mode 100755 index af02c4fb0..000000000 --- a/scripts/get.sh +++ /dev/null @@ -1,34 +0,0 @@ -#!/bin/bash - -TRIDENT_PORT=8000 - -if [ -z "$TRIDENT_IP" ] -then - export TRIDENT_IP=`kubectl describe pod --selector=app=trident.netapp.io 2>/dev/null | grep ^IP | awk -F' ' '{print $NF}'` -fi -if [ -z "$TRIDENT_IP" ] -then - TRIDENT_IP=$(docker ps -a 2>/dev/null | awk '{print $1,$2}' | grep trident | awk '{print $1}' | xargs -I {} docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' {}) -fi -if [ -z "$TRIDENT_IP" ] -then - >&2 echo "Unable to discover Trident IP. Either Trident is not running or its IP address must be manually set at \$TRIDENT_IP." - exit 1 -fi - -if [ $# -eq 1 ] -then - echo "curl -s -S -D - ${TRIDENT_IP}:${TRIDENT_PORT}/trident/v1/${1}" - echo - curl -s -S -D - ${TRIDENT_IP}:${TRIDENT_PORT}/trident/v1/${1} -elif [ $# -eq 2 ] -then - echo "curl -s -S -D - ${TRIDENT_IP}:${TRIDENT_PORT}/trident/v1/${1}/${2}" - echo - curl -s -S -D - ${TRIDENT_IP}:${TRIDENT_PORT}/trident/v1/${1}/${2} -else - >&2 echo "Usage: $0 " - >&2 echo "resource-type: Type of resource; either 'volume', 'backend', or 'storageclass'. Required." - >&2 echo "resource-name: name of specific resource. Optional." - exit 1 -fi diff --git a/scripts/json-get.sh b/scripts/json-get.sh deleted file mode 100755 index 6fd6dd5eb..000000000 --- a/scripts/json-get.sh +++ /dev/null @@ -1,30 +0,0 @@ -#!/bin/bash - -TRIDENT_PORT=8000 - -if [ -z "$TRIDENT_IP" ] -then - export TRIDENT_IP=`kubectl describe pod --selector=app=trident.netapp.io 2>/dev/null | grep ^IP | awk -F' ' '{print $NF}'` -fi -if [ -z "$TRIDENT_IP" ] -then - TRIDENT_IP=$(docker ps -a 2>/dev/null | awk '{print $1,$2}' | grep trident | awk '{print $1}' | xargs -I {} docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' {}) -fi -if [ -z "$TRIDENT_IP" ] -then - >&2 echo "Unable to discover Trident IP. Either Trident is not running or its IP address must be manually set at \$TRIDENT_IP." - exit 1 -fi - -if [ $# -eq 1 ] -then - curl -s -S ${TRIDENT_IP}:${TRIDENT_PORT}/trident/v1/${1} | jq '.' -elif [ $# -eq 2 ] -then - curl -s -S ${TRIDENT_IP}:${TRIDENT_PORT}/trident/v1/${1}/${2} | jq '.' -else - >&2 echo "Usage: $0 " - >&2 echo "resource-type: either 'volume' or 'backend'. Required." - >&2 echo "resource-name: name of specific resource. Optional." - exit 1 -fi diff --git a/scripts/post.sh b/scripts/post.sh deleted file mode 100755 index 0b491884b..000000000 --- a/scripts/post.sh +++ /dev/null @@ -1,29 +0,0 @@ -#!/bin/bash - -TRIDENT_PORT=8000 - -if [ -z "$TRIDENT_IP" ] -then - export TRIDENT_IP=`kubectl describe pod --selector=app=trident.netapp.io 2>/dev/null | grep ^IP | awk -F' ' '{print $NF}'` -fi -if [ -z "$TRIDENT_IP" ] -then - TRIDENT_IP=$(docker ps -a 2>/dev/null | awk '{print $1,$2}' | grep trident | awk '{print $1}' | xargs -I {} docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' {}) -fi -if [ -z "$TRIDENT_IP" ] -then - >&2 echo "Unable to discover Trident IP. Either Trident is not running or its IP address must be manually set at \$TRIDENT_IP." - exit 1 -fi - -if [ $# -ne 1 ] -then - >&2 echo "Usage: $0 " - >&2 echo "resource-type: Type of resource; either 'volume', 'backend', or 'storageclass'. Required." - >&2 echo "Provide JSON description of resource to POST on stdin." - exit 1 -fi - -echo "curl -XPOST -s -S -D - ${TRIDENT_IP}:${TRIDENT_PORT}/trident/v1/${1} -d @-" -echo -curl -XPOST -s -S -D - ${TRIDENT_IP}:${TRIDENT_PORT}/trident/v1/${1} -d @-