Skip to content

Commit 3b9bb2d

Browse files
authored
Merge pull request #273 from jiaxunsongucb/tests
test: change the way credentials are loaded
2 parents a7acae2 + ccf9645 commit 3b9bb2d

File tree

13 files changed

+209
-203
lines changed

13 files changed

+209
-203
lines changed

Makefile

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ IMAGE_TAG ?= $(REGISTRY)/$(IMAGE_NAME):$(IMAGE_VERSION)
2828
IMAGE_TAG_LATEST = $(REGISTRY)/$(IMAGE_NAME):latest
2929
BUILD_DATE ?= $(shell date -u +"%Y-%m-%dT%H:%M:%SZ")
3030
LDFLAGS ?= "-X ${PKG}/pkg/blob.driverVersion=${IMAGE_VERSION} -X ${PKG}/pkg/blob.gitCommit=${GIT_COMMIT} -X ${PKG}/pkg/blob.buildDate=${BUILD_DATE} -s -w -extldflags '-static'"
31-
E2E_HELM_OPTIONS ?= --set image.blob.pullPolicy=IfNotPresent --set image.blob.repository=$(REGISTRY)/$(IMAGE_NAME) --set image.blob.tag=$(IMAGE_VERSION)
32-
GINKGO_FLAGS = -ginkgo.noColor -ginkgo.v
31+
E2E_HELM_OPTIONS ?= --set image.blob.pullPolicy=Always --set image.blob.repository=$(REGISTRY)/$(IMAGE_NAME) --set image.blob.tag=$(IMAGE_VERSION)
32+
GINKGO_FLAGS = -ginkgo.v
3333
GO111MODULE = on
3434
GOPATH ?= $(shell go env GOPATH)
3535
GOBIN ?= $(GOPATH)/bin
@@ -79,15 +79,15 @@ e2e-teardown:
7979

8080
.PHONY: blob
8181
blob:
82-
CGO_ENABLED=0 GOOS=linux go build -a -ldflags ${LDFLAGS} -o _output/blobplugin ./pkg/blobplugin
82+
CGO_ENABLED=0 GOOS=linux go build -a -ldflags ${LDFLAGS} -mod vendor -o _output/blobplugin ./pkg/blobplugin
8383

8484
.PHONY: blob-windows
8585
blob-windows:
86-
CGO_ENABLED=0 GOOS=windows go build -a -ldflags ${LDFLAGS} -o _output/blobplugin.exe ./pkg/blobplugin
86+
CGO_ENABLED=0 GOOS=windows go build -a -ldflags ${LDFLAGS} -mod vendor -o _output/blobplugin.exe ./pkg/blobplugin
8787

8888
.PHONT: blob-darwin
8989
blob-darwin:
90-
CGO_ENABLED=0 GOOS=darwin go build -a -ldflags ${LDFLAGS} -o _output/blobplugin ./pkg/blobplugin
90+
CGO_ENABLED=0 GOOS=darwin go build -a -ldflags ${LDFLAGS} -mod vendor -o _output/blobplugin ./pkg/blobplugin
9191

9292
.PHONY: container
9393
container: blob
@@ -143,3 +143,7 @@ create-example-deployment:
143143
kubectl apply -f deploy/example/storageclass-blobfuse.yaml
144144
kubectl apply -f deploy/example/deployment.yaml
145145
kubectl apply -f deploy/example/statefulset.yaml
146+
147+
.PHONY: delete-metrics-svc
148+
delete-metrics-svc:
149+
kubectl delete -f deploy/example/metrics/csi-blob-controller-svc.yaml --ignore-not-found

hack/verify-boilerplate.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ REPO_ROOT=$(dirname "${BASH_SOURCE}")/..
3030
boilerDir="${REPO_ROOT}/hack/boilerplate"
3131
boiler="${boilerDir}/boilerplate.py"
3232

33-
files_need_boilerplate=($(${boiler} --rootdir=${REPO_ROOT}))
33+
files_need_boilerplate=($(${boiler} --rootdir=${REPO_ROOT} --verbose))
3434

3535
# Run boilerplate.py unit tests
3636
unitTestOut="$(mktemp)"

