Skip to content

Commit 12ea362

Browse files
authored
Merge pull request kubernetes-sigs#621 from mattcary/regional
Add test support for regional PD
2 parents e68d03c + 9d1ce53 commit 12ea362

File tree

6 files changed

+75
-17
lines changed

6 files changed

+75
-17
lines changed

test/k8s-integration/cluster.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ func gkeLocationArgs(gceZone, gceRegion string) (locationArg, locationVal string
3030
return
3131
}
3232

33+
func isRegionalGKECluster(gceZone, gceRegion string) bool {
34+
return len(gceRegion) > 0
35+
}
36+
3337
func clusterDownGCE(k8sDir string) error {
3438
cmd := exec.Command(filepath.Join(k8sDir, "hack", "e2e-internal", "e2e-down.sh"))
3539
err := runCommand("Bringing Down E2E Cluster on GCE", cmd)
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
apiVersion: storage.k8s.io/v1
2+
kind: StorageClass
3+
metadata:
4+
name: csi-gcepd-regional
5+
provisioner: pd.csi.storage.gke.io
6+
parameters:
7+
type: pd-standard
8+
replication-type: regional-pd
9+
volumeBindingMode: WaitForFirstConsumer

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ DriverInfo:
1919
debug:
2020
nouid32:
2121
SupportedSizeRange:
22-
Min: 5Gi
22+
Min: {{.MinimumVolumeSize}}
2323
Max: 64Ti
2424
TopologyKeys:
2525
- topology.gke.io/zone
26+
NumAllowedTopologies: {{.NumAllowedTopologies}}

test/k8s-integration/driver-config.go

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,13 @@ import (
1010
)
1111

1212
type driverConfig struct {
13-
StorageClassFile string
14-
StorageClass string
15-
SnapshotClassFile string
16-
Capabilities []string
17-
SupportedFsType []string
13+
StorageClassFile string
14+
StorageClass string
15+
SnapshotClassFile string
16+
Capabilities []string
17+
SupportedFsType []string
18+
MinimumVolumeSize string
19+
NumAllowedTopologies int
1820
}
1921

2022
const (
@@ -98,12 +100,20 @@ func generateDriverConfigFile(platform, pkgDir, storageClassFile, snapshotClassF
98100
absSnapshotClassFilePath = filepath.Join(pkgDir, testConfigDir, snapshotClassFile)
99101
}
100102

103+
minimumVolumeSize := "5Gi"
104+
numAllowedTopologies := 1
105+
if storageClassFile == regionalPDStorageClass {
106+
minimumVolumeSize = "200Gi"
107+
numAllowedTopologies = 2
108+
}
101109
params := driverConfig{
102-
StorageClassFile: filepath.Join(pkgDir, testConfigDir, storageClassFile),
103-
StorageClass: storageClassFile[:strings.LastIndex(storageClassFile, ".")],
104-
SnapshotClassFile: absSnapshotClassFilePath,
105-
SupportedFsType: fsTypes,
106-
Capabilities: caps,
110+
StorageClassFile: filepath.Join(pkgDir, testConfigDir, storageClassFile),
111+
StorageClass: storageClassFile[:strings.LastIndex(storageClassFile, ".")],
112+
SnapshotClassFile: absSnapshotClassFilePath,
113+
SupportedFsType: fsTypes,
114+
Capabilities: caps,
115+
MinimumVolumeSize: minimumVolumeSize,
116+
NumAllowedTopologies: numAllowedTopologies,
107117
}
108118

109119
// Write config file

test/k8s-integration/main.go

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ var (
4949
gkeReleaseChannel = flag.String("gke-release-channel", "", "GKE release channel to be used for cluster deploy. One of 'rapid', 'stable' or 'regular'")
5050
gkeTestClusterName = flag.String("gke-cluster-name", "gcp-pd-csi-driver-test-cluster", "GKE cluster name")
5151
gkeNodeVersion = flag.String("gke-node-version", "", "GKE cluster worker node version")
52+
isRegionalCluster = flag.Bool("is-regional-cluster", false, "tell the test that a regional cluster is being used. Should be used for running on an existing regional cluster (ie, --bringup-cluster=false). The test will fail if a zonal GKE cluster is created when this flag is true")
5253

5354
// Test infrastructure flags
5455
boskosResourceType = flag.String("boskos-resource-type", "gce-project", "name of the boskos resource type to reserve")
@@ -74,6 +75,7 @@ const (
7475
k8sOutOfDockerBuildBinDir = "_output/bin"
7576
externalDriverNamespace = "gce-pd-csi-driver"
7677
managedDriverNamespace = "kube-system"
78+
regionalPDStorageClass = "sc-regional.yaml"
7779
)
7880

7981
func init() {
@@ -97,11 +99,11 @@ func main() {
9799
ensureVariable(deployOverlayName, false, "'deploy-overlay-name' must not be set when using GKE managed driver")
98100
}
99101

100-
if *deployOverlayName != "noauth" {
101-
ensureVariable(saFile, true, "service-account-file is a required flag")
102-
}
103102
if !*useGKEManagedDriver {
104103
ensureVariable(deployOverlayName, true, "deploy-overlay-name is a required flag")
104+
if *deployOverlayName != "noauth" {
105+
ensureVariable(saFile, true, "service-account-file is a required flag")
106+
}
105107
}
106108

107109
ensureVariable(testFocus, true, "test-focus is a required flag")
@@ -122,6 +124,9 @@ func main() {
122124
ensureVariable(kubeFeatureGates, false, "kube-feature-gates set but not bringing up new cluster")
123125
} else {
124126
ensureVariable(imageType, true, "image type is a required flag. Available options include 'cos' and 'ubuntu'")
127+
if *isRegionalCluster {
128+
klog.Error("is-regional-cluster can only be set when using an existing cluster")
129+
}
125130
}
126131

127132
if *platform == "windows" {
@@ -269,6 +274,14 @@ func handle() error {
269274
testDir = k8sDir
270275
}
271276

277+
if *deploymentStrat == "gke" {
278+
gkeRegional := isRegionalGKECluster(*gceZone, *gceRegion)
279+
if *isRegionalCluster && !gkeRegional {
280+
return fmt.Errorf("--is-regional-cluster set but deployed GKE cluster would be zonal")
281+
}
282+
*isRegionalCluster = gkeRegional
283+
}
284+
272285
// Create a cluster either through GKE or GCE
273286
if *bringupCluster {
274287
var err error = nil
@@ -418,10 +431,24 @@ func handle() error {
418431

419432
// Run the tests using the testDir kubernetes
420433
if len(*storageClassFiles) != 0 {
421-
storageClasses := strings.Split(*storageClassFiles, ",")
434+
applicableStorageClassFiles := []string{}
435+
for _, rawScFile := range strings.Split(*storageClassFiles, ",") {
436+
scFile := strings.TrimSpace(rawScFile)
437+
if len(scFile) == 0 {
438+
continue
439+
}
440+
if scFile == regionalPDStorageClass && !*isRegionalCluster {
441+
klog.Warningf("Skipping regional StorageClass in zonal cluster")
442+
continue
443+
}
444+
applicableStorageClassFiles = append(applicableStorageClassFiles, scFile)
445+
}
446+
if len(applicableStorageClassFiles) == 0 {
447+
return fmt.Errorf("No applicable storage classes found")
448+
}
422449
var ginkgoErrors []string
423450
var testOutputDirs []string
424-
for _, scFile := range storageClasses {
451+
for _, scFile := range applicableStorageClassFiles {
425452
outputDir := strings.TrimSuffix(scFile, ".yaml")
426453
testOutputDirs = append(testOutputDirs, outputDir)
427454
if err = runCSITests(*platform, pkgDir, testDir, *testFocus, testSkip, scFile,

test/run-k8s-integration-ci.sh

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,21 @@ readonly gke_release_channel=${GKE_RELEASE_CHANNEL:-""}
2525
readonly teardown_driver=${GCE_PD_TEARDOWN_DRIVER:-true}
2626
readonly gke_node_version=${GKE_NODE_VERSION:-}
2727
readonly run_intree_plugin_tests=${RUN_INTREE_PLUGIN_TESTS:-false}
28+
29+
storage_classes=sc-standard.yaml,sc-balanced.yaml,sc-ssd.yaml
30+
31+
if [[ -n $gce_region ]] ; then
32+
storage_classes="${storage_classes}",sc-regional
33+
fi
34+
2835
export GCE_PD_VERBOSITY=9
2936

3037
make -C "${PKGDIR}" test-k8s-integration
3138

3239
base_cmd="${PKGDIR}/bin/k8s-integration-test \
3340
--run-in-prow=true --service-account-file=${E2E_GOOGLE_APPLICATION_CREDENTIALS} \
3441
--do-driver-build=${do_driver_build} --teardown-driver=${teardown_driver} --boskos-resource-type=${boskos_resource_type} \
35-
--storageclass-files=sc-standard.yaml,sc-balanced.yaml,sc-ssd.yaml --snapshotclass-file=pd-volumesnapshotclass.yaml \
42+
--storageclass-files="${storage_classes}" --snapshotclass-file=pd-volumesnapshotclass.yaml \
3643
--deployment-strategy=${deployment_strategy} --test-version=${test_version} \
3744
--num-nodes=3 --image-type=${image_type}"
3845

0 commit comments

Comments
 (0)