Skip to content

Commit

Permalink
add file cache e2e tests
Browse files Browse the repository at this point in the history
  • Loading branch information
songjiaxun committed Feb 17, 2024
1 parent d8f8bcf commit 6252eea
Show file tree
Hide file tree
Showing 13 changed files with 280 additions and 61 deletions.
2 changes: 2 additions & 0 deletions pkg/sidecar_mounter/sidecar_mounter.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,8 @@ func (mc *MountConfig) prepareMountArgs() (map[string]string, map[string]string)
value = GCSFuseAppName + "-" + value
case flag == util.DisableFileCacheKey:
configFileFlagMap["cache-dir"] = ""
klog.Info("gcsfuse file cache is disabled.")

continue
}

Expand Down
1 change: 1 addition & 0 deletions test/e2e/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ var _ = ginkgo.Describe("E2E Test Suite", func() {
testsuites.InitGcsFuseCSIPerformanceTestSuite,
testsuites.InitGcsFuseCSISubPathTestSuite,
testsuites.InitGcsFuseCSIAutoTerminationTestSuite,
testsuites.InitGcsFuseCSIFileCacheTestSuite,
}

testDriver := InitGCSFuseCSITestDriver(c, m, *bucketLocation, *skipGcpSaTest)
Expand Down
18 changes: 13 additions & 5 deletions test/e2e/specs/specs.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ const (
ForceNewBucketPrefix = "gcsfuse-csi-force-new-bucket"
SubfolderInBucketPrefix = "gcsfuse-csi-subfolder-in-bucket"
MultipleBucketsPrefix = "gcsfuse-csi-multiple-buckets"
DisableFileCachePrefix = "gcsfuse-csi-disable-file-cache"
ImplicitDirsPath = "implicit-dir"
InvalidVolume = "<invalid-name>"

Expand Down Expand Up @@ -280,6 +281,14 @@ func (t *TestPod) setupVolume(volumeResource *storageframework.VolumeResource, n
t.pod.Spec.Volumes = append(t.pod.Spec.Volumes, volume)
}

func (t *TestPod) SetupCacheVolumeMount(mountPath string) {
volumeMount := v1.VolumeMount{
Name: webhook.SidecarContainerCacheVolumeName,
MountPath: mountPath,
}
t.pod.Spec.Containers[0].VolumeMounts = append(t.pod.Spec.Containers[0].VolumeMounts, volumeMount)
}

func (t *TestPod) SetName(name string) {
t.pod.Name = name
}
Expand Down Expand Up @@ -956,12 +965,11 @@ func CreateImplicitDirInBucket(dirPath, bucketName string) {
}
}

func CreateEmptyFileInBucket(fileName, bucketName string) {
f, err := os.Create(fileName)
func CreateTestFileInBucket(fileName, bucketName string) {
err := os.WriteFile(fileName, []byte(fileName), 0o644)
if err != nil {
framework.Failf("Failed to create an empty data file: %v", err)
framework.Failf("Failed to create a test file: %v", err)
}
f.Close()
defer func() {
err = os.Remove(fileName)
if err != nil {
Expand All @@ -971,6 +979,6 @@ func CreateEmptyFileInBucket(fileName, bucketName string) {

//nolint:gosec
if output, err := exec.Command("gsutil", "cp", fileName, fmt.Sprintf("gs://%v", bucketName)).CombinedOutput(); err != nil {
framework.Failf("Failed to create an empty file in GCS bucket: %v, output: %s", err, output)
framework.Failf("Failed to create a test file in GCS bucket: %v, output: %s", err, output)
}
}
17 changes: 13 additions & 4 deletions test/e2e/testdriver.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ type gcsVolume struct {
bucketName string
serviceAccountNamespace string
mountOptions string
disableFileCache string
shared bool
readOnly bool
}
Expand Down Expand Up @@ -181,6 +182,7 @@ func (n *GCSFuseCSITestDriver) CreateVolume(ctx context.Context, config *storage
}

mountOptions := "debug_gcs,debug_fuse,debug_fs"
disableFileCache := ""
switch config.Prefix {
case specs.NonRootVolumePrefix:
mountOptions += ",uid=1001"
Expand All @@ -193,19 +195,22 @@ func (n *GCSFuseCSITestDriver) CreateVolume(ctx context.Context, config *storage
dirPath := uuid.NewString()
specs.CreateImplicitDirInBucket(dirPath, bucketName)
mountOptions += ",only-dir=" + dirPath
case specs.DisableFileCachePrefix:
disableFileCache = "true"
}

v := &gcsVolume{
bucketName: bucketName,
serviceAccountNamespace: config.Framework.Namespace.Name,
mountOptions: mountOptions,
disableFileCache: disableFileCache,
}

if !isMultipleBucketsPrefix {
n.volumeStore = append(n.volumeStore, v)
}

if config.Prefix == "" {
if config.Prefix == "" || config.Prefix == specs.DisableFileCachePrefix {
// Use config.Prefix to pass the bucket names back to the test suite.
config.Prefix = bucketName
}
Expand All @@ -226,7 +231,10 @@ func (v *gcsVolume) DeleteVolume(_ context.Context) {

func (n *GCSFuseCSITestDriver) GetPersistentVolumeSource(readOnly bool, _ string, volume storageframework.TestVolume) (*v1.PersistentVolumeSource, *v1.VolumeNodeAffinity) {
gv, _ := volume.(*gcsVolume)
va := map[string]string{"mountOptions": gv.mountOptions}
va := map[string]string{
driver.VolumeContextKeyMountOptions: gv.mountOptions,
driver.VolumeContextKeyDisableFileCache: gv.disableFileCache,
}

return &v1.PersistentVolumeSource{
CSI: &v1.CSIPersistentVolumeSource{
Expand All @@ -243,8 +251,9 @@ func (n *GCSFuseCSITestDriver) GetVolume(config *storageframework.PerTestConfig,
gv, _ := volume.(*gcsVolume)

return map[string]string{
"bucketName": gv.bucketName,
"mountOptions": gv.mountOptions,
driver.VolumeContextKeyBucketName: gv.bucketName,
driver.VolumeContextKeyMountOptions: gv.mountOptions,
driver.VolumeContextKeyDisableFileCache: gv.disableFileCache,
}, gv.shared, gv.readOnly
}

Expand Down
16 changes: 8 additions & 8 deletions test/e2e/testsuites/auto_termination.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ func (t *gcsFuseCSIAutoTerminationTestSuite) DefineTests(driver storageframework
tPod1 := specs.NewTestPod(f.ClientSet, f.Namespace)
tPod1.SetRestartPolicy(v1.RestartPolicyAlways)
tPod1.SetGracePeriod(600)
tPod1.SetupVolume(l.volumeResource, "test-gcsfuse-volume", mountPath, false)
tPod1.SetupVolume(l.volumeResource, volumeName, mountPath, false)
cmd := []string{
fmt.Sprintf("handle_term() { echo 'Caught SIGTERM signal!'; echo 'hello world' > %v/data && grep 'hello world' %v/data; sleep 5; exit 0; };", mountPath, mountPath),
"trap handle_term SIGTERM;",
Expand All @@ -118,7 +118,7 @@ func (t *gcsFuseCSIAutoTerminationTestSuite) DefineTests(driver storageframework

ginkgo.By("Configuring the second pod")
tPod2 := specs.NewTestPod(f.ClientSet, f.Namespace)
tPod2.SetupVolume(l.volumeResource, "test-gcsfuse-volume", mountPath, false)
tPod2.SetupVolume(l.volumeResource, volumeName, mountPath, false)

ginkgo.By("Deploying the second pod")
tPod2.Create(ctx)
Expand All @@ -139,7 +139,7 @@ func (t *gcsFuseCSIAutoTerminationTestSuite) DefineTests(driver storageframework
ginkgo.By("Configuring the pod")
tPod := specs.NewTestPod(f.ClientSet, f.Namespace)
tPod.SetRestartPolicy(v1.RestartPolicyNever)
tPod.SetupVolume(l.volumeResource, "test-gcsfuse-volume", mountPath, false)
tPod.SetupVolume(l.volumeResource, volumeName, mountPath, false)
tPod.SetCommand(fmt.Sprintf("echo 'hello world' > %v/data && grep 'hello world' %v/data", mountPath, mountPath))

ginkgo.By("Deploying the pod")
Expand All @@ -157,7 +157,7 @@ func (t *gcsFuseCSIAutoTerminationTestSuite) DefineTests(driver storageframework
ginkgo.By("Configuring the pod")
tPod := specs.NewTestPod(f.ClientSet, f.Namespace)
tPod.SetRestartPolicy(v1.RestartPolicyNever)
tPod.SetupVolume(l.volumeResource, "test-gcsfuse-volume", mountPath, false)
tPod.SetupVolume(l.volumeResource, volumeName, mountPath, false)
tPod.SetCommand("sleep 10; exit 1;")

ginkgo.By("Deploying the pod")
Expand All @@ -175,7 +175,7 @@ func (t *gcsFuseCSIAutoTerminationTestSuite) DefineTests(driver storageframework
ginkgo.By("Configuring the first pod")
tPod := specs.NewTestPod(f.ClientSet, f.Namespace)
tPod.SetRestartPolicy(v1.RestartPolicyAlways)
tPod.SetupVolume(l.volumeResource, "test-gcsfuse-volume", mountPath, false)
tPod.SetupVolume(l.volumeResource, volumeName, mountPath, false)
tPod.SetCommand(fmt.Sprintf("echo 'hello world' > %v/data && grep 'hello world' %v/data", mountPath, mountPath))

ginkgo.By("Deploying the first pod")
Expand All @@ -197,7 +197,7 @@ func (t *gcsFuseCSIAutoTerminationTestSuite) DefineTests(driver storageframework
ginkgo.By("Configuring the pod")
tPod := specs.NewTestPod(f.ClientSet, f.Namespace)
tPod.SetRestartPolicy(v1.RestartPolicyAlways)
tPod.SetupVolume(l.volumeResource, "test-gcsfuse-volume", mountPath, false)
tPod.SetupVolume(l.volumeResource, volumeName, mountPath, false)
tPod.SetCommand("sleep 10; exit 1;")

ginkgo.By("Deploying the pod")
Expand All @@ -219,7 +219,7 @@ func (t *gcsFuseCSIAutoTerminationTestSuite) DefineTests(driver storageframework
ginkgo.By("Configuring the pod")
tPod := specs.NewTestPod(f.ClientSet, f.Namespace)
tPod.SetRestartPolicy(v1.RestartPolicyOnFailure)
tPod.SetupVolume(l.volumeResource, "test-gcsfuse-volume", mountPath, false)
tPod.SetupVolume(l.volumeResource, volumeName, mountPath, false)
cmd := []string{
"sleep 10;",
fmt.Sprintf("if [ -f %v/testfile ]; then echo 'Completed Successfully!'; exit 0; fi;", mountPath),
Expand All @@ -244,7 +244,7 @@ func (t *gcsFuseCSIAutoTerminationTestSuite) DefineTests(driver storageframework
ginkgo.By("Configuring the pod")
tPod := specs.NewTestPod(f.ClientSet, f.Namespace)
tPod.SetRestartPolicy(v1.RestartPolicyAlways)
tPod.SetupVolume(l.volumeResource, "test-gcsfuse-volume", mountPath, false)
tPod.SetupVolume(l.volumeResource, volumeName, mountPath, false)
tPod.SetCommand("sleep 10; exit 1;")

ginkgo.By("Deploying the pod")
Expand Down
14 changes: 7 additions & 7 deletions test/e2e/testsuites/failed_mount.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ func (t *gcsFuseCSIFailedMountTestSuite) DefineTests(driver storageframework.Tes

ginkgo.By("Configuring the pod")
tPod := specs.NewTestPod(f.ClientSet, f.Namespace)
tPod.SetupVolume(l.volumeResource, "test-gcsfuse-volume", mountPath, false)
tPod.SetupVolume(l.volumeResource, volumeName, mountPath, false)

ginkgo.By("Deploying the pod")
tPod.Create(ctx)
Expand All @@ -116,7 +116,7 @@ func (t *gcsFuseCSIFailedMountTestSuite) DefineTests(driver storageframework.Tes

ginkgo.By("Configuring the pod")
tPod := specs.NewTestPod(f.ClientSet, f.Namespace)
tPod.SetupVolume(l.volumeResource, "test-gcsfuse-volume", mountPath, false)
tPod.SetupVolume(l.volumeResource, volumeName, mountPath, false)

ginkgo.By("Deploying the pod")
tPod.Create(ctx)
Expand All @@ -133,7 +133,7 @@ func (t *gcsFuseCSIFailedMountTestSuite) DefineTests(driver storageframework.Tes

ginkgo.By("Configuring the pod")
tPod := specs.NewTestPod(f.ClientSet, f.Namespace)
tPod.SetupVolume(l.volumeResource, "test-gcsfuse-volume", mountPath, false)
tPod.SetupVolume(l.volumeResource, volumeName, mountPath, false)

ginkgo.By("Deploying a Kubernetes service account without access to the GCS bucket")
saName := "sa-without-access"
Expand Down Expand Up @@ -163,7 +163,7 @@ func (t *gcsFuseCSIFailedMountTestSuite) DefineTests(driver storageframework.Tes

ginkgo.By("Configuring the pod")
tPod := specs.NewTestPod(f.ClientSet, f.Namespace)
tPod.SetupVolume(l.volumeResource, "test-gcsfuse-volume", mountPath, false)
tPod.SetupVolume(l.volumeResource, volumeName, mountPath, false)

tPod.SetAnnotations(map[string]string{
"gke-gcsfuse/volumes": "false",
Expand All @@ -184,7 +184,7 @@ func (t *gcsFuseCSIFailedMountTestSuite) DefineTests(driver storageframework.Tes

ginkgo.By("Configuring the pod")
tPod := specs.NewTestPod(f.ClientSet, f.Namespace)
tPod.SetupVolume(l.volumeResource, "test-gcsfuse-volume", mountPath, false)
tPod.SetupVolume(l.volumeResource, volumeName, mountPath, false)
tPod.SetCommand("touch /mnt/test/test_file && while true; do echo $(date) >> /mnt/test/test_file; done")

tPod.SetAnnotations(map[string]string{
Expand All @@ -206,7 +206,7 @@ func (t *gcsFuseCSIFailedMountTestSuite) DefineTests(driver storageframework.Tes

ginkgo.By("Configuring the pod")
tPod := specs.NewTestPod(f.ClientSet, f.Namespace)
tPod.SetupVolume(l.volumeResource, "test-gcsfuse-volume", mountPath, false)
tPod.SetupVolume(l.volumeResource, volumeName, mountPath, false)

ginkgo.By("Deploying the pod")
tPod.Create(ctx)
Expand All @@ -223,7 +223,7 @@ func (t *gcsFuseCSIFailedMountTestSuite) DefineTests(driver storageframework.Tes

ginkgo.By("Configuring the pod")
tPod := specs.NewTestPod(f.ClientSet, f.Namespace)
tPod.SetupVolume(l.volumeResource, "test-gcsfuse-volume", mountPath, false)
tPod.SetupVolume(l.volumeResource, volumeName, mountPath, false)

tPod.SetAnnotations(map[string]string{
"gke-gcsfuse/memory-limit": "1000000000Gi",
Expand Down
Loading

0 comments on commit 6252eea

Please sign in to comment.