Skip to content

Commit 8138dfb

Browse files
committed
Update utils_test.go and add more comments
1 parent 56b6b8e commit 8138dfb

6 files changed

Lines changed: 46 additions & 50 deletions

File tree

test/e2e/e2e_test.go

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -90,33 +90,6 @@ var _ = func() bool {
9090
return true
9191
}()
9292

93-
// fetchGCSFuseVersion initiates a minimal, standalone framework to query the cluster sidecar
94-
// during the init() phase. This enables dynamic test tree construction depending on the
95-
// version found in the remote cluster.
96-
// func fetchGCSFuseVersion() string {
97-
// config, err := framework.LoadConfig()
98-
// if err != nil {
99-
// klog.Fatalf("failed to load kube config for standalone version fetch: %v", err)
100-
// }
101-
// k8sClient, err := k8sclientset.NewForConfig(config)
102-
// if err != nil {
103-
// klog.Fatalf("failed to create client for standalone version fetch: %v", err)
104-
// }
105-
106-
// minimalFramework := &framework.Framework{
107-
// ClientSet: k8sClient,
108-
// Namespace: &corev1.Namespace{
109-
// ObjectMeta: metav1.ObjectMeta{
110-
// Name: "default",
111-
// },
112-
// },
113-
// }
114-
// ctx := context.Background()
115-
// versionStr := specs.GetGCSFuseVersion(ctx, minimalFramework)
116-
// klog.Infof("Fetched GCSFuse version globally: %s", versionStr)
117-
// return versionStr
118-
// }
119-
12093
func TestE2E(t *testing.T) {
12194
t.Parallel()
12295

test/e2e/testsuites/gcsfuse_integration.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ func (t *gcsFuseCSIGCSFuseIntegrationTestSuite) DefineTests(driver storageframew
180180
v, branch := utils.GCSFuseBranch(gcsfuseVersionStr)
181181

182182
// Rename_symlink tests are in separat test package only of v2.11.4 for now
183-
if testName == testNameRenameSymlink && (v.AtLeast(version.MustParseSemantic("v3.0.0-gke.0")) || v.LessThan(version.MustParseSemantic("v2.11.4-gke.0")) || branch == utils.MasterBranchName) {
183+
if testName == testNameRenameSymlink && (branch == utils.MasterBranchName || (v.AtLeast(version.MustParseSemantic("v3.0.0-gke.0")) || v.LessThan(version.MustParseSemantic("v2.11.4-gke.0")))) {
184184
e2eskipper.Skipf("skip gcsfuse integration rename_symlink test on gcsfuse version %v", v.String())
185185
}
186186

test/e2e/testsuites/gcsfuse_integration_file_cache_parallel_downloads.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ func (t *gcsFuseCSIGCSFuseIntegrationFileCacheParallelDownloadsTestSuite) Define
112112
return branch
113113
}
114114

115+
// TODO: Remove this once all supported GCSFuse versions support test_config.yaml.
115116
gcsfuseIntegrationFileCacheTest := func(testName string, readOnly bool, fileCacheCapacity, fileCacheForRangeRead, metadataCacheTTLSeconds string, mountOptions ...string) {
116117
ginkgo.By("Checking GCSFuse version and skip test if needed")
117118
ginkgo.By(fmt.Sprintf("Running integration test %v with GCSFuse version %v", testName, GCSFuseVersionStr))
@@ -328,6 +329,7 @@ func (t *gcsFuseCSIGCSFuseIntegrationFileCacheParallelDownloadsTestSuite) Define
328329
}
329330
}
330331

332+
// TODO: Remove this once all supported GCSFuse versions support test_config.yaml.
331333
generateStaticTests := func() {
332334
// The following test cases are derived from https://github.com/GoogleCloudPlatform/gcsfuse/blob/master/tools/integration_tests/run_tests_mounted_directory.sh
333335

@@ -467,10 +469,9 @@ func (t *gcsFuseCSIGCSFuseIntegrationFileCacheParallelDownloadsTestSuite) Define
467469

468470
framework.Logf("Generating tests based on test config")
469471

470-
// The gcsfuse test_config.yaml is introduced from the gcsfuse v3.5+.
471-
// If the gcsfuse version is less than v3.5+, we will use the static tests.
472+
// The gcsfuse test_config.yaml is introduced from the gcsfuse v3.7+.
473+
// If the gcsfuse version is less than v3.7+, we will use the static tests.
472474
// We will remove the static tests in the future.
473-
474475
if utils.IsReadFromTestConfig(GCSFuseVersionStr) {
475476
klog.Info("Generating tests based on test config")
476477
generateDynamicTests(GCSFuseVersionStr)

test/e2e/utils/handler.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ func Handle(testParams *TestParameters) error {
298298

299299
gcsfuseVersion, err := FetchGCSFuseVersion(context.Background(), k8sclientset)
300300
if err != nil {
301-
klog.Warningf("Failed to fetch GCSFuse version from cluster: %v. Tests might skip or fail if depending on this version.", err)
301+
return fmt.Errorf("failed to fetch GCSFuse version from cluster: %v. Tests might skip or fail if depending on this version.", err)
302302
} else {
303303
klog.Infof("Fetched GCSFuse version from cluster: %s", gcsfuseVersion)
304304
// Exporting the version so Ginkgo specs can read it

test/e2e/utils/utils.go

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ import (
4343
const (
4444
DefaultNamespace = "default"
4545
MinGCSFuseKernelParamsVersion = "v3.7.0-gke.0"
46-
MinGCSFuseTestConfigVersion = "v3.5.0-gke.0"
46+
MinGCSFuseTestConfigVersion = "v3.7.0-gke.0"
4747

4848
GcsfuseVersionVarName = "gcsfuse-version"
4949

@@ -190,7 +190,7 @@ func ParseTestConfig(body []byte) (TestPackages, error) {
190190
}
191191

192192
func IsParallelDownloadsEnabled(flag string) bool {
193-
return strings.Contains(flag, "file-cache-enable-parallel-downloads") && !strings.Contains(flag, "file-cache-enable-parallel-downloads=false")
193+
return strings.Contains(flag, flagFileCacheEnableParallelDownloads) && !strings.Contains(flag, flagFileCacheEnableParallelDownloads+"=false")
194194
}
195195

196196
func IsFileCacheEnabled(testName string) bool {
@@ -234,7 +234,6 @@ func ParseConfigFlags(flagStr string) ParsedConfig {
234234
// See: https://github.com/GoogleCloudPlatform/gcs-fuse-csi-driver/blob/main/pkg/sidecar_mounter/sidecar_mounter_config.go#L83
235235

236236
// Group 1: Flags that are parsed manually and should not be passed to mountOptions.
237-
238237
// file-cache:max-size-mb is used by the CSI driver to enable the file cache feature and configure the cache volume.
239238
// If not provided or set to 0, the cache directory will not be created.
240239
// See: https://github.com/GoogleCloudPlatform/gcs-fuse-csi-driver/blob/main/pkg/sidecar_mounter/sidecar_mounter_config.go#L237-L241
@@ -262,14 +261,11 @@ func ParseConfigFlags(flagStr string) ParsedConfig {
262261
continue
263262
}
264263

265-
// Group 2: The following flags are translated to config file representation and passed to mountOptions.
266-
267-
// "log-file" is disallowed. The gcsfuse e2e tests hardcoded the log file in their test config.s
268-
// We parse this to configure the test pod to align with the gcsfuse test config.
269-
if strings.HasPrefix(f, flagLogFile) {
270-
parsed.LogFilePath = strings.TrimPrefix(f, flagLogFile)
271-
f = "logging:file-path:" + parsed.LogFilePath
272-
} else if f == flagFileCacheEnableParallelDownloads || strings.HasPrefix(f, flagFileCacheEnableParallelDownloads+"=") {
264+
// TODO: Remove this block after boolean flags formatting bug is fixed.
265+
// Group 2: The following flags are booleans but not in boolFlags map in sidecar_mounter_config.go.
266+
// They will be parsed as "x y" which is not a valid format in gcsfuse
267+
// They need to be translated into config file representation x:y
268+
if f == flagFileCacheEnableParallelDownloads || strings.HasPrefix(f, flagFileCacheEnableParallelDownloads+"=") {
273269
val := "true"
274270
if strings.Contains(f, "=") {
275271
val = strings.SplitN(f, "=", 2)[1]
@@ -287,9 +283,14 @@ func ParseConfigFlags(flagStr string) ParsedConfig {
287283
val = strings.SplitN(f, "=", 2)[1]
288284
}
289285
f = "file-system:enable-kernel-reader:" + val
290-
} else if strings.HasPrefix(f, flagLogFormat) {
291-
// "log-format" is disallowed so we need to format it to config file format
286+
}
287+
288+
// log-format and log-file are in the disallowedFlags map, so we need to parse them and set them manually.
289+
if strings.HasPrefix(f, flagLogFormat) {
292290
f = "logging:format:" + strings.TrimPrefix(f, flagLogFormat)
291+
} else if strings.HasPrefix(f, flagLogFile) {
292+
parsed.LogFilePath = strings.TrimPrefix(f, flagLogFile)
293+
f = "logging:file-path:" + parsed.LogFilePath
293294
}
294295

295296
parsed.MountOptions = append(parsed.MountOptions, f)
@@ -342,6 +343,7 @@ func FetchGCSFuseVersion(ctx context.Context, cl clientset.Interface) (string, e
342343
return "", fmt.Errorf("expected data for key `sidecar-image` in the config map `gcsfusecsi-image-config`")
343344
}
344345

346+
// Deploy a temporary Pod to run the gcsfuse binary and fetch its version.
345347
pod := &corev1.Pod{
346348
ObjectMeta: metav1.ObjectMeta{
347349
GenerateName: "gcsfuse-version-fetcher-",
@@ -395,6 +397,8 @@ func FetchGCSFuseVersion(ctx context.Context, cl clientset.Interface) (string, e
395397
klog.Infof("Pod %s is running, waiting 60s before fetching GCSFuse version from logs", createdPod.Name)
396398
time.Sleep(60 * time.Second)
397399

400+
// Fetch logs from the specific container running the gcsfuse binary.
401+
// We retry reading logs because it might take time for the logs to propagate to the apiserver.
398402
var logs []byte
399403
req := cl.CoreV1().Pods(DefaultNamespace).GetLogs(createdPod.Name, &corev1.PodLogOptions{Container: webhook.GcsFuseSidecarName})
400404
err = wait.PollUntilContextTimeout(ctx, 30*time.Second, time.Minute*10, true, func(ctx context.Context) (bool, error) {
@@ -411,7 +415,7 @@ func FetchGCSFuseVersion(ctx context.Context, cl clientset.Interface) (string, e
411415

412416
output := string(logs)
413417

414-
// Parse: "gcsfuse version 3.7.1-gke.0 ..."
418+
// Parse the version string from the standard format: "gcsfuse version 3.7.1-gke.0 ..."
415419
l := strings.Split(strings.TrimSpace(output), " ")
416420
if len(l) <= 2 {
417421
return "", fmt.Errorf("unexpected version output format: %s", output)

test/e2e/utils/utils_test.go

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,15 +79,14 @@ func TestParseConfigFlags(t *testing.T) {
7979
}{
8080
{
8181
name: "should parse standard file cache flags correctly",
82-
flagStr: "--file-cache-max-size-mb=9,--file-cache-cache-file-for-range-read=true,--metadata-cache-ttl-secs=10,--o=ro",
82+
flagStr: "--file-cache-max-size-mb=9,--file-cache-cache-file-for-range-read=true,--metadata-cache-ttl-secs=10,--o=ro,--log-severity=trace",
8383
expectedParsed: ParsedConfig{
8484
FileCacheCapacity: "9Mi",
8585
ReadOnly: true,
86+
LogSeverity: "trace",
8687
MountOptions: []string{
87-
"file-cache:max-size-mb:9",
8888
"file-cache-cache-file-for-range-read=true",
8989
"metadata-cache-ttl-secs=10",
90-
"o=ro",
9190
},
9291
},
9392
},
@@ -97,6 +96,7 @@ func TestParseConfigFlags(t *testing.T) {
9796
expectedParsed: ParsedConfig{
9897
FileCacheCapacity: "50Mi",
9998
ReadOnly: false,
99+
LogSeverity: "info",
100100
MountOptions: []string{},
101101
},
102102
},
@@ -106,12 +106,30 @@ func TestParseConfigFlags(t *testing.T) {
106106
expectedParsed: ParsedConfig{
107107
FileCacheCapacity: "100Mi",
108108
ReadOnly: false,
109+
LogSeverity: "info",
109110
MountOptions: []string{
110-
"file-cache:max-size-mb:100",
111111
"metadata-cache-ttl-secs=0",
112112
},
113113
},
114114
},
115+
{
116+
name: "should translate configuration flags correctly",
117+
flagStr: "--log-file=/tmp/log,--file-cache-enable-parallel-downloads,--file-cache-enable-o-direct=false,--enable-kernel-reader=true,--log-format=text,--cache-dir=/tmp/cache",
118+
expectedParsed: ParsedConfig{
119+
FileCacheCapacity: "50Mi",
120+
ReadOnly: false,
121+
LogFilePath: "/tmp/log",
122+
LogSeverity: "info",
123+
CacheDir: "/tmp/cache",
124+
MountOptions: []string{
125+
"logging:file-path:/tmp/log",
126+
"file-cache:enable-parallel-downloads:true",
127+
"file-cache:enable-o-direct:false",
128+
"file-system:enable-kernel-reader:true",
129+
"logging:format:text",
130+
},
131+
},
132+
},
115133
}
116134

117135
for _, tc := range testCases {

0 commit comments

Comments
 (0)