pkg/blobplugin/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ ADD . .
1818
ARG TARGETARCH
1919
ARG TARGETOS
2020
ARG LDFLAGS
21-
RUN CGO_ENABLED=0 GOOS=$TARGETOS GOARCH=$TARGETARCH go build -a -ldflags "${LDFLAGS:--X sigs.k8s.io/blob-csi-driver/pkg/blob.driverVersion=latest}" -o _output/blobplugin ./pkg/blobplugin
21+
RUN CGO_ENABLED=0 GOOS=$TARGETOS GOARCH=$TARGETARCH go build -a -ldflags "${LDFLAGS:--X sigs.k8s.io/blob-csi-driver/pkg/blob.driverVersion=latest}" -mod vendor -o _output/blobplugin ./pkg/blobplugin
2222

2323
FROM k8s.gcr.io/build-image/debian-base-amd64:v2.1.3
2424
COPY --from=builder /go/src/sigs.k8s.io/blob-csi-driver/_output/blobplugin /blobplugin

test/e2e/README.md

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,33 @@
22

33
## Run E2E tests Locally
44
### Prerequisite
5-
- Make sure a kubernetes cluster(with version >= 1.13) is set up and kubeconfig is under `$HOME/.kube/config`
6-
- Copy out `/etc/kubernetes/azure.json` under one agent node to local machine
7-
> For AKS cluster, need to modify `resourceGroup` to the node resource group name inside `/etc/kubernetes/azure.json`
5+
- Make sure a kubernetes cluster(with version >= 1.13) is set up and kubeconfig is under `$HOME/.kube/config`. Make sure kubectl is functional.
6+
- Better to do: install Helm and Tiller
7+
```
8+
# Use v2.11.0 helm to match tiller's version in clusters made by aks-engine
9+
curl https://raw.githubusercontent.com/helm/helm/master/scripts/get | DESIRED_VERSION=v2.11.0 bash
10+
11+
# Install Tiller for Helm version v2.11.0
12+
helm init --history-max 200 --override spec.selector.matchLabels.'name'='tiller',spec.selector.matchLabels.'app'='helm' --output yaml | sed 's@apiVersion: extensions/v1beta1@apiVersion: apps/v1@' | kubectl apply -f -
13+
```
14+
- Set Azure credentials by environment variables
15+
> You could get these variables from `/etc/kubernetes/azure.json` on a kubernetes cluster node
16+
```
17+
# Required environment variables:
18+
export set AZURE_TENANT_ID=
19+
export set AZURE_SUBSCRIPTION_ID=
20+
export set AZURE_CLIENT_ID=
21+
export set AZURE_CLIENT_SECRET=
22+
23+
# Optional environment variables:
24+
# If the the test is not for the public Azure, e.g. Azure China Cloud, then you need to set AZURE_CLOUD_NAME and AZURE_LOCATION.
25+
# For Azure Stack Clound, you need to set AZURE_ENVIRONMENT_FILEPATH for your cloud environment.
26+
# If you have an existing resource group created for the test, then you need to set variable AZURE_RESOURCE_GROUP.
27+
export set AZURE_CLOUD_NAME=
28+
export set AZURE_LOCATION=
29+
export set AZURE_ENVIRONMENT_FILEPATH=
30+
export set AZURE_RESOURCE_GROUP=
31+
```
832

