Skip to content

Commit 121c7e0

Browse files
authored
Merge pull request #1274 from yaozile123/file-cache-testsuit-refactor
File cache testsuit refactor
2 parents f30c3d0 + 1c384fd commit 121c7e0

File tree

10 files changed

+1525
-191
lines changed

10 files changed

+1525
-191
lines changed

pkg/sidecar_mounter/sidecar_mounter_config.go

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -80,23 +80,28 @@ type sidecarRetryConfig struct {
8080

8181
var prometheusPort = 62990
8282

83-
// disallowedFlags is a map of flags that are not allowed to be passed to gcsfuse directly.
84-
// Note: If you add more disallowed flags here, you should update the disallowedFlagsMapping
85-
// in test/e2e/utils/utils.go to ensure they are correctly translated to the config file format.
86-
var disallowedFlags = map[string]bool{
87-
"temp-dir": true,
88-
"config-file": true,
89-
"foreground": true,
90-
"log-file": true,
91-
"log-format": true,
92-
"key-file": true,
93-
"token-url": true,
94-
"reuse-token-from-url": true,
95-
"o": true,
96-
"cache-dir": true,
97-
"prometheus-port": true,
98-
"kernel-params-file": true,
99-
KernelParamsFileConfigFlag: true,
83+
// DisallowedFlags is a map of flags that are disallowed to be passed to sidecar mounter directly.
84+
// They are mapped to their config file style representation so that they can be passed in config file format
85+
// as a workaround to bypass the disallowed flags validation.
86+
// Note: If you add a new disallowed flag here that is needed for integration testing,
87+
// you should also update the ParseConfigFlags() logic in test/e2e/utils/utils.go to handle it.
88+
var DisallowedFlags = map[string]string{
89+
// The following flags are explicitly handled in test/e2e/utils/utils.go
90+
"log-file": "logging:file-path",
91+
"log-format": "logging:format",
92+
"o": "o",
93+
"cache-dir": "cache-dir",
94+
95+
// --- Unused in test/e2e/utils/utils.go ---
96+
"temp-dir": "temp-dir",
97+
"config-file": "config-file",
98+
"foreground": "foreground",
99+
"key-file": "gcs-auth:key-file",
100+
"token-url": "gcs-auth:token-url",
101+
"reuse-token-from-url": "gcs-auth:reuse-token-from-url",
102+
"prometheus-port": "prometheus-port",
103+
"kernel-params-file": "file-system:kernel-params-file",
104+
KernelParamsFileConfigFlag: KernelParamsFileConfigFlag,
100105
}
101106

102107
// Fetch the following information from a given socket path:
@@ -218,7 +223,7 @@ func (mc *MountConfig) prepareMountArgs() {
218223
continue
219224
}
220225

221-
if disallowedFlags[f] {
226+
if _, ok := DisallowedFlags[f]; ok {
222227
invalidArgs = append(invalidArgs, arg)
223228
} else {
224229
configFileFlagMap[f] = v
@@ -239,7 +244,7 @@ func (mc *MountConfig) prepareMountArgs() {
239244
}
240245

241246
flag := argPair[0]
242-
if disallowedFlags[flag] {
247+
if _, ok := DisallowedFlags[flag]; ok {
243248
invalidArgs = append(invalidArgs, arg)
244249

245250
continue

test/e2e/testsuites/gcsfuse_integration.go

Lines changed: 103 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ const (
5656
testNameInactiveStreamTimeout = "inactive_stream_timeout"
5757
testNameBufferedReads = "buffered_read"
5858
testNameRenameSymlink = "rename_symlink"
59+
testNameRapidAppends = "rapid_appends"
5960

6061
testNamePrefixSucceed = "should succeed in "
6162

@@ -72,6 +73,15 @@ const (
7273
gcsfuseGoEnvSetupFormat = "export GO_VERSION=$(%v) && export GOTOOLCHAIN=go$GO_VERSION && export PATH=$PATH:/usr/local/go/bin"
7374
)
7475

76+
// testPackageTimeoutMap controls the duration of the `-timeout` flag passed to the underlying `go test` executions.
77+
// If you need to extend the timeout for a specific test package, add or modify its limit in minutes here.
78+
var testPackageTimeoutMap = map[string]int{
79+
testNameListLargeDir: 60,
80+
testNameWriteLargeFiles: 60,
81+
testNameReadLargeFiles: 60,
82+
testNameRapidAppends: 60,
83+
}
84+
7585
var GCSFuseVersionStr = ""
7686

7787
const gcsfuseGoVersionLegacyCommand = `grep -o 'go[0-9]\+\.[0-9]\+\.[0-9]\+' ./gcsfuse/tools/cd_scripts/e2e_test.sh | cut -c3-`
@@ -94,6 +104,31 @@ func zbEnabled(driver storageframework.TestDriver) bool {
94104
return gcsfuseCSITestDriver.EnableZB
95105
}
96106

107+
// flatEnabled checks if the Flat Namespace feature is enabled for the given driver.
108+
func flatEnabled(driver storageframework.TestDriver) bool {
109+
gcsfuseCSITestDriver, ok := driver.(*specs.GCSFuseCSITestDriver)
110+
gomega.Expect(ok).To(gomega.BeTrue(), "failed to cast storageframework.TestDriver to *specs.GCSFuseCSITestDriver")
111+
112+
return !gcsfuseCSITestDriver.EnableHierarchicalNamespace && !gcsfuseCSITestDriver.EnableZB
113+
}
114+
115+
// isConfigCompatible returns true if the parsed config is compatible with the current driver setup.
116+
func isConfigCompatible(config utils.TestConfig, driver storageframework.TestDriver) bool {
117+
if !config.RunOnGke {
118+
return false
119+
}
120+
if !config.Compatible.Flat && flatEnabled(driver) {
121+
return false
122+
}
123+
if !config.Compatible.HNS && hnsEnabled(driver) && !zbEnabled(driver) {
124+
return false
125+
}
126+
if !config.Compatible.Zonal && zbEnabled(driver) {
127+
return false
128+
}
129+
return true
130+
}
131+
97132
// getGoParsingCommand returns the command to get the go version for the gcsfuse integration tests based on the gcsfuse version and branch.
98133
// In gcsfuse v3.7.0 the go location was moved to a centralized dir ./gcsfuse/.go-version.
99134
// If using v3.6.0 or older, we use gcsfuseGoVersionLegacyCommand; otherwise we use gcsfuseCentralizedLocationGoVersionCommand.
@@ -113,6 +148,72 @@ func getClientProtocol(driver storageframework.TestDriver) string {
113148
return gcsfuseCSITestDriver.ClientProtocol
114149
}
115150

151+
type TestCommandConfig struct {
152+
TestPkg string
153+
TestName string
154+
GoEnvSetupCmd string
155+
MountPath string
156+
SecondaryMountPath string // Optional
157+
BucketName string
158+
OnlyDir string
159+
}
160+
161+
// generateTestCommand constructs the test command for validating file cache parameters.
162+
// This is used dynamically across the file cache logic tests including parallel downloads.
163+
func generateTestCommand(opts TestCommandConfig) string {
164+
timeoutStr := ""
165+
if t, ok := testPackageTimeoutMap[opts.TestPkg]; ok {
166+
timeoutStr = fmt.Sprintf(" -timeout %dm", t)
167+
}
168+
169+
goTestCmd := fmt.Sprintf("GODEBUG=asyncpreemptoff=1 go test ./%v/... -p 1 --integrationTest -v --config-file=../test_config.yaml%s", opts.TestPkg, timeoutStr)
170+
if opts.TestName != "" {
171+
goTestCmd = fmt.Sprintf("GODEBUG=asyncpreemptoff=1 go test ./%v/... -p 1 --integrationTest -v -run ^%v$ --config-file=../test_config.yaml%s", opts.TestPkg, opts.TestName, timeoutStr)
172+
}
173+
174+
commandArgs := []string{
175+
fmt.Sprintf(gcsfuseGoEnvSetupFormat, opts.GoEnvSetupCmd),
176+
fmt.Sprintf("export MOUNTED_DIR=%q", opts.MountPath),
177+
}
178+
179+
if opts.SecondaryMountPath != "" {
180+
commandArgs = append(commandArgs, fmt.Sprintf("export MOUNTED_DIR_SECONDARY=%q", opts.SecondaryMountPath))
181+
}
182+
183+
commandArgs = append(commandArgs,
184+
fmt.Sprintf("export BUCKET_NAME=%q", opts.BucketName),
185+
fmt.Sprintf("export ONLY_DIR=%q", opts.OnlyDir),
186+
fmt.Sprintf("cd %v", gcsfuseIntegrationTestsBasePath),
187+
goTestCmd,
188+
)
189+
190+
return strings.Join(commandArgs, " && ")
191+
}
192+
193+
// configureLargeFileResources configures the pod and sidecar resources for memory-intensive large file tests.
194+
// Note: We only increase memory limits for specific tests like testNameWriteLargeFiles, testNameReadLargeFiles
195+
// and testNameRapidAppends. Other test cases run stable within the default memory for now
196+
// limits and do not require additional resources.
197+
func configureLargeFileResources(tPod *specs.TestPod, testNameOrPkg string, driver storageframework.TestDriver) (string, string) {
198+
sidecarMemoryLimit := defaultSidecarMemoryLimit
199+
sidecarMemoryRequest := defaultSidecarMemoryRequest
200+
201+
if testNameOrPkg == testNameWriteLargeFiles || testNameOrPkg == testNameReadLargeFiles {
202+
tPod.SetResource("1", "8Gi", "5Gi")
203+
sidecarMemoryLimit = "1Gi"
204+
if zbEnabled(driver) {
205+
sidecarMemoryRequest = "1Gi"
206+
sidecarMemoryLimit = "2Gi"
207+
}
208+
}
209+
if testNameOrPkg == testNameRapidAppends {
210+
sidecarMemoryRequest = "2Gi"
211+
sidecarMemoryLimit = "3Gi"
212+
}
213+
214+
return sidecarMemoryRequest, sidecarMemoryLimit
215+
}
216+
116217
type gcsFuseCSIGCSFuseIntegrationTestSuite struct {
117218
tsInfo storageframework.TestSuiteInfo
118219
}
@@ -260,17 +361,8 @@ func (t *gcsFuseCSIGCSFuseIntegrationTestSuite) DefineTests(driver storageframew
260361
tPod := specs.NewTestPod(f.ClientSet, f.Namespace)
261362
tPod.SetImage(specs.GolangImage)
262363
tPod.SetResource("1", "5Gi", "5Gi")
263-
sidecarMemoryLimit := defaultSidecarMemoryLimit
264-
sidecarMemoryRequest := defaultSidecarMemoryRequest
265-
266-
if testName == testNameWriteLargeFiles || testName == testNameReadLargeFiles {
267-
tPod.SetResource("1", "6Gi", "5Gi")
268-
sidecarMemoryLimit = "1Gi"
269-
if zbEnabled(driver) {
270-
sidecarMemoryRequest = "1Gi"
271-
sidecarMemoryLimit = "2Gi"
272-
}
273-
}
364+
365+
sidecarMemoryRequest, sidecarMemoryLimit := configureLargeFileResources(tPod, testName, driver)
274366

275367
mo := l.volumeResource.VolSource.CSI.VolumeAttributes["mountOptions"]
276368
if testName == testNameExplicitDir && strings.Contains(mo, "only-dir") {

0 commit comments

Comments
 (0)