Skip to content

Commit 4a14d99

Browse files
authored
Merge pull request #54 from ZeroMagic/e2e
test: add e2e test framework
2 parents 90ed2f5 + f121389 commit 4a14d99

File tree

1,003 files changed

+244124
-388
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,003 files changed

+244124
-388
lines changed

Gopkg.lock

Lines changed: 535 additions & 35 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Gopkg.toml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656

5757
[[constraint]]
5858
name = "k8s.io/kubernetes"
59-
version = "v1.15.0"
59+
version = "=v1.15.0"
6060

6161
[[override]]
6262
name = "gopkg.in/fsnotify.v1"
@@ -101,3 +101,7 @@
101101
[[override]]
102102
name = "github.com/Azure/azure-sdk-for-go"
103103
version = "v21.3.0"
104+
105+
[[override]]
106+
name = "github.com/kubernetes-csi/external-snapshotter"
107+
version = "=v1.0.1"

Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ integration-test:
3333
test/integration/run-tests-all-clouds.sh
3434
sanity-test:
3535
test/sanity/run-tests-all-clouds.sh
36+
e2e-test:
37+
test/e2e/run-test.sh
3638
blobfuse:
3739
if [ ! -d ./vendor ]; then dep ensure -vendor-only; fi
3840
CGO_ENABLED=0 GOOS=linux go build -a -ldflags ${LDFLAGS} -o _output/blobfuseplugin ./pkg/blobfuseplugin

deploy/install-driver.sh

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/bin/bash
2+
3+
# Copyright 2019 The Kubernetes Authors.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
set -uo pipefail
18+
19+
kubectl apply -f deploy/crd-csi-driver-registry.yaml
20+
kubectl apply -f deploy/crd-csi-node-info.yaml
21+
kubectl apply -f deploy/rbac-csi-blobfuse-controller.yaml
22+
kubectl apply -f deploy/csi-blobfuse-controller.yaml
23+
kubectl apply -f deploy/csi-blobfuse-node.yaml

