Skip to content

Commit 25f8d13

Browse files
committed
Enable XFS selectively for GKE clusters with proper COS support
1 parent 12ea362 commit 25f8d13

File tree

2 files changed

+63
-14
lines changed

2 files changed

+63
-14
lines changed

test/k8s-integration/driver-config.go

Lines changed: 53 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import (
55
"fmt"
66
"os"
77
"path/filepath"
8+
"regexp"
9+
"strconv"
810
"strings"
911
"text/template"
1012
)
@@ -70,7 +72,6 @@ func generateDriverConfigFile(platform, pkgDir, storageClassFile, snapshotClassF
7072
"ext2",
7173
"ext3",
7274
"ext4",
73-
"xfs",
7475
}
7576
}
7677

@@ -82,12 +83,25 @@ func generateDriverConfigFile(platform, pkgDir, storageClassFile, snapshotClassF
8283
dataSource
8384
*/
8485

85-
// TODO: Support adding/removing capabilities based on Kubernetes version.
8686
switch deploymentStrat {
8787
case "gke":
88-
fallthrough
89-
case "gce":
9088
caps = append(caps, "controllerExpansion", "nodeExpansion")
89+
if *imageType == "cos" {
90+
major, minor, err := getGKEClusterVersion()
91+
if err != nil {
92+
return "", fmt.Errorf("Cannot find GKE cluster version to set driver config: %w", err)
93+
}
94+
if major > 1 || minor >= 18 {
95+
// COS supports XFS from 1.18 on.
96+
fsTypes = append(fsTypes, "xfs")
97+
}
98+
// Otherwise XFS is not supported on COS.
99+
} else {
100+
// XFS is supported on all non-COS images.
101+
fsTypes = append(fsTypes, "xfs")
102+
}
103+
case "gce":
104+
fsTypes = append(fsTypes, "xfs")
91105
default:
92106
return "", fmt.Errorf("got unknown deployment strat %s, expected gce or gke", deploymentStrat)
93107
}
@@ -124,3 +138,38 @@ func generateDriverConfigFile(platform, pkgDir, storageClassFile, snapshotClassF
124138

125139
return configFilePath, nil
126140
}
141+
142+
func getGKEClusterVersion() (major, minor int, err error) {
143+
if *gkeClusterVer == "" && *gkeReleaseChannel == "" {
144+
return 0, 0, fmt.Errorf("No GKE version found")
145+
}
146+
// TODO: the release channels are hardcoded (as is latest, below), which means they will need to be updated at each GKE release. It would be better to find the version automatically, maybe through gcloud container get-server-config.
147+
switch *gkeReleaseChannel {
148+
case "": // Use gkeClusterVer instead.
149+
case "rapid":
150+
return 1, 18, nil
151+
case "regular":
152+
return 1, 17, nil
153+
case "stable":
154+
return 1, 16, nil
155+
}
156+
157+
if *gkeClusterVer == "latest" {
158+
return 1, 17, nil
159+
}
160+
161+
versionRE := regexp.MustCompile(`^(\d+)\.(\d+)`)
162+
matches := versionRE.FindStringSubmatch(*gkeClusterVer)
163+
if len(matches) != 3 {
164+
return 0, 0, fmt.Errorf("Unknown GKE cluster version %s", *gkeClusterVer)
165+
}
166+
major, err = strconv.Atoi(matches[1])
167+
if err != nil || major < 1 {
168+
return 0, 0, fmt.Errorf("Couldn't parse major version %s in %s: %w", matches[1], *gkeClusterVer, err)
169+
}
170+
minor, err = strconv.Atoi(matches[2])
171+
if err != nil || minor < 0 {
172+
return 0, 0, fmt.Errorf("Couldn't parse minor version %s in %s: %w", matches[2], *gkeClusterVer, err)
173+
}
174+
return
175+
}

test/run-k8s-integration-local.sh

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/bin/bash
1+
#!/bin/bash -x
22

33
set -o nounset
44
set -o errexit
@@ -65,11 +65,11 @@ make -C "${PKGDIR}" test-k8s-integration
6565
# This version of the command brings up (and subsequently tears down) a GKE
6666
# cluster using a release channel, and with managed GCE PersistentDisk CSI driver add-on enabled, and points to
6767
# the local K8s repository to get the e2e test binary.
68-
# ${PKGDIR}/bin/k8s-integration-test --run-in-prow=false --service-account-file=${GCE_PD_SA_DIR}/cloud-sa.json \
69-
# --test-focus="External.Storage" --local-k8s-dir=$KTOP --storageclass-files=sc-standard.yaml,sc-balanced.yaml,sc-ssd.yaml \
70-
# --snapshotclass-file=pd-volumesnapshotclass.yaml --do-driver-build=false --teardown-driver=false \
71-
# --gce-zone="us-central1-c" --num-nodes=${NUM_NODES:-3} --gke-release-channel="rapid" --deployment-strategy="gke" \
72-
# --use-gke-managed-driver=true --teardown-cluster=true
68+
${PKGDIR}/bin/k8s-integration-test --run-in-prow=false \
69+
--test-focus="External.Storage.*XFS" --local-k8s-dir=$KTOP --storageclass-files=sc-standard.yaml \
70+
--snapshotclass-file=pd-volumesnapshotclass.yaml --do-driver-build=false --teardown-driver=false \
71+
--gce-zone="us-central1-c" --num-nodes=${NUM_NODES:-3} --gke-release-channel="rapid" --deployment-strategy="gke" \
72+
--use-gke-managed-driver=true --teardown-cluster=true --bringup-cluster=true
7373

7474
# This version of the command does not build the driver or K8s, points to a local K8s repo to get
7575
# the e2e.test binary, does not bring up or down the cluster, and uses application default
@@ -84,10 +84,10 @@ make -C "${PKGDIR}" test-k8s-integration
8484
#
8585
# As with all other methods local credentials must be set by running
8686
# gcloud auth application-default login
87-
"${PKGDIR}/bin/k8s-integration-test" --run-in-prow=false \
88-
--deploy-overlay-name=noauth --bringup-cluster=false --teardown-cluster=false --local-k8s-dir="$KTOP" \
89-
--storageclass-files=sc-standard.yaml --do-driver-build=false --test-focus='External.Storage' \
90-
--gce-zone="us-central1-b" --num-nodes="${NUM_NODES:-3}"
87+
# "${PKGDIR}/bin/k8s-integration-test" --run-in-prow=false \
88+
# --deploy-overlay-name=noauth --bringup-cluster=false --teardown-cluster=false --local-k8s-dir="$KTOP" \
89+
# --storageclass-files=sc-standard.yaml --do-driver-build=false --test-focus='External.Storage' \
90+
# --gce-zone="us-central1-b" --num-nodes="${NUM_NODES:-3}"
9191

9292

9393
# This version of the command does not build the driver or K8s, points to a

0 commit comments

Comments
 (0)