Skip to content

Commit 2e2a158

Browse files
authored
Merge pull request #505 from saikat-royc/external-snapshotter-integration-tests
Provide optional flags to run PD CSI driver snapshot tests
2 parents 3a355f1 + fe230b4 commit 2e2a158

File tree

6 files changed

+46
-11
lines changed

6 files changed

+46
-11
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
apiVersion: snapshot.storage.k8s.io/v1beta1
2+
kind: VolumeSnapshotClass
3+
metadata:
4+
name: csi-gce-pd-snapshot-class
5+
driver: pd.csi.storage.gke.io
6+
deletionPolicy: Delete

test/k8s-integration/config/test-config-template.in

+4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
StorageClass:
22
FromFile: {{.StorageClassFile}}
3+
{{if .SnapshotClassFile }}
4+
SnapshotClass:
5+
FromFile: {{ .SnapshotClassFile }}
6+
{{end}}
37
DriverInfo:
48
Name: csi-gcepd
59
SupportedFsType:

test/k8s-integration/driver-config.go

+15-6
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@ import (
99
)
1010

1111
type driverConfig struct {
12-
StorageClassFile string
13-
Capabilities []string
12+
StorageClassFile string
13+
SnapshotClassFile string
14+
Capabilities []string
1415
}
1516

1617
const (
@@ -21,7 +22,7 @@ const (
2122

2223
// generateDriverConfigFile loads a testdriver config template and creates a file
2324
// with the test-specific configuration
24-
func generateDriverConfigFile(pkgDir, storageClassFile, deploymentStrat string) (string, error) {
25+
func generateDriverConfigFile(pkgDir, storageClassFile, snapshotClassFile, deploymentStrat string) (string, error) {
2526
// Load template
2627
t, err := template.ParseFiles(filepath.Join(pkgDir, testConfigDir, configTemplateFile))
2728
if err != nil {
@@ -51,7 +52,6 @@ func generateDriverConfigFile(pkgDir, storageClassFile, deploymentStrat string)
5152
}
5253

5354
/* Unsupported Capabilities:
54-
snapshotDataSource
5555
pvcDataSource
5656
RWX
5757
volumeLimits # PD Supports volume limits but test is very slow
@@ -72,9 +72,18 @@ func generateDriverConfigFile(pkgDir, storageClassFile, deploymentStrat string)
7272
return "", fmt.Errorf("got unknown deployment strat %s, expected gce or gke", deploymentStrat)
7373
}
7474

75+
var absSnapshotClassFilePath string
76+
// If snapshot class is passed in as argument, include snapshot specific driver capabiltiites.
77+
if snapshotClassFile != "" {
78+
caps = append(caps, "snapshotDataSource")
79+
// Update the absolute file path pointing to the snapshot class file, if it is provided as an argument.
80+
absSnapshotClassFilePath = filepath.Join(pkgDir, testConfigDir, snapshotClassFile)
81+
}
82+
7583
params := driverConfig{
76-
StorageClassFile: filepath.Join(pkgDir, testConfigDir, storageClassFile),
77-
Capabilities: caps,
84+
StorageClassFile: filepath.Join(pkgDir, testConfigDir, storageClassFile),
85+
SnapshotClassFile: absSnapshotClassFilePath,
86+
Capabilities: caps,
7887
}
7988

8089
// Write config file

test/k8s-integration/main.go

+7-5
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ var (
4747
// Test infrastructure flags
4848
boskosResourceType = flag.String("boskos-resource-type", "gce-project", "name of the boskos resource type to reserve")
4949
storageClassFile = flag.String("storageclass-file", "", "name of storageclass yaml file to use for test relative to test/k8s-integration/config")
50+
snapshotClassFile = flag.String("snapshotclass-file", "", "name of snapshotclass yaml file to use for test relative to test/k8s-integration/config")
5051
inProw = flag.Bool("run-in-prow", false, "is the test running in PROW")
5152

5253
// Driver flags
@@ -300,10 +301,9 @@ func handle() error {
300301
}
301302

302303
testSkip := generateTestSkip(normalizedVersion)
303-
304304
// Run the tests using the testDir kubernetes
305305
if len(*storageClassFile) != 0 {
306-
err = runCSITests(pkgDir, testDir, *testFocus, testSkip, *storageClassFile, cloudProviderArgs, *deploymentStrat)
306+
err = runCSITests(pkgDir, testDir, *testFocus, testSkip, *storageClassFile, *snapshotClassFile, cloudProviderArgs, *deploymentStrat)
307307
} else if *migrationTest {
308308
err = runMigrationTests(pkgDir, testDir, *testFocus, testSkip, cloudProviderArgs)
309309
} else {
@@ -318,7 +318,7 @@ func handle() error {
318318
}
319319

320320
func generateTestSkip(normalizedVersion string) string {
321-
skipString := "\\[Disruptive\\]|\\[Serial\\]|\\[Feature:.+\\]"
321+
skipString := "\\[Disruptive\\]|\\[Serial\\]"
322322
switch normalizedVersion {
323323
// Fall-through versioning since all test cases we want to skip in 1.15
324324
// should also be skipped in 1.14
@@ -333,6 +333,8 @@ func generateTestSkip(normalizedVersion string) string {
333333
// bug-fix introduced in 1.17
334334
// (https://github.com/kubernetes/kubernetes/pull/81163)
335335
skipString = skipString + "|volumeMode\\sshould\\snot\\smount\\s/\\smap\\sunused\\svolumes\\sin\\sa\\spod"
336+
// Skip Snapshot tests pre 1.17
337+
skipString = skipString + "|snapshot"
336338
fallthrough
337339
case "1.17":
338340
case "latest":
@@ -359,8 +361,8 @@ func runMigrationTests(pkgDir, testDir, testFocus, testSkip string, cloudProvide
359361
return runTestsWithConfig(testDir, testFocus, testSkip, "--storage.migratedPlugins=kubernetes.io/gce-pd", cloudProviderArgs)
360362
}
361363

362-
func runCSITests(pkgDir, testDir, testFocus, testSkip, storageClassFile string, cloudProviderArgs []string, deploymentStrat string) error {
363-
testDriverConfigFile, err := generateDriverConfigFile(pkgDir, storageClassFile, deploymentStrat)
364+
func runCSITests(pkgDir, testDir, testFocus, testSkip, storageClassFile, snapshotClassFile string, cloudProviderArgs []string, deploymentStrat string) error {
365+
testDriverConfigFile, err := generateDriverConfigFile(pkgDir, storageClassFile, snapshotClassFile, deploymentStrat)
364366
if err != nil {
365367
return err
366368
}

test/run-k8s-integration-local.sh

+10
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,16 @@ make -C ${PKGDIR} test-k8s-integration
4646
# --gce-region="us-central1" --num-nodes=${NUM_NODES:-3} --gke-cluster-version="latest" --deployment-strategy="gke" \
4747
# --test-version="master"
4848

49+
# This version of the command builds and deploys the GCE PD CSI driver.
50+
# Points to a local K8s repository to get the e2e test binary, does not bring up
51+
# or tear down the kubernetes cluster. In addition, it runs External Storage
52+
# snapshot tests for the PD CSI driver.
53+
#${PKGDIR}/bin/k8s-integration-test --run-in-prow=false \
54+
#--staging-image=${GCE_PD_CSI_STAGING_IMAGE} --service-account-file=${GCE_PD_SA_DIR}/cloud-sa.json \
55+
#--deploy-overlay-name=prow-gke-release-staging-head --bringup-cluster=false --teardown-cluster=false --test-focus="External.*Storage.*snapshot" --local-k8s-dir=$KTOP \
56+
#--storageclass-file=sc-standard.yaml --snapshotclass-file=pd-volumesnapshotclass.yaml --do-driver-build=true \
57+
#--gce-zone="us-central1-b" --num-nodes=${NUM_NODES:-3}
58+
4959
# This version of the command does not build the driver or K8s, points to a
5060
# local K8s repo to get the e2e.test binary, and does not bring up or down the cluster
5161

test/run-k8s-integration.sh

+4
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,8 @@ else
4444
base_cmd="${base_cmd} --gce-region=${gce_region}"
4545
fi
4646

47+
if [[ "$overlay_name" =~ .*"gke-release-staging".* ]]; then
48+
base_cmd="${base_cmd} --snapshotclass-file=pd-volumesnapshotclass.yaml"
49+
fi
50+
4751
eval $base_cmd

0 commit comments

Comments
 (0)