forked from kubernetes-sigs/aws-ebs-csi-driver
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request kubernetes-sigs#1769 from AndrewSirenko/formatting…
…OptionE2eTestsSimpler Add e2e tests for format options
- Loading branch information
Showing
7 changed files
with
244 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
/* | ||
Copyright 2018 The Kubernetes Authors. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package e2e | ||
|
||
import ( | ||
"fmt" | ||
ebscsidriver "github.com/kubernetes-sigs/aws-ebs-csi-driver/pkg/driver" | ||
"github.com/kubernetes-sigs/aws-ebs-csi-driver/tests/e2e/driver" | ||
"github.com/kubernetes-sigs/aws-ebs-csi-driver/tests/e2e/testsuites" | ||
. "github.com/onsi/ginkgo/v2" | ||
v1 "k8s.io/api/core/v1" | ||
clientset "k8s.io/client-go/kubernetes" | ||
"k8s.io/kubernetes/test/e2e/framework" | ||
admissionapi "k8s.io/pod-security-admission/api" | ||
) | ||
|
||
var ( | ||
testedFsTypes = []string{ebscsidriver.FSTypeExt4} | ||
|
||
formatOptionTests = []testsuites.FormatOptionTest{ | ||
{ | ||
CreateVolumeParameterKey: ebscsidriver.BlockSizeKey, | ||
CreateVolumeParameterValue: "1024", | ||
}, | ||
{ | ||
CreateVolumeParameterKey: ebscsidriver.INodeSizeKey, | ||
CreateVolumeParameterValue: "512", | ||
}, | ||
{ | ||
CreateVolumeParameterKey: ebscsidriver.BytesPerINodeKey, | ||
CreateVolumeParameterValue: "8192", | ||
}, | ||
{ | ||
CreateVolumeParameterKey: ebscsidriver.NumberOfINodesKey, | ||
CreateVolumeParameterValue: "200192", | ||
}, | ||
} | ||
) | ||
|
||
var _ = Describe("[ebs-csi-e2e] [single-az] [format-options] Formatting a volume", func() { | ||
f := framework.NewDefaultFramework("ebs") | ||
f.NamespacePodSecurityEnforceLevel = admissionapi.LevelPrivileged | ||
|
||
var ( | ||
cs clientset.Interface | ||
ns *v1.Namespace | ||
ebsDriver driver.PVTestDriver | ||
) | ||
|
||
BeforeEach(func() { | ||
cs = f.ClientSet | ||
ns = f.Namespace | ||
ebsDriver = driver.InitEbsCSIDriver() | ||
}) | ||
|
||
for _, fsType := range testedFsTypes { | ||
Context(fmt.Sprintf("using an %s filesystem", fsType), func() { | ||
for _, formatOptionTestCase := range formatOptionTests { | ||
formatOptionTestCase := formatOptionTestCase | ||
if fsTypeDoesNotSupportFormatOptionParameter(fsType, formatOptionTestCase.CreateVolumeParameterKey) { | ||
continue | ||
} | ||
|
||
Context(fmt.Sprintf("with a custom %s parameter", formatOptionTestCase.CreateVolumeParameterKey), func() { | ||
It("successfully mounts and is resizable", func() { | ||
formatOptionTestCase.Run(cs, ns, ebsDriver, fsType) | ||
}) | ||
}) | ||
} | ||
}) | ||
} | ||
}) | ||
|
||
func fsTypeDoesNotSupportFormatOptionParameter(fsType string, createVolumeParameterKey string) bool { | ||
_, paramNotSupported := ebscsidriver.FileSystemConfigs[fsType].NotSupportedParams[createVolumeParameterKey] | ||
return paramNotSupported | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/* | ||
Copyright 2018 The Kubernetes Authors. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package testsuites | ||
|
||
import "fmt" | ||
|
||
const ( | ||
DefaultVolumeName = "test-volume-1" | ||
DefaultMountPath = "/mnt/default-mount" | ||
) | ||
|
||
func PodCmdWriteToVolume(volumeMountPath string) string { | ||
return fmt.Sprintf("echo 'hello world' >> %s/data && grep 'hello world' %s/data && sync", volumeMountPath, volumeMountPath) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
/* | ||
Copyright 2018 The Kubernetes Authors. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package testsuites | ||
|
||
import ( | ||
awscloud "github.com/kubernetes-sigs/aws-ebs-csi-driver/pkg/cloud" | ||
"github.com/kubernetes-sigs/aws-ebs-csi-driver/tests/e2e/driver" | ||
. "github.com/onsi/ginkgo/v2" | ||
v1 "k8s.io/api/core/v1" | ||
clientset "k8s.io/client-go/kubernetes" | ||
) | ||
|
||
// FormatOptionTest will provision required StorageClass(es), PVC(s) and Pod(s) in order to test that volumes with | ||
// a specified custom format options will mount and are able to be later resized. | ||
type FormatOptionTest struct { | ||
CreateVolumeParameterKey string | ||
CreateVolumeParameterValue string | ||
} | ||
|
||
const ( | ||
volumeSizeIncreaseAmtGi = 1 | ||
) | ||
|
||
func (t *FormatOptionTest) Run(client clientset.Interface, namespace *v1.Namespace, ebsDriver driver.PVTestDriver, fsType string) { | ||
By("setting up pvc with custom format option") | ||
volumeDetails := createFormatOptionVolumeDetails(fsType, t) | ||
testPvc, _ := volumeDetails.SetupDynamicPersistentVolumeClaim(client, namespace, ebsDriver) | ||
defer testPvc.Cleanup() | ||
|
||
By("deploying pod with custom format option") | ||
formatOptionMountPod := createPodWithVolume(client, namespace, PodCmdWriteToVolume(DefaultMountPath), testPvc, volumeDetails) | ||
defer formatOptionMountPod.Cleanup() | ||
formatOptionMountPod.WaitForSuccess() | ||
|
||
By("testing that pvc is able to be resized") | ||
ResizeTestPvc(client, namespace, testPvc, volumeSizeIncreaseAmtGi) | ||
|
||
By("validating resized pvc by deploying new pod") | ||
resizeTestPod := createPodWithVolume(client, namespace, PodCmdWriteToVolume(DefaultMountPath), testPvc, volumeDetails) | ||
defer resizeTestPod.Cleanup() | ||
|
||
By("confirming new pod can write to resized volume") | ||
resizeTestPod.WaitForSuccess() | ||
} | ||
|
||
func createFormatOptionVolumeDetails(fsType string, t *FormatOptionTest) *VolumeDetails { | ||
additionalParameters := map[string]string{ | ||
t.CreateVolumeParameterKey: t.CreateVolumeParameterValue, | ||
} | ||
|
||
allowVolumeExpansion := true | ||
|
||
volume := VolumeDetails{ | ||
VolumeType: awscloud.VolumeTypeGP2, | ||
FSType: fsType, | ||
MountOptions: []string{"rw"}, | ||
ClaimSize: driver.MinimumSizeForVolumeType(awscloud.VolumeTypeGP2), | ||
VolumeMount: VolumeMountDetails{ | ||
NameGenerate: DefaultVolumeName, | ||
MountPathGenerate: DefaultMountPath, | ||
}, | ||
AllowVolumeExpansion: &allowVolumeExpansion, | ||
AdditionalParameters: additionalParameters, | ||
} | ||
|
||
return &volume | ||
} | ||
|
||
func createPodWithVolume(client clientset.Interface, namespace *v1.Namespace, cmd string, testPvc *TestPersistentVolumeClaim, volumeDetails *VolumeDetails) *TestPod { | ||
testPod := NewTestPod(client, namespace, cmd) | ||
testPod.SetupVolume(testPvc.persistentVolumeClaim, volumeDetails.VolumeMount.NameGenerate, volumeDetails.VolumeMount.MountPathGenerate, volumeDetails.VolumeMount.ReadOnly) | ||
testPod.Create() | ||
|
||
return testPod | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters