diff --git a/test/k8s-integration/config/pd-volumesnapshotclass.yaml b/test/k8s-integration/config/pd-volumesnapshotclass.yaml new file mode 100644 index 000000000..bff9c3cde --- /dev/null +++ b/test/k8s-integration/config/pd-volumesnapshotclass.yaml @@ -0,0 +1,6 @@ +apiVersion: snapshot.storage.k8s.io/v1beta1 +kind: VolumeSnapshotClass +metadata: + name: csi-gce-pd-snapshot-class +driver: pd.csi.storage.gke.io +deletionPolicy: Delete diff --git a/test/k8s-integration/config/test-config-template.in b/test/k8s-integration/config/test-config-template.in index 9cdc2787e..971986a0b 100644 --- a/test/k8s-integration/config/test-config-template.in +++ b/test/k8s-integration/config/test-config-template.in @@ -1,5 +1,9 @@ StorageClass: FromFile: {{.StorageClassFile}} +{{if .SnapshotClassFile }} +SnapshotClass: + FromFile: {{ .SnapshotClassFile }} +{{end}} DriverInfo: Name: csi-gcepd SupportedFsType: diff --git a/test/k8s-integration/driver-config.go b/test/k8s-integration/driver-config.go index e8705883d..00fdc9daf 100644 --- a/test/k8s-integration/driver-config.go +++ b/test/k8s-integration/driver-config.go @@ -9,8 +9,9 @@ import ( ) type driverConfig struct { - StorageClassFile string - Capabilities []string + StorageClassFile string + SnapshotClassFile string + Capabilities []string } const ( @@ -21,7 +22,7 @@ const ( // generateDriverConfigFile loads a testdriver config template and creates a file // with the test-specific configuration -func generateDriverConfigFile(pkgDir, storageClassFile, deploymentStrat string) (string, error) { +func generateDriverConfigFile(pkgDir, storageClassFile, snapshotClassFile, deploymentStrat string) (string, error) { // Load template t, err := template.ParseFiles(filepath.Join(pkgDir, testConfigDir, configTemplateFile)) if err != nil { @@ -51,7 +52,6 @@ func generateDriverConfigFile(pkgDir, storageClassFile, deploymentStrat string) } /* Unsupported Capabilities: - snapshotDataSource pvcDataSource RWX volumeLimits # PD Supports volume limits but test is very slow @@ -72,9 +72,18 @@ func generateDriverConfigFile(pkgDir, storageClassFile, deploymentStrat string) return "", fmt.Errorf("got unknown deployment strat %s, expected gce or gke", deploymentStrat) } + var absSnapshotClassFilePath string + // If snapshot class is passed in as argument, include snapshot specific driver capabiltiites. + if snapshotClassFile != "" { + caps = append(caps, "snapshotDataSource") + // Update the absolute file path pointing to the snapshot class file, if it is provided as an argument. + absSnapshotClassFilePath = filepath.Join(pkgDir, testConfigDir, snapshotClassFile) + } + params := driverConfig{ - StorageClassFile: filepath.Join(pkgDir, testConfigDir, storageClassFile), - Capabilities: caps, + StorageClassFile: filepath.Join(pkgDir, testConfigDir, storageClassFile), + SnapshotClassFile: absSnapshotClassFilePath, + Capabilities: caps, } // Write config file diff --git a/test/k8s-integration/main.go b/test/k8s-integration/main.go index 63f09725b..b807e776b 100644 --- a/test/k8s-integration/main.go +++ b/test/k8s-integration/main.go @@ -47,6 +47,7 @@ var ( // Test infrastructure flags boskosResourceType = flag.String("boskos-resource-type", "gce-project", "name of the boskos resource type to reserve") storageClassFile = flag.String("storageclass-file", "", "name of storageclass yaml file to use for test relative to test/k8s-integration/config") + snapshotClassFile = flag.String("snapshotclass-file", "", "name of snapshotclass yaml file to use for test relative to test/k8s-integration/config") inProw = flag.Bool("run-in-prow", false, "is the test running in PROW") // Driver flags @@ -300,10 +301,9 @@ func handle() error { } testSkip := generateTestSkip(normalizedVersion) - // Run the tests using the testDir kubernetes if len(*storageClassFile) != 0 { - err = runCSITests(pkgDir, testDir, *testFocus, testSkip, *storageClassFile, cloudProviderArgs, *deploymentStrat) + err = runCSITests(pkgDir, testDir, *testFocus, testSkip, *storageClassFile, *snapshotClassFile, cloudProviderArgs, *deploymentStrat) } else if *migrationTest { err = runMigrationTests(pkgDir, testDir, *testFocus, testSkip, cloudProviderArgs) } else { @@ -318,7 +318,7 @@ func handle() error { } func generateTestSkip(normalizedVersion string) string { - skipString := "\\[Disruptive\\]|\\[Serial\\]|\\[Feature:.+\\]" + skipString := "\\[Disruptive\\]|\\[Serial\\]" switch normalizedVersion { // Fall-through versioning since all test cases we want to skip in 1.15 // should also be skipped in 1.14 @@ -333,6 +333,8 @@ func generateTestSkip(normalizedVersion string) string { // bug-fix introduced in 1.17 // (https://github.com/kubernetes/kubernetes/pull/81163) skipString = skipString + "|volumeMode\\sshould\\snot\\smount\\s/\\smap\\sunused\\svolumes\\sin\\sa\\spod" + // Skip Snapshot tests pre 1.17 + skipString = skipString + "|snapshot" fallthrough case "1.17": case "latest": @@ -359,8 +361,8 @@ func runMigrationTests(pkgDir, testDir, testFocus, testSkip string, cloudProvide return runTestsWithConfig(testDir, testFocus, testSkip, "--storage.migratedPlugins=kubernetes.io/gce-pd", cloudProviderArgs) } -func runCSITests(pkgDir, testDir, testFocus, testSkip, storageClassFile string, cloudProviderArgs []string, deploymentStrat string) error { - testDriverConfigFile, err := generateDriverConfigFile(pkgDir, storageClassFile, deploymentStrat) +func runCSITests(pkgDir, testDir, testFocus, testSkip, storageClassFile, snapshotClassFile string, cloudProviderArgs []string, deploymentStrat string) error { + testDriverConfigFile, err := generateDriverConfigFile(pkgDir, storageClassFile, snapshotClassFile, deploymentStrat) if err != nil { return err } diff --git a/test/run-k8s-integration-local.sh b/test/run-k8s-integration-local.sh index d3f76df32..dd507dda4 100755 --- a/test/run-k8s-integration-local.sh +++ b/test/run-k8s-integration-local.sh @@ -46,6 +46,16 @@ make -C ${PKGDIR} test-k8s-integration # --gce-region="us-central1" --num-nodes=${NUM_NODES:-3} --gke-cluster-version="latest" --deployment-strategy="gke" \ # --test-version="master" +# This version of the command builds and deploys the GCE PD CSI driver. +# Points to a local K8s repository to get the e2e test binary, does not bring up +# or tear down the kubernetes cluster. In addition, it runs External Storage +# snapshot tests for the PD CSI driver. +#${PKGDIR}/bin/k8s-integration-test --run-in-prow=false \ +#--staging-image=${GCE_PD_CSI_STAGING_IMAGE} --service-account-file=${GCE_PD_SA_DIR}/cloud-sa.json \ +#--deploy-overlay-name=prow-gke-release-staging-head --bringup-cluster=false --teardown-cluster=false --test-focus="External.*Storage.*snapshot" --local-k8s-dir=$KTOP \ +#--storageclass-file=sc-standard.yaml --snapshotclass-file=pd-volumesnapshotclass.yaml --do-driver-build=true \ +#--gce-zone="us-central1-b" --num-nodes=${NUM_NODES:-3} + # This version of the command does not build the driver or K8s, points to a # local K8s repo to get the e2e.test binary, and does not bring up or down the cluster diff --git a/test/run-k8s-integration.sh b/test/run-k8s-integration.sh index b321da3d0..07abc9a49 100755 --- a/test/run-k8s-integration.sh +++ b/test/run-k8s-integration.sh @@ -44,4 +44,8 @@ else base_cmd="${base_cmd} --gce-region=${gce_region}" fi +if [[ "$overlay_name" =~ .*"gke-release-staging".* ]]; then + base_cmd="${base_cmd} --snapshotclass-file=pd-volumesnapshotclass.yaml" +fi + eval $base_cmd