-
Notifications
You must be signed in to change notification settings - Fork 4.8k
STOR-3065: Add storage CSI tests for cloning PVC to a larger volume #31443
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
radeore
wants to merge
1
commit into
openshift:main
Choose a base branch
from
radeore:pvc-clone-tests
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+199
−1
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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,180 @@ | ||
| package csi | ||
|
|
||
| import ( | ||
| "context" | ||
| "fmt" | ||
|
|
||
| g "github.com/onsi/ginkgo/v2" | ||
| v1 "k8s.io/api/core/v1" | ||
| "k8s.io/apimachinery/pkg/api/resource" | ||
| metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
| clientset "k8s.io/client-go/kubernetes" | ||
| e2e "k8s.io/kubernetes/test/e2e/framework" | ||
| e2enode "k8s.io/kubernetes/test/e2e/framework/node" | ||
| e2epod "k8s.io/kubernetes/test/e2e/framework/pod" | ||
| e2epv "k8s.io/kubernetes/test/e2e/framework/pv" | ||
| e2eskipper "k8s.io/kubernetes/test/e2e/framework/skipper" | ||
| e2evolume "k8s.io/kubernetes/test/e2e/framework/volume" | ||
| storageframework "k8s.io/kubernetes/test/e2e/storage/framework" | ||
| "k8s.io/kubernetes/test/e2e/storage/testsuites" | ||
| storageutils "k8s.io/kubernetes/test/e2e/storage/utils" | ||
| admissionapi "k8s.io/pod-security-admission/api" | ||
| ) | ||
|
|
||
| func initPVCCloneLargerCSISuite() storageframework.TestSuite { | ||
| return &pvcCloneLargerCSISuite{ | ||
| tsInfo: storageframework.TestSuiteInfo{ | ||
| Name: "OpenShift CSI extended - CSI Clone", | ||
| TestPatterns: []storageframework.TestPattern{ | ||
| storageframework.DefaultFsDynamicPV, | ||
| storageframework.BlockVolModeDynamicPV, | ||
| }, | ||
| SupportedSizeRange: e2evolume.SizeRange{ | ||
| Min: "1Mi", | ||
| }, | ||
| }, | ||
| } | ||
| } | ||
|
|
||
| // pvcCloneLargerCSISuite covers cloning a PVC into a larger destination volume | ||
| // for both filesystem and raw block volume modes. | ||
| type pvcCloneLargerCSISuite struct { | ||
| tsInfo storageframework.TestSuiteInfo | ||
| } | ||
|
|
||
| var _ storageframework.TestSuite = &pvcCloneLargerCSISuite{} | ||
|
|
||
| func (s *pvcCloneLargerCSISuite) GetTestSuiteInfo() storageframework.TestSuiteInfo { | ||
| return s.tsInfo | ||
| } | ||
|
|
||
| func (s *pvcCloneLargerCSISuite) SkipUnsupportedTests(driver storageframework.TestDriver, pattern storageframework.TestPattern) { | ||
| dInfo := driver.GetDriverInfo() | ||
| if !dInfo.Capabilities[storageframework.CapPVCDataSource] { | ||
| e2eskipper.Skipf("Driver %q does not support cloning - skipping", dInfo.Name) | ||
| } | ||
| if pattern.VolMode == v1.PersistentVolumeBlock && !dInfo.Capabilities[storageframework.CapBlock] { | ||
| e2eskipper.Skipf("Driver %s doesn't support %v -- skipping", dInfo.Name, pattern.VolMode) | ||
| } | ||
| // Cloning to a larger filesystem volume requires the driver to expand the | ||
| // filesystem when presenting the volume (same requirement as snapshot restore). | ||
| if pattern.VolMode != v1.PersistentVolumeBlock && dInfo.Capabilities[storageframework.CapFSResizeFromSourceNotSupported] { | ||
| e2eskipper.Skipf("Driver %q does not support filesystem resizing from source - skipping", dInfo.Name) | ||
| } | ||
| } | ||
|
|
||
| func (s *pvcCloneLargerCSISuite) DefineTests(driver storageframework.TestDriver, pattern storageframework.TestPattern) { | ||
| f := e2e.NewFrameworkWithCustomTimeouts("csi-clone-larger", storageframework.GetDriverTimeouts(driver)) | ||
| f.NamespacePodSecurityLevel = admissionapi.LevelPrivileged | ||
|
|
||
| dInfo := driver.GetDriverInfo() | ||
|
|
||
| g.It("should provision volume with pvc data source larger than original volume", func(ctx context.Context) { | ||
| dDriver, ok := driver.(storageframework.DynamicPVTestDriver) | ||
| if !ok { | ||
| e2eskipper.Skipf("Driver %q does not support dynamic provisioning - skipping", dInfo.Name) | ||
| } | ||
|
|
||
| config := driver.PrepareTest(ctx, f) | ||
| cs := config.Framework.ClientSet | ||
|
|
||
| // Some drivers cannot clone across topology segments; pin source and clone to one. | ||
| pinToDriverTopology(ctx, &config.ClientNodeSelection, cs, dInfo) | ||
|
|
||
| testConfig := storageframework.ConvertTestConfig(config) | ||
| expectedContent := fmt.Sprintf("Hello from namespace %s", f.Namespace.Name) | ||
| contentTest := func(pvcName string) e2evolume.Test { | ||
| return e2evolume.Test{ | ||
| Volume: *storageutils.CreateVolumeSource(pvcName, false /* readOnly */), | ||
| Mode: pattern.VolMode, | ||
| File: "index.html", | ||
| ExpectedContent: expectedContent, | ||
| } | ||
| } | ||
|
|
||
| claimSize, err := storageutils.GetSizeRangesIntersection(s.GetTestSuiteInfo().SupportedSizeRange, dInfo.SupportedSizeRange) | ||
| e2e.ExpectNoError(err, "determine intersection of test and driver size ranges") | ||
|
|
||
| sc := dDriver.GetDynamicProvisionStorageClass(ctx, config, pattern.FsType) | ||
| if sc == nil { | ||
| e2eskipper.Skipf("Driver %q does not define Dynamic Provision StorageClass - skipping", dInfo.Name) | ||
| } | ||
|
|
||
| g.By("Creating StorageClass and source PVC with test data") | ||
| testsuites.SetupStorageClass(ctx, cs, sc) | ||
| sourcePVC, err := cs.CoreV1().PersistentVolumeClaims(f.Namespace.Name).Create(ctx, | ||
| e2epv.MakePersistentVolumeClaim(e2epv.PersistentVolumeClaimConfig{ | ||
| ClaimSize: claimSize, | ||
| StorageClassName: &sc.Name, | ||
| VolumeMode: &pattern.VolMode, | ||
| }, f.Namespace.Name), | ||
| metav1.CreateOptions{}) | ||
| e2e.ExpectNoError(err) | ||
| g.DeferCleanup(func(ctx context.Context) { | ||
| _ = cs.CoreV1().PersistentVolumeClaims(sourcePVC.Namespace).Delete(ctx, sourcePVC.Name, metav1.DeleteOptions{}) | ||
| }) | ||
| e2evolume.InjectContent(ctx, f, testConfig, nil, "", []e2evolume.Test{contentTest(sourcePVC.Name)}) | ||
|
|
||
| g.By("Recording source PVC capacity and requesting a larger clone") | ||
| sourcePVC, err = cs.CoreV1().PersistentVolumeClaims(sourcePVC.Namespace).Get(ctx, sourcePVC.Name, metav1.GetOptions{}) | ||
| e2e.ExpectNoError(err, "Failed to get source PVC: %v", err) | ||
| storageRequest := resource.NewQuantity(sourcePVC.Status.Capacity.Storage().Value(), resource.BinarySI) | ||
| storageRequest.Add(resource.MustParse("1Gi")) | ||
| largerSize := storageRequest.String() | ||
|
|
||
| clonePVC := sourcePVC.DeepCopy() | ||
| clonePVC.ObjectMeta = metav1.ObjectMeta{ | ||
| GenerateName: "pvc-", | ||
| Namespace: sourcePVC.Namespace, | ||
| } | ||
| clonePVC.Status = v1.PersistentVolumeClaimStatus{} | ||
| clonePVC.Spec.VolumeName = "" | ||
| clonePVC.Spec.Resources.Requests = v1.ResourceList{v1.ResourceStorage: *storageRequest} | ||
| clonePVC.Spec.DataSourceRef = &v1.TypedObjectReference{ | ||
| Kind: "PersistentVolumeClaim", | ||
| Name: sourcePVC.Name, | ||
| } | ||
|
|
||
| testCase := &testsuites.StorageClassTest{ | ||
| Client: cs, | ||
| Timeouts: f.Timeouts, | ||
| Claim: clonePVC, | ||
| Class: sc, | ||
| Provisioner: sc.Provisioner, | ||
| ClaimSize: largerSize, | ||
| ExpectedSize: largerSize, | ||
| VolumeMode: pattern.VolMode, | ||
| NodeSelection: testConfig.ClientNodeSelection, | ||
| PvCheck: func(ctx context.Context, claim *v1.PersistentVolumeClaim) { | ||
| g.By("checking whether the cloned volume has the pre-populated data") | ||
| e2evolume.TestVolumeClientSlow(ctx, f, testConfig, nil, "", []e2evolume.Test{contentTest(claim.Name)}) | ||
| }, | ||
| } | ||
|
|
||
| // Cloning fails if the source disk is still detaching; wait for VolumeAttachment removal. | ||
| volumeAttachment := e2evolume.GetVolumeAttachmentName(ctx, cs, testConfig, testCase.Provisioner, sourcePVC.Name, sourcePVC.Namespace) | ||
| e2e.ExpectNoError(e2evolume.WaitForVolumeAttachmentTerminated(ctx, volumeAttachment, cs, f.Timeouts.DataSourceProvision)) | ||
|
|
||
| g.By("Provisioning clone PVC larger than the source and verifying data") | ||
| testCase.TestDynamicProvisioning(ctx) | ||
| }) | ||
| } | ||
|
|
||
| // pinToDriverTopology constrains pods to one topology segment advertised by the driver. | ||
| // Matches the intent of upstream ensureTopologyRequirements for PVC cloning. | ||
| func pinToDriverTopology(ctx context.Context, nodeSelection *e2epod.NodeSelection, cs clientset.Interface, dInfo *storageframework.DriverInfo) { | ||
| if nodeSelection.Name != "" || len(dInfo.TopologyKeys) == 0 { | ||
| return | ||
| } | ||
| node, err := e2enode.GetRandomReadySchedulableNode(ctx, cs) | ||
| e2e.ExpectNoError(err) | ||
| topo := make(map[string]string, len(dInfo.TopologyKeys)) | ||
| for _, key := range dInfo.TopologyKeys { | ||
| if val, ok := node.Labels[key]; ok && val != "" { | ||
| topo[key] = val | ||
| } | ||
| } | ||
| if len(topo) > 0 { | ||
| e2epod.SetNodeAffinityTopologyRequirement(nodeSelection, topo) | ||
| } | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
Assert the source capacity is non-zero before deriving the clone size.
If
Status.Capacityis missing (unbound/late-status PVC),Storage()yields0andlargerSizesilently becomes exactly1Gi, so the test no longer verifies "larger than the source" — it may even request less than the source. A cheap guard keeps the intent explicit.🛡️ Proposed guard
📝 Committable suggestion
🤖 Prompt for AI Agents