Skip to content

Commit

Permalink
Merge pull request #54 from phillc/master
Browse files Browse the repository at this point in the history
Converge test suite to CCM
  • Loading branch information
phillc authored Aug 21, 2020
2 parents cb797f0 + e450cfd commit e3eaa07
Show file tree
Hide file tree
Showing 11 changed files with 130 additions and 42 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ linode-blockstorage-csi-driver
dist/
.vscode/
coverage.txt
*.coverprofile

*.terraform
e2e/test/terraform*
*junit.xml
*junit.xml
6 changes: 1 addition & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,6 @@ export GO111MODULE=on
.PHONY: all
all: linode

.PHONY: vendor
vendor:
go mod vendor

.PHONY: fmt
fmt:
go fmt ./...
Expand All @@ -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
Expand Down
31 changes: 31 additions & 0 deletions e2e/Makefile
Original file line number Diff line number Diff line change
@@ -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/
54 changes: 54 additions & 0 deletions e2e/README.md
Original file line number Diff line number Diff line change
@@ -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=<your 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`
File renamed without changes.
File renamed without changes.
6 changes: 6 additions & 0 deletions e2e/test/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# dont commit temporary files written here by Terraform
*.conf
cluster.tf
terraform*
.terraform

19 changes: 0 additions & 19 deletions e2e/test/Makefile

This file was deleted.

2 changes: 1 addition & 1 deletion e2e/test/csi_driver_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package test

import (
"e2e_test/framework"
"e2e_test/test/framework"
"time"

. "github.com/onsi/ginkgo"
Expand Down
49 changes: 34 additions & 15 deletions e2e/test/e2e_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}

Expand All @@ -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)
Expand All @@ -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")
}
})
2 changes: 1 addition & 1 deletion e2e/test/framework/framework.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
)

var (
Image = "linode/linode-blockstorage-csi-driver:v0.1.0"
Image = "linode/linode-blockstorage-csi-driver:latest"
ApiToken = ""
KubeConfigFile = ""
)
Expand Down

0 comments on commit e3eaa07

Please sign in to comment.