test/e2e/README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
## End to End Test
2+
3+
## Run E2E tests Locally
4+
### Prerequisite
5+
Make sure a kubernetes cluster is set up and kubeconfig is under $HOME/.kube/config
6+
7+
### Run test
8+
```
9+
make e2e-test
10+
```
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
/*
2+
Copyright 2019 The Kubernetes Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package driver
18+
19+
import (
20+
"fmt"
21+
22+
blobfuse "github.com/csi-driver/blobfuse-csi-driver/pkg/blobfuse"
23+
"github.com/kubernetes-csi/external-snapshotter/pkg/apis/volumesnapshot/v1alpha1"
24+
v1 "k8s.io/api/core/v1"
25+
storagev1 "k8s.io/api/storage/v1"
26+
"k8s.io/apimachinery/pkg/api/resource"
27+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
28+
)
29+
30+
// Implement DynamicPVTestDriver interface
31+
type blobFuseCSIDriver struct {
32+
driverName string
33+
}
34+
35+
// InitBlobFuseCSIDriver returns blobFuseCSIDriver that implemnts DynamicPVTestDriver interface
36+
func InitBlobFuseCSIDriver() PVTestDriver {
37+
return &blobFuseCSIDriver{
38+
driverName: blobfuse.DriverName,
39+
}
40+
}
41+
42+
func (d *blobFuseCSIDriver) GetDynamicProvisionStorageClass(parameters map[string]string, mountOptions []string, reclaimPolicy *v1.PersistentVolumeReclaimPolicy, bindingMode *storagev1.VolumeBindingMode, allowedTopologyValues []string, namespace string) *storagev1.StorageClass {
43+
provisioner := d.driverName
44+
generateName := fmt.Sprintf("%s-%s-dynamic-sc-", namespace, provisioner)
45+
return getStorageClass(generateName, provisioner, parameters, mountOptions, reclaimPolicy, bindingMode, nil)
46+
}
47+
48+
func (d *blobFuseCSIDriver) GetVolumeSnapshotClass(namespace string) *v1alpha1.VolumeSnapshotClass {
49+
provisioner := d.driverName
50+
generateName := fmt.Sprintf("%s-%s-dynamic-sc-", namespace, provisioner)
51+
return getVolumeSnapshotClass(generateName, provisioner)
52+
}
53+
54+
func (d *blobFuseCSIDriver) GetPersistentVolume(volumeID string, fsType string, size string, reclaimPolicy *v1.PersistentVolumeReclaimPolicy, namespace string) *v1.PersistentVolume {
55+
provisioner := d.driverName
56+
generateName := fmt.Sprintf("%s-%s-preprovsioned-pv-", namespace, provisioner)
57+
// Default to Retain ReclaimPolicy for pre-provisioned volumes
58+
pvReclaimPolicy := v1.PersistentVolumeReclaimRetain
59+
if reclaimPolicy != nil {
60+
pvReclaimPolicy = *reclaimPolicy
61+
}
62+
return &v1.PersistentVolume{
63+
ObjectMeta: metav1.ObjectMeta{
64+
GenerateName: generateName,
65+
Namespace: namespace,
66+
// TODO remove if https://github.com/kubernetes-csi/external-provisioner/issues/202 is fixed
67+
Annotations: map[string]string{
68+
"pv.kubernetes.io/provisioned-by": provisioner,
69+
},
70+
},
71+
Spec: v1.PersistentVolumeSpec{
72+
AccessModes: []v1.PersistentVolumeAccessMode{v1.ReadWriteOnce},
73+
Capacity: v1.ResourceList{
74+
v1.ResourceName(v1.ResourceStorage): resource.MustParse(size),
75+
},
76+
PersistentVolumeReclaimPolicy: pvReclaimPolicy,
77+
PersistentVolumeSource: v1.PersistentVolumeSource{
78+
CSI: &v1.CSIPersistentVolumeSource{
79+
Driver: provisioner,
80+
VolumeHandle: volumeID,
81+
FSType: fsType,
82+
},
83+
},
84+
},
85+
}
86+
}
87+
88+
func GetParameters() map[string]string {
89+
return map[string]string{
90+
"skuName": "Standard_LRS",
91+
}
92+
}

test/e2e/driver/driver.go

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
/*
2+
Copyright 2019 The Kubernetes Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package driver
18+
19+
import (
20+
"github.com/kubernetes-csi/external-snapshotter/pkg/apis/volumesnapshot/v1alpha1"
21+
v1 "k8s.io/api/core/v1"
22+
storagev1 "k8s.io/api/storage/v1"
23+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
24+
)
25+
26+
const (
27+
VolumeSnapshotClassKind = "VolumeSnapshotClass"
28+
SnapshotAPIVersion = "snapshot.storage.k8s.io/v1alpha1"
29+
)
30+
31+
type PVTestDriver interface {
32+
DynamicPVTestDriver
33+
PreProvisionedVolumeTestDriver
34+
VolumeSnapshotTestDriver
35+
}
36+
37+
// DynamicPVTestDriver represents an interface for a CSI driver that supports DynamicPV
38+
type DynamicPVTestDriver interface {
39+
// GetDynamicProvisionStorageClass returns a StorageClass dynamic provision Persistent Volume
40+
GetDynamicProvisionStorageClass(parameters map[string]string, mountOptions []string, reclaimPolicy *v1.PersistentVolumeReclaimPolicy, bindingMode *storagev1.VolumeBindingMode, allowedTopologyValues []string, namespace string) *storagev1.StorageClass
41+
}
42+
43+
// PreProvisionedVolumeTestDriver represents an interface for a CSI driver that supports pre-provisioned volume
44+
type PreProvisionedVolumeTestDriver interface {
45+
// GetPersistentVolume returns a PersistentVolume with pre-provisioned volumeHandle
46+
GetPersistentVolume(volumeID string, fsType string, size string, reclaimPolicy *v1.PersistentVolumeReclaimPolicy, namespace string) *v1.PersistentVolume
47+
}
48+
49+
type VolumeSnapshotTestDriver interface {
50+
GetVolumeSnapshotClass(namespace string) *v1alpha1.VolumeSnapshotClass
51+
}
52+
53+
func getStorageClass(
54+
generateName string,
55+
provisioner string,
56+
parameters map[string]string,
57+
mountOptions []string,
58+
reclaimPolicy *v1.PersistentVolumeReclaimPolicy,
59+
bindingMode *storagev1.VolumeBindingMode,
60+
allowedTopologies []v1.TopologySelectorTerm,
61+
) *storagev1.StorageClass {
62+
if reclaimPolicy == nil {
63+
defaultReclaimPolicy := v1.PersistentVolumeReclaimDelete
64+
reclaimPolicy = &defaultReclaimPolicy
65+
}
66+
if bindingMode == nil {
67+
defaultBindingMode := storagev1.VolumeBindingImmediate
68+
bindingMode = &defaultBindingMode
69+
}
70+
return &storagev1.StorageClass{
71+
ObjectMeta: metav1.ObjectMeta{
72+
GenerateName: generateName,
73+
},
74+
Provisioner: provisioner,
75+
Parameters: parameters,
76+
MountOptions: mountOptions,
77+
ReclaimPolicy: reclaimPolicy,
78+
VolumeBindingMode: bindingMode,
79+
AllowedTopologies: allowedTopologies,
80+
}
81+
}
82+
83+
func getVolumeSnapshotClass(generateName string, provisioner string) *v1alpha1.VolumeSnapshotClass {
84+
return &v1alpha1.VolumeSnapshotClass{
85+
TypeMeta: metav1.TypeMeta{
86+
Kind: VolumeSnapshotClassKind,
87+
APIVersion: SnapshotAPIVersion,
88+
},
89+
90+
ObjectMeta: metav1.ObjectMeta{
91+
GenerateName: generateName,
92+
},
93+
Snapshotter: provisioner,
94+
}
95+
}

test/e2e/dynamic_provisioning.go

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
/*
2+
Copyright 2019 The Kubernetes Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package e2e
18+
19+
import (
20+
"fmt"
21+
"os"
22+
23+
"github.com/csi-driver/blobfuse-csi-driver/pkg/blobfuse"
24+
"github.com/csi-driver/blobfuse-csi-driver/test/e2e/driver"
25+
"github.com/csi-driver/blobfuse-csi-driver/test/e2e/testsuites"
26+
. "github.com/onsi/ginkgo"
27+
v1 "k8s.io/api/core/v1"
28+
clientset "k8s.io/client-go/kubernetes"
29+
"k8s.io/kubernetes/test/e2e/framework"
30+
)
31+
32+
var _ = Describe("Dynamic Provisioning", func() {
33+
f := framework.NewDefaultFramework("blobfuse")
34+
35+
var (
36+
cs clientset.Interface
37+
ns *v1.Namespace
38+
testDriver driver.PVTestDriver
39+
)
40+
41+
nodeid := os.Getenv("nodeid")
42+
blobfuseDriver := blobfuse.NewDriver(nodeid)
43+
endpoint := "unix:///tmp/csi.sock"
44+
45+
go func() {
46+
blobfuseDriver.Run(endpoint)
47+
}()
48+
49+
BeforeEach(func() {
50+
cs = f.ClientSet
51+
ns = f.Namespace
52+
})
53+
54+
testDriver = driver.InitBlobFuseCSIDriver()
55+
It(fmt.Sprintf("should create a volume on demand"), func() {
56+
pods := []testsuites.PodDetails{
57+
{
58+
Cmd: "echo 'hello world' > /mnt/test-1/data && grep 'hello world' /mnt/test-1/data",
59+
Volumes: []testsuites.VolumeDetails{
60+
{
61+
ClaimSize: "10Gi",
62+
VolumeMount: testsuites.VolumeMountDetails{
63+
NameGenerate: "test-volume-",
64+
MountPathGenerate: "/mnt/test-",
65+
},
66+
},
67+
},
68+
},
69+
}
70+
test := testsuites.DynamicallyProvisionedCmdVolumeTest{
71+
CSIDriver: testDriver,
72+
Pods: pods,
73+
}
74+
test.Run(cs, ns)
75+
})
76+
})

test/e2e/run-test.sh

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#!/bin/bash
2+
3+
# Copyright 2019 The Kubernetes Authors.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
set -uo pipefail
18+
19+
kubectl get daemonsets csi-blobfuse-node -n kube-system; checkBlobFuseDriver=$?;
20+
if [ $checkBlobFuseDriver -ne 0 ]; then
21+
echo "BlobFuse csi driver daemonset not found";
22+
echo "Installing BlobFuse csi driver";
23+
deploy/install-driver.sh
24+
echo "BlobFuse csi driver installed";
25+
fi
26+
27+
# Fetching ginkgo for running the test
28+
GO111MODULE=off go get -u github.com/onsi/ginkgo/ginkgo
29+
# Exporting KUBECONFIG path
30+
export KUBECONFIG=$HOME/.kube/config
31+
# Running the e2e test
32+
ginkgo test/e2e
33+
# Checking for test status
34+
TEST_PASS=$?
35+
if [[ $TEST_PASS -ne 0 ]]; then
36+
exit 1
37+
fi

0 commit comments

Comments
 (0)