Skip to content

Provide optional flags to run PD CSI driver snapshot tests #505

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions test/k8s-integration/config/pd-volumesnapshotclass.yaml
Original file line number Diff line number Diff line change
@@ -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
4 changes: 4 additions & 0 deletions test/k8s-integration/config/test-config-template.in
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
StorageClass:
FromFile: {{.StorageClassFile}}
{{if .SnapshotClassFile }}
SnapshotClass:
FromFile: {{ .SnapshotClassFile }}
{{end}}
DriverInfo:
Name: csi-gcepd
SupportedFsType:
Expand Down
21 changes: 15 additions & 6 deletions test/k8s-integration/driver-config.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ import (
)

type driverConfig struct {
StorageClassFile string
Capabilities []string
StorageClassFile string
SnapshotClassFile string
Capabilities []string
}

const (
Expand All @@ -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 {
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
12 changes: 7 additions & 5 deletions test/k8s-integration/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand All @@ -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
Expand All @@ -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":
Expand All @@ -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
}
Expand Down
10 changes: 10 additions & 0 deletions test/run-k8s-integration-local.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 4 additions & 0 deletions test/run-k8s-integration.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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