From 789b9b514a6a2e7275d7f56e4e79983dd70ed41d Mon Sep 17 00:00:00 2001 From: phillc <15082+phillc@users.noreply.github.com> Date: Thu, 13 Aug 2020 13:27:56 -0400 Subject: [PATCH 1/2] Converging CSI and CCM e2e suites - pretty much copy paste from ccm --- .gitignore | 3 +- e2e/Makefile | 31 +++++++++++++++++++ e2e/README.md | 54 +++++++++++++++++++++++++++++++++ e2e/{test => }/go.mod | 0 e2e/{test => }/go.sum | 0 e2e/test/.gitignore | 6 ++++ e2e/test/Makefile | 19 ------------ e2e/test/csi_driver_test.go | 2 +- e2e/test/e2e_suite_test.go | 49 +++++++++++++++++++++--------- e2e/test/framework/framework.go | 2 +- 10 files changed, 129 insertions(+), 37 deletions(-) create mode 100644 e2e/Makefile create mode 100644 e2e/README.md rename e2e/{test => }/go.mod (100%) rename e2e/{test => }/go.sum (100%) create mode 100644 e2e/test/.gitignore delete mode 100644 e2e/test/Makefile diff --git a/.gitignore b/.gitignore index c7d761ed..d93cf4b4 100644 --- a/.gitignore +++ b/.gitignore @@ -36,7 +36,8 @@ linode-blockstorage-csi-driver dist/ .vscode/ coverage.txt +*.coverprofile *.terraform e2e/test/terraform* -*junit.xml \ No newline at end of file +*junit.xml diff --git a/e2e/Makefile b/e2e/Makefile new file mode 100644 index 00000000..a0c91de8 --- /dev/null +++ b/e2e/Makefile @@ -0,0 +1,31 @@ +export GO111MODULE=on +IMG ?= linode/linode-blockstorage-csi-driver:latest + +imports: $(GOPATH)/bin/goimports + goimports -w test + +.PHONY: test reuse-and-test clean + +reuse-and-test: SUITE_ARGS='--reuse' + +test reuse-and-test: $(GOPATH)/bin/ginkgo check-token + go list -m; \ + ginkgo -r --v --progress --trace --cover $(TEST_ARGS) -- --v=3 --image=${IMG} $(SUITE_ARGS); \ + +clean: check-token + cd test; \ + ./scripts/delete_cluster.sh csi-linode-for-reuse; \ + rm terraform.tfstate; \ + rm -rf terraform.tfstate.d + +check-token: + @if test "$(LINODE_API_TOKEN)" = "" ; then \ + echo "LINODE_API_TOKEN must be set"; \ + exit 1; \ + fi + +install-terraform: + sudo apt-get install wget unzip + wget https://releases.hashicorp.com/terraform/0.11.13/terraform_0.11.13_linux_amd64.zip + unzip terraform_0.11.13_linux_amd64.zip + sudo mv terraform /usr/local/bin/ diff --git a/e2e/README.md b/e2e/README.md new file mode 100644 index 00000000..21c6a7a3 --- /dev/null +++ b/e2e/README.md @@ -0,0 +1,54 @@ +## How to run these End-to-end (e2e) tests + +Install the following packages (macOS examples) + +``` +brew install terraform +brew install kubectl +brew install golang +``` + +Add the following environment variables to your shell rc + +``` +export LINODE_API_TOKEN= + +export GOPATH=$HOME/go +export PATH=$HOME/go/bin:$PATH +export GO111MODULE=on +``` + +If you need a Linode API token visit this page: +https://cloud.linode.com/profile/tokens + +Then, `go get` this repo +`go get github.com/linode/linode-blockstorage-csi-driver` + +That may fail, if it does, navigate to the directory that was created and run `go mod tidy`: + +``` +cd ~/go/src/github.com/linode/linode-blockstorage-csi-driver +go mod tidy +``` + +Then, use the makefile in the directory above this directory to build the CSI (this is to download goimports) + +``` +cd $GOPATH/src/github.com/linode/linode-blockstorage-csi-driver +make build +``` + +By default the tests use $HOME/.ssh/id\_rsa.pub as the public key used to provision the cluster, so it needs to be added to your agent. + +``` +ssh-add $HOME/.ssh/id_rsa +``` + +Come back here and run the tests + +``` +cd e2e +make test +``` + +To save time on multiple runs by allowing the cluster to remain, use `make reuse-and-test` diff --git a/e2e/test/go.mod b/e2e/go.mod similarity index 100% rename from e2e/test/go.mod rename to e2e/go.mod diff --git a/e2e/test/go.sum b/e2e/go.sum similarity index 100% rename from e2e/test/go.sum rename to e2e/go.sum diff --git a/e2e/test/.gitignore b/e2e/test/.gitignore new file mode 100644 index 00000000..fc3ef35d --- /dev/null +++ b/e2e/test/.gitignore @@ -0,0 +1,6 @@ +# dont commit temporary files written here by Terraform +*.conf +cluster.tf +terraform* +.terraform + diff --git a/e2e/test/Makefile b/e2e/test/Makefile deleted file mode 100644 index 3cf1f226..00000000 --- a/e2e/test/Makefile +++ /dev/null @@ -1,19 +0,0 @@ -export GO111MODULE=on - -$(GOPATH)/bin/ginkgo: - GO111MODULE=off go get -u github.com/onsi/ginkgo/ginkgo - -ginkgo_test: $(GOPATH)/bin/ginkgo - go vet ./ - @if [ -z "${LINODE_API_TOKEN}" ]; then\ - echo "Skipping Test, LINODE_API_TOKEN is not set";\ - else \ - go list -m; \ - ginkgo -r --v --progress --trace --cover -- --v=3; \ - fi - -install-terraform: - sudo apt-get install wget unzip - wget https://releases.hashicorp.com/terraform/0.11.13/terraform_0.11.13_linux_amd64.zip - unzip terraform_0.11.13_linux_amd64.zip - sudo mv terraform /usr/local/bin/ \ No newline at end of file diff --git a/e2e/test/csi_driver_test.go b/e2e/test/csi_driver_test.go index 419ff129..e01fddd3 100644 --- a/e2e/test/csi_driver_test.go +++ b/e2e/test/csi_driver_test.go @@ -1,7 +1,7 @@ package test import ( - "e2e_test/framework" + "e2e_test/test/framework" "time" . "github.com/onsi/ginkgo" diff --git a/e2e/test/e2e_suite_test.go b/e2e/test/e2e_suite_test.go index d29a7980..8dc3717d 100644 --- a/e2e/test/e2e_suite_test.go +++ b/e2e/test/e2e_suite_test.go @@ -2,33 +2,35 @@ package test import ( "flag" - "github.com/appscode/go/crypto/rand" - "k8s.io/client-go/util/homedir" "testing" "time" - "e2e_test/framework" + "k8s.io/client-go/util/homedir" + + "e2e_test/test/framework" + "os" + "path/filepath" + + "github.com/appscode/go/crypto/rand" . "github.com/onsi/ginkgo" "github.com/onsi/ginkgo/reporters" . "github.com/onsi/gomega" "k8s.io/client-go/kubernetes" "k8s.io/client-go/tools/clientcmd" - "os" - "path/filepath" ) var ( StorageClass = "linode-block-storage" useExisting = false - dlt = false - ClusterName = rand.WithUniqSuffix("csi-linode") + reuse = false + clusterName string ) func init() { flag.StringVar(&framework.Image, "image", framework.Image, "registry/repository:tag") flag.StringVar(&framework.ApiToken, "api-token", os.Getenv("LINODE_API_TOKEN"), "linode api token") - flag.BoolVar(&dlt, "delete", dlt, "Delete cluster after test") - flag.BoolVar(&useExisting, "use-existing", useExisting, "Use existing kubernetes cluster") + flag.BoolVar(&reuse, "reuse", reuse, "Create a cluster and continue to use it") + flag.BoolVar(&useExisting, "use-existing", useExisting, "Use an existing kubernetes cluster") flag.StringVar(&framework.KubeConfigFile, "kubeconfig", filepath.Join(homedir.HomeDir(), ".kube/config"), "To use existing cluster provide kubeconfig file") } @@ -49,13 +51,27 @@ func TestE2e(t *testing.T) { } var _ = BeforeSuite(func() { + if reuse { + clusterName = "csi-linode-for-reuse" + } else { + clusterName = rand.WithUniqSuffix("csi-linode") + } + + dir, err := os.Getwd() + Expect(err).NotTo(HaveOccurred()) + kubeConfigFile := filepath.Join(dir, clusterName+".conf") + + if reuse { + if _, err := os.Stat(kubeConfigFile); !os.IsNotExist(err) { + useExisting = true + framework.KubeConfigFile = kubeConfigFile + } + } if !useExisting { - err := framework.CreateCluster(ClusterName) - Expect(err).NotTo(HaveOccurred()) - dir, err := os.Getwd() + err := framework.CreateCluster(clusterName) Expect(err).NotTo(HaveOccurred()) - framework.KubeConfigFile = filepath.Join(dir, ClusterName+".conf") + framework.KubeConfigFile = kubeConfigFile } By("Using kubeconfig from " + framework.KubeConfigFile) @@ -74,8 +90,11 @@ var _ = BeforeSuite(func() { }) var _ = AfterSuite(func() { - if dlt || !useExisting { - err := framework.DeleteCluster(ClusterName) + if !(useExisting || reuse) { + By("Deleting cluster") + err := framework.DeleteCluster(clusterName) Expect(err).NotTo(HaveOccurred()) + } else { + By("Not deleting cluster") } }) diff --git a/e2e/test/framework/framework.go b/e2e/test/framework/framework.go index a3b360c3..125c02d0 100644 --- a/e2e/test/framework/framework.go +++ b/e2e/test/framework/framework.go @@ -7,7 +7,7 @@ import ( ) var ( - Image = "linode/linode-blockstorage-csi-driver:v0.1.0" + Image = "linode/linode-blockstorage-csi-driver:latest" ApiToken = "" KubeConfigFile = "" ) From e450cfd621debbaba85bd27cdbeb2fafeb00d6a2 Mon Sep 17 00:00:00 2001 From: phillc <15082+phillc@users.noreply.github.com> Date: Thu, 20 Aug 2020 11:05:02 -0400 Subject: [PATCH 2/2] Remove go mod vendor --- Makefile | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/Makefile b/Makefile index a92923b9..67c902d0 100644 --- a/Makefile +++ b/Makefile @@ -23,10 +23,6 @@ export GO111MODULE=on .PHONY: all all: linode -.PHONY: vendor -vendor: - go mod vendor - .PHONY: fmt fmt: go fmt ./... @@ -40,7 +36,7 @@ test: vet go test -v ./... -cover .PHONY: linode -linode: vendor test +linode: test CGO_ENABLED=0 GOOS=linux go build -a -ldflags '-X main.vendorVersion=$(REV) -extldflags "-static"' -o _output/linode ./app/linode .PHONY: linode-container