933
### Run test
1034
```

test/e2e/pre_provisioning_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ var _ = ginkgo.Describe("[blob-csi-e2e] Pre-Provisioned", func() {
7272
}
7373
_, err := blobDriver.DeleteVolume(context.Background(), req)
7474
if err != nil {
75-
ginkgo.Fail(fmt.Sprintf("create volume %q error: %v", volumeID, err))
75+
ginkgo.Fail(fmt.Sprintf("delete volume %q error: %v", volumeID, err))
7676
}
7777
}
7878
})

test/e2e/suite_test.go

Lines changed: 69 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -71,14 +71,14 @@ var _ = ginkgo.BeforeSuite(func() {
7171
handleFlags()
7272
framework.AfterReadingAllFlags(&framework.TestContext)
7373

74-
if testutil.IsRunningInProw() {
75-
creds, err := credentials.CreateAzureCredentialFile(false)
76-
gomega.Expect(err).NotTo(gomega.HaveOccurred())
77-
azureClient, err := azure.GetClient(creds.Cloud, creds.SubscriptionID, creds.AADClientID, creds.TenantID, creds.AADClientSecret)
78-
gomega.Expect(err).NotTo(gomega.HaveOccurred())
79-
_, err = azureClient.EnsureResourceGroup(context.Background(), creds.ResourceGroup, creds.Location, nil)
80-
gomega.Expect(err).NotTo(gomega.HaveOccurred())
74+
creds, err := credentials.CreateAzureCredentialFile()
75+
gomega.Expect(err).NotTo(gomega.HaveOccurred())
76+
azureClient, err := azure.GetClient(creds.Cloud, creds.SubscriptionID, creds.AADClientID, creds.TenantID, creds.AADClientSecret)
77+
gomega.Expect(err).NotTo(gomega.HaveOccurred())
78+
_, err = azureClient.EnsureResourceGroup(context.Background(), creds.ResourceGroup, creds.Location, nil)
79+
gomega.Expect(err).NotTo(gomega.HaveOccurred())
8180

81+
if testutil.IsRunningInProw() {
8282
// Need to login to ACR using SP credential if we are running in Prow so we can push test images.
8383
// If running locally, user should run 'docker login' before running E2E tests
8484
registry := os.Getenv("REGISTRY")
@@ -89,23 +89,24 @@ var _ = ginkgo.BeforeSuite(func() {
8989
err = cmd.Run()
9090
gomega.Expect(err).NotTo(gomega.HaveOccurred())
9191
log.Println("docker login is successful")
92+
}
93+
94+
// Install Azure Blob Storage CSI driver on cluster from project root
95+
e2eBootstrap := testCmd{
96+
command: "make",
97+
args: []string{"e2e-bootstrap"},
98+
startLog: "Installing Azure Blob Storage CSI driver ...",
99+
endLog: "Azure Blob Storage CSI driver installed",
100+
}
92101

93-
// Install Azure Blob Storage CSI driver on cluster from project root
94-
e2eBootstrap := testCmd{
95-
command: "make",
96-
args: []string{"e2e-bootstrap"},
97-
startLog: "Installing Azure Blob Storage CSI driver ...",
98-
endLog: "Azure Blob Storage CSI driver installed",
99-
}
100-
101-
createMetricsSVC := testCmd{
102-
command: "make",
103-
args: []string{"create-metrics-svc"},
104-
startLog: "create metrics service ...",
105-
endLog: "metrics service created",
106-
}
107-
execTestCmd([]testCmd{e2eBootstrap, createMetricsSVC})
102+
createMetricsSVC := testCmd{
103+
command: "make",
104+
args: []string{"create-metrics-svc"},
105+
startLog: "create metrics service ...",
106+
endLog: "metrics service created",
108107
}
108+
execTestCmd([]testCmd{e2eBootstrap, createMetricsSVC})
109+
109110
nodeid := os.Getenv("nodeid")
110111
kubeconfig := os.Getenv(kubeconfigEnvVar)
111112
blobDriver = blob.NewDriver(nodeid)
@@ -116,49 +117,53 @@ var _ = ginkgo.BeforeSuite(func() {
116117
})
117118

118119
var _ = ginkgo.AfterSuite(func() {
119-
if testutil.IsRunningInProw() {
120-
createExampleDeployment := testCmd{
121-
command: "make",
122-
args: []string{"create-example-deployment"},
123-
startLog: "create example deployments",
124-
endLog: "example deployments created",
125-
}
126-
execTestCmd([]testCmd{createExampleDeployment})
127-
// sleep 120s waiting for deployment running complete
128-
time.Sleep(120 * time.Second)
129-
130-
blobLog := testCmd{
131-
command: "bash",
132-
args: []string{"test/utils/blob_log.sh"},
133-
startLog: "===================blob log===================",
134-
endLog: "==================================================",
135-
}
136-
e2eTeardown := testCmd{
137-
command: "make",
138-
args: []string{"e2e-teardown"},
139-
startLog: "Uninstalling Azure Blob Storage CSI driver...",
140-
endLog: "Azure Blob Storage CSI driver uninstalled",
141-
}
142-
execTestCmd([]testCmd{blobLog, e2eTeardown})
143-
144-
// install/uninstall CSI Driver deployment scripts test
145-
installDriver := testCmd{
146-
command: "bash",
147-
args: []string{"deploy/install-driver.sh", "master", "local"},
148-
startLog: "===================install CSI Driver deployment scripts test===================",
149-
endLog: "===================================================",
150-
}
151-
uninstallDriver := testCmd{
152-
command: "bash",
153-
args: []string{"deploy/uninstall-driver.sh", "master", "local"},
154-
startLog: "===================uninstall CSI Driver deployment scripts test===================",
155-
endLog: "===================================================",
156-
}
157-
execTestCmd([]testCmd{installDriver, uninstallDriver})
158-
159-
err := credentials.DeleteAzureCredentialFile()
160-
gomega.Expect(err).NotTo(gomega.HaveOccurred())
120+
createExampleDeployment := testCmd{
121+
command: "make",
122+
args: []string{"create-example-deployment"},
123+
startLog: "create example deployments",
124+
endLog: "example deployments created",
125+
}
126+
execTestCmd([]testCmd{createExampleDeployment})
127+
// sleep 120s waiting for deployment running complete
128+
time.Sleep(120 * time.Second)
129+
130+
blobLog := testCmd{
131+
command: "bash",
132+
args: []string{"test/utils/blob_log.sh"},
133+
startLog: "===================blob log===================",
134+
endLog: "==================================================",
135+
}
136+
deleteMetricsSVC := testCmd{
137+
command: "make",
138+
args: []string{"delete-metrics-svc"},
139+
startLog: "delete metrics service...",
140+
endLog: "metrics service deleted",
161141
}
142+
e2eTeardown := testCmd{
143+
command: "make",
144+
args: []string{"e2e-teardown"},
145+
startLog: "Uninstalling Azure Blob Storage CSI driver...",
146+
endLog: "Azure Blob Storage CSI driver uninstalled",
147+
}
148+
execTestCmd([]testCmd{blobLog, deleteMetricsSVC, e2eTeardown})
149+
150+
// install/uninstall CSI Driver deployment scripts test
151+
installDriver := testCmd{
152+
command: "bash",
153+
args: []string{"deploy/install-driver.sh", "master", "local"},
154+
startLog: "===================install CSI Driver deployment scripts test===================",
155+
endLog: "===================================================",
156+
}
157+
uninstallDriver := testCmd{
158+
command: "bash",
159+
args: []string{"deploy/uninstall-driver.sh", "master", "local"},
160+
startLog: "===================uninstall CSI Driver deployment scripts test===================",
161+
endLog: "===================================================",
162+
}
163+
execTestCmd([]testCmd{installDriver, uninstallDriver})
164+
165+
err := credentials.DeleteAzureCredentialFile()
166+
gomega.Expect(err).NotTo(gomega.HaveOccurred())
162167
})
163168

164169
func TestE2E(t *testing.T) {

test/integration/README.md

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,32 @@ Integration test verifies the functionality of CSI driver as a standalone server
33

44
## Run Integration Tests Locally
55
### Prerequisite
6-
- make sure `GOPATH` is set and [csc](https://github.com/rexray/gocsi/tree/master/csc) tool is installed under `$GOPATH/bin/csc`
6+
- Make sure `GOPATH` is set and [csc](https://github.com/rexray/gocsi/tree/master/csc) tool is installed under `$GOPATH/bin/csc`
77
```
8-
export set GOPATH=/root/go
8+
export set GOPATH=$HOME/go
99
go get github.com/rexray/gocsi/csc
10+
cd $GOPATH/src/github.com/rexray/gocsi/csc
11+
make build
12+
export PATH=$PATH:$GOROOT/bin:$GOPATH/bin
1013
```
1114

12-
- set Azure credentials by environment variables
13-
> you could get these variables from `/etc/kubernetes/azure.json` on a kubernetes cluster node
15+
- Set Azure credentials by environment variables
16+
> You could get these variables from `/etc/kubernetes/azure.json` on a kubernetes cluster node
1417
```
15-
export set tenantId=
16-
export set subscriptionId=
17-
export set aadClientId=
18-
export set aadClientSecret=
19-
export set resourceGroup=
20-
export set location=
18+
# Required environment variables:
19+
export set AZURE_TENANT_ID=
20+
export set AZURE_SUBSCRIPTION_ID=
21+
export set AZURE_CLIENT_ID=
22+
export set AZURE_CLIENT_SECRET=
23+
24+
# Optional environment variables:
25+
# If the the test is not for the public Azure, e.g. Azure China Cloud, then you need to set AZURE_CLOUD_NAME and AZURE_LOCATION.
26+
# For Azure Stack Clound, you need to set AZURE_ENVIRONMENT_FILEPATH for your cloud environment.
27+
# If you have an existing resource group created for the test, then you need to set variable AZURE_RESOURCE_GROUP.
28+
export set AZURE_CLOUD_NAME=
29+
export set AZURE_LOCATION=
30+
export set AZURE_ENVIRONMENT_FILEPATH=
31+
export set AZURE_RESOURCE_GROUP=
2132
```
2233

2334
### Run integration tests

test/integration/integration_test.go

Lines changed: 2 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -26,45 +26,19 @@ import (
2626

2727
"sigs.k8s.io/blob-csi-driver/test/utils/azure"
2828
"sigs.k8s.io/blob-csi-driver/test/utils/credentials"
29-
"sigs.k8s.io/blob-csi-driver/test/utils/testutil"
3029

3130
"github.com/stretchr/testify/assert"
3231
)
3332

34-
func TestIntegrationOnAzurePublicCloud(t *testing.T) {
35-
// Test on AzurePublicCloud
36-
creds, err := credentials.CreateAzureCredentialFile(false)
33+
func TestIntegration(t *testing.T) {
34+
creds, err := credentials.CreateAzureCredentialFile()
3735
defer func() {
3836
err := credentials.DeleteAzureCredentialFile()
3937
assert.NoError(t, err)
4038
}()
4139
assert.NoError(t, err)
4240
assert.NotNil(t, creds)
4341

44-
testIntegration(t, creds)
45-
}
46-
47-
func TestIntegrationOnAzureChinaCloud(t *testing.T) {
48-
if testutil.IsRunningInProw() {
49-
t.Skipf("Skipping integration test on Azure China Cloud because Prow only tests on Azure Public Cloud at the moment")
50-
}
51-
52-
// Test on AzureChinaCloud
53-
creds, err := credentials.CreateAzureCredentialFile(true)
54-
defer func() {
55-
err := credentials.DeleteAzureCredentialFile()
56-
assert.NoError(t, err)
57-
}()
58-
59-
if err != nil {
60-
// Skip the test if Azure China Cloud credentials are not supplied
61-
t.Skipf("Skipping integration test on Azure China Cloud due to the following error %v", err)
62-
}
63-
assert.NotNil(t, creds)
64-
testIntegration(t, creds)
65-
}
66-
67-
func testIntegration(t *testing.T, creds *credentials.Credentials) {
6842
os.Setenv("AZURE_CREDENTIAL_FILE", credentials.TempAzureCredentialFilePath)
6943

7044
azureClient, err := azure.GetClient(creds.Cloud, creds.SubscriptionID, creds.AADClientID, creds.TenantID, creds.AADClientSecret)

test/sanity/README.md

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,31 @@
11
## Sanity Tests
2-
Testing the Azure File CSI driver using the [`sanity`](https://github.com/kubernetes-csi/csi-test/tree/master/pkg/sanity) package test suite.
2+
Testing the Azure Blob CSI driver using the [`sanity`](https://github.com/kubernetes-csi/csi-test/tree/master/pkg/sanity) package test suite.
33

44
## Run Integration Tests Locally
55
### Prerequisite
6-
- make sure `GOPATH` is set
6+
- Make sure `GOPATH` is set
77

8-
- set the environment variable AZURE_CREDENTIAL_FILE with the path to cloud provider config file only if you have the file at a different location than `/etc/kubernetes/azure.json`
9-
> By default Cloud provider config file is present at `/etc/kubernetes/azure.json` on a kubernetes cluster node
108
```
11-
export set AZURE_CREDENTIAL_FILE=
9+
export set GOPATH=$HOME/go
10+
```
11+
12+
- Set Azure credentials by environment variables
13+
> You could get these variables from `/etc/kubernetes/azure.json` on a kubernetes cluster node
14+
```
15+
# Required environment variables:
16+
export set AZURE_TENANT_ID=
17+
export set AZURE_SUBSCRIPTION_ID=
18+
export set AZURE_CLIENT_ID=
19+
export set AZURE_CLIENT_SECRET=
20+
21+
# Optional environment variables:
22+
# If the the test is not for the public Azure, e.g. Azure China Cloud, then you need to set AZURE_CLOUD_NAME and AZURE_LOCATION.
23+
# For Azure Stack Clound, you need to set AZURE_ENVIRONMENT_FILEPATH for your cloud environment.
24+
# If you have an existing resource group created for the test, then you need to set variable AZURE_RESOURCE_GROUP.
25+
export set AZURE_CLOUD_NAME=
26+
export set AZURE_LOCATION=
27+
export set AZURE_ENVIRONMENT_FILEPATH=
28+
export set AZURE_RESOURCE_GROUP=
1229
```
1330

1431
### Run integration tests

test/sanity/run-test.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,3 @@ _output/blobplugin --endpoint "$endpoint" --nodeid "$nodeid" -v=5 &
3636
echo "Begin to run sanity test..."
3737
readonly CSI_SANITY_BIN='csi-test/cmd/csi-sanity/csi-sanity'
3838
"$CSI_SANITY_BIN" --ginkgo.v --csi.endpoint=$endpoint -ginkgo.skip="should fail when requesting to create a volume with already existing name and different capacity"
39-

0 commit comments

Comments
 (0)