diff --git a/.github/workflows/windows.yml b/.github/workflows/windows.yml index 061a502c..988aed7c 100644 --- a/.github/workflows/windows.yml +++ b/.github/workflows/windows.yml @@ -14,18 +14,8 @@ jobs: go-version: ${{ matrix.go-version }} - name: Checkout code uses: actions/checkout@v2 - - name: Build - run: | - go build -v -a -o ./bin/csi-proxy.exe ./cmd/csi-proxy - name: Run Windows Integration Tests run: | - # start the CSI Proxy before running tests on windows - Start-Job -Name CSIProxy -ScriptBlock { - .\bin\csi-proxy.exe - }; - Start-Sleep -Seconds 30; - Write-Output "getting named pipes" - [System.IO.Directory]::GetFiles("\\.\\pipe\\") $env:CSI_PROXY_GH_ACTIONS="TRUE" go test -v -race ./integrationtests/... unit_tests: diff --git a/Makefile b/Makefile index ce9c0d38..0cad3f0e 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,4 @@ -CMDS=csi-proxy -all: build test +all: test # include release tools for building binary and testing targets include release-tools/build.make @@ -10,42 +9,6 @@ REPO_ROOT = $(CURDIR) BUILD_DIR = bin BUILD_TOOLS_DIR = $(BUILD_DIR)/tools GO_ENV_VARS = GO111MODULE=on GOOS=windows -CSI_PROXY_API_GEN = $(BUILD_DIR)/csi-proxy-api-gen - -.PHONY: compile-csi-proxy-api-gen -compile-csi-proxy-api-gen: - GO111MODULE=on go build -o $(CSI_PROXY_API_GEN) ./cmd/csi-proxy-api-gen - -.PHONY: generate -generate: generate-protobuf generate-csi-proxy-api-gen - -# using xargs instead of -exec since the latter doesn't propagate exit statuses -.PHONY: generate-protobuf -generate-protobuf: - @ if ! which protoc > /dev/null 2>&1; then echo 'Unable to find protoc binary' ; exit 1; fi - @ generate_protobuf_for() { \ - local FILE="$$1"; \ - local FILE_DIR="$$(dirname "$(GOPATH)/$$FILE")"; \ - echo "Generating protobuf file from $$FILE in $$FILE_DIR"; \ - protoc -I "$(GOPATH)/src/" -I '$(REPO_ROOT)/client/api' "$$FILE" --go_out=plugins="grpc:$(GOPATH)/src"; \ - } ; \ - export -f generate_protobuf_for; \ - find '$(REPO_ROOT)' -not -path './vendor/*' -name '*.proto' | sed -e "s|$(GOPATH)/src/||g" | xargs -n1 '$(SHELL)' -c 'generate_protobuf_for "$$0"' - -.PHONY: generate-csi-proxy-api-gen -generate-csi-proxy-api-gen: compile-csi-proxy-api-gen - $(CSI_PROXY_API_GEN) -i github.com/kubernetes-csi/csi-proxy/client/api,github.com/kubernetes-csi/csi-proxy/integrationtests/apigroups/api/dummy --v=8 - -.PHONY: clean -clean: clean-protobuf clean-generated - -.PHONY: clean-protobuf -clean-protobuf: - find '$(REPO_ROOT)' -name '*.proto' -exec '$(SHELL)' -c 'rm -vf "$$(dirname {})/$$(basename {} .proto).pb.go"' \; - -.PHONY: clean-generated -clean-generated: - find '$(REPO_ROOT)' -name '*_generated.go' -exec '$(SHELL)' -c '[[ "$$(head -n 1 "{}")" == "// Code generated by csi-proxy-api-gen"* ]] && rm -v {}' \; # see https://github.com/golangci/golangci-lint/releases GOLANGCI_LINT_VERSION = v1.21.0 @@ -60,17 +23,14 @@ lint: $(GOLANGCI_LINT) test: test-go test-go: @ echo; echo "### $@:" - # TODO: After issue https://github.com/microsoft/go-winio/pull/169 is resolved, remove the filter on the test path. - GO111MODULE=on go test `find ./internal/server/ -type d -not -name server`;\ - cd client && GO111MODULE=on go test `go list ./... | grep -v group` && cd ../ + GO111MODULE=on go test ./pkg/... .PHONY: test-vet test: test-vet test-vet: @ echo; echo "### $@:" - # TODO: After issue https://github.com/microsoft/go-winio/pull/169 is resolved, remove the filter on the test path. - # GO111MODULE=on go vet `find ./internal/server/ -type d -not -name server`;\ - cd client && GO111MODULE=on go vet `go list ./... | grep -v group` && cd ../ + GO111MODULE=on go vet ./pkg/... + # see https://github.com/golangci/golangci-lint#binary-release $(GOLANGCI_LINT): curl -sfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b "$$(dirname '$(GOLANGCI_LINT)')" '$(GOLANGCI_LINT_VERSION)' diff --git a/scripts/run-integration.sh b/scripts/run-integration.sh index 7cc048a9..64ac8e35 100755 --- a/scripts/run-integration.sh +++ b/scripts/run-integration.sh @@ -7,9 +7,8 @@ # - a kubernetes cluster with a Windows nodepool # # Steps: -# - cross compile the csi-proxy binary and the integration tests +# - cross compile the csi-proxy integration tests # - copy to the VM using scp -# - restart the CSI Proxy binary process with a helper powershell script # - run the integration tests set -euxo pipefail @@ -18,12 +17,8 @@ pkgdir=${GOPATH}/src/github.com/kubernetes-csi/csi-proxy source $pkgdir/scripts/utils.sh main() { - compile_csi_proxy compile_csi_proxy_integration_tests - sync_csi_proxy sync_csi_proxy_integration_tests - sync_powershell_utils - restart_csi_proxy run_csi_proxy_integration_tests } diff --git a/scripts/sync-csi-proxy.sh b/scripts/sync-csi-proxy.sh deleted file mode 100755 index 9d58a322..00000000 --- a/scripts/sync-csi-proxy.sh +++ /dev/null @@ -1,26 +0,0 @@ -#!/bin/bash - -# -# Installs CSI Proxy in a kubernetes node -# -# Requirements: -# - a kubernetes cluster with a Windows nodepool -# -# Steps: -# - cross compile the binary -# - copy to the VM using scp -# - restart the CSI Proxy binary process with a helper powershell script - -set -euxo pipefail - -pkgdir=${GOPATH}/src/github.com/kubernetes-csi/csi-proxy -source $pkgdir/scripts/utils.sh - -main() { - compile_csi_proxy - sync_csi_proxy - sync_powershell_utils - restart_csi_proxy -} - -main diff --git a/scripts/utils.psm1 b/scripts/utils.psm1 deleted file mode 100644 index 335df1d7..00000000 --- a/scripts/utils.psm1 +++ /dev/null @@ -1,41 +0,0 @@ -function Restart-CSIProxy { - # stop the csiproxy service - Get-Process csi-proxy | Stop-Process -Force - sc.exe stop csiproxy - Start-Sleep -Seconds 1; - sc.exe delete csiproxy - Start-Sleep -Seconds 1; - - # copy the binary from the user directory - Copy-Item -Path "C:\Users\$env:UserName\csi-proxy.exe" -Destination "C:\etc\kubernetes\node\bin\csi-proxy.exe" - - # restart the csiproxy service - $flags = "-v=5 -windows-service -log_file=C:\etc\kubernetes\logs\csi-proxy.log -logtostderr=false" - sc.exe create csiproxy start= "auto" binPath= "C:\etc\kubernetes\node\bin\csi-proxy.exe $flags" - sc.exe failure csiproxy reset= 0 actions= restart/10000 - sc.exe start csiproxy - - Start-Sleep -Seconds 5; - - Write-Output "Checking the status of csi-proxy" - sc.exe query csiproxy - [System.IO.Directory]::GetFiles("\\.\\pipe\\") - - Write-Output "Get logs" - Get-Content C:\etc\kubernetes\logs\csi-proxy.log -Tail 20 -} - -function Run-CSIProxyIntegrationTests { - param ( - [string]$test_args = "" - ) - - $ErrorActionPreference = "Stop"; - Write-Output "Running integration tests with test_args=$test_args"; - $flags = $test_args.Split(" "); - .\integrationtests.test.exe @flags - - if (-not $?) { - throw "failed to run with exit code=$?" - } -} diff --git a/scripts/utils.sh b/scripts/utils.sh index fa33a0a2..472b603f 100644 --- a/scripts/utils.sh +++ b/scripts/utils.sh @@ -19,45 +19,23 @@ sync_file_to_vm() { gcloud compute scp $@ $windows_node:"C:\\Users\\${current_account}" } -compile_csi_proxy() { - echo "Compiling CSI Proxy" - make -C $pkgdir build -} - compile_csi_proxy_integration_tests() { echo "Compiling CSI Proxy integration tests" GOOS=windows GOARCH=amd64 go test -c $pkgdir/integrationtests -o $pkgdir/bin/integrationtests.test.exe } -sync_csi_proxy() { - echo "Sync the csi-proxy.exe binary" - local csi_proxy_bin_path="$pkgdir/bin/csi-proxy.exe" - sync_file_to_vm $csi_proxy_bin_path -} - sync_csi_proxy_integration_tests() { echo "Sync the integrationtests.exe binary" local integration_bin_path="$pkgdir/bin/integrationtests.test.exe" sync_file_to_vm $integration_bin_path } -sync_powershell_utils() { - local utils_psm1="$pkgdir/scripts/utils.psm1" - sync_file_to_vm $utils_psm1 -} - -restart_csi_proxy() { - echo "Restart csi-proxy service" - gcloud compute ssh $windows_node --command='powershell -c "& { $ErrorActionPreference = \"Stop\"; Import-Module (Resolve-Path(\"utils.psm1\")); Restart-CSIProxy; }"' -} - run_csi_proxy_integration_tests() { echo "Run integration tests" local ps1=$(cat << 'EOF' "& { $ErrorActionPreference = \"Stop\"; - Import-Module (Resolve-Path(\"utils.psm1\")); - Run-CSIProxyIntegrationTests -test_args \"--test.v\"; + .\integrationtests.test.exe --test.v }" EOF );