-
Notifications
You must be signed in to change notification settings - Fork 807
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8f246ed
commit b52144b
Showing
6 changed files
with
224 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("with an %s filesystem", fsType), func() { | ||
for _, formatOptionTestCase := range formatOptionTests { | ||
formatOptionTestCase := formatOptionTestCase // Go trap | ||
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,93 @@ | ||
/* | ||
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" | ||
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 | ||
volumeMountPath = "/mnt/test-format-option" // TODO should I keep this as mnt/test-1, and refactor to be `DefaultMountPath` globally in testsuites? | ||
) | ||
|
||
var ( | ||
podCmdWriteToVolume = fmt.Sprintf("echo 'hello world' >> %s/data && grep 'hello world' %s/data && sync", volumeMountPath, volumeMountPath) // TODO Debt: All the dynamic provisioning tests use this same cmd. Should we refactor out into exported constant? | ||
) | ||
|
||
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, volumeMountPath, t) | ||
testPvc, _ := volumeDetails.SetupDynamicPersistentVolumeClaim(client, namespace, ebsDriver) | ||
defer testPvc.Cleanup() | ||
|
||
By("deploying pod with custom format option") | ||
getFsInfoTestPod := createPodWithVolume(client, namespace, podCmdWriteToVolume, testPvc, volumeDetails) | ||
defer getFsInfoTestPod.Cleanup() | ||
getFsInfoTestPod.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, testPvc, volumeDetails) | ||
defer resizeTestPod.Cleanup() | ||
|
||
By("confirming new pod can write to resized volume") | ||
resizeTestPod.WaitForSuccess() | ||
} | ||
|
||
// TODO should we improve this across e2e tests via builder design pattern? Or is that not go-like? | ||
func createFormatOptionVolumeDetails(fsType string, volumeMountPath string, t *FormatOptionTest) *VolumeDetails { | ||
allowVolumeExpansion := true | ||
|
||
volume := VolumeDetails{ | ||
VolumeType: awscloud.VolumeTypeGP2, | ||
FSType: fsType, | ||
MountOptions: []string{"rw"}, | ||
ClaimSize: driver.MinimumSizeForVolumeType(awscloud.VolumeTypeGP2), | ||
VolumeMount: VolumeMountDetails{ | ||
NameGenerate: "test-volume-format-option", | ||
MountPathGenerate: volumeMountPath, | ||
}, | ||
AllowVolumeExpansion: &allowVolumeExpansion, | ||
AdditionalParameters: map[string]string{ | ||
t.CreateVolumeParameterKey: t.CreateVolumeParameterValue, | ||
}, | ||
} | ||
|
||
return &volume | ||
} | ||
|
||
// TODO putting this in function may be overkill? In an ideal world we refactor out TestEverything objects so testPod.SetupVolume isn't gross. | ||
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