-
Notifications
You must be signed in to change notification settings - Fork 151
Improve ListSnapshot filtering tests #259
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
Improve ListSnapshot filtering tests #259
Conversation
Hi @timoreimann. Thanks for your PR. I'm waiting for a kubernetes-csi member to verify that this patch is reasonable to test. If it is, they should reply with Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
Our implementation of ListSnapshots currently returns all snapshots. The request parameter also provides fields to filter by snapshot ID and source volume ID, which we have been ignoring so far. Based on discussions with SIG Storage [1], it became clear that CSI drivers are expected to process present IDs in the ListSnapshots call appropriately. While the spec marks them as OPTIONAL, it turned out that the optionality refers to the CO, not the SP. (A request for clarification has been filed in [2].) As soon as any of IDs are provided, drivers are expected to take them into account. In fact, csi-snapshotter always passes a snapshot ID in and only ever takes the first snapshot item from the list of snapshots returned, which means that our current implementation is buggy for cases where the account holds more than one snapshot (at least on Kubernetes; other COs could potentially behave differently). This change fixes the issue by retrieving the snapshot by direct lookup if a snapshot ID is given. If a source volume ID is given, we do additional filtering by only returning the snapshots that were sourced by the same volume. The existing csi-sanity tests did not catch this bug. A PR to that project was submitted [3] to close the gap. Once it is merged, we should upgrade our version of the test package. [1]: https://kubernetes.slack.com/archives/C8EJ01Z46/p1587038433091900 [2]: container-storage-interface/spec#426 [3]: kubernetes-csi/csi-test#259
Our implementation of ListSnapshots currently returns all snapshots. The request parameter also provides fields to filter by snapshot ID and source volume ID, which we have been ignoring so far. Based on discussions with SIG Storage [1], it became clear that CSI drivers are expected to process present IDs in the ListSnapshots call appropriately. While the spec marks them as OPTIONAL, it turned out that the optionality refers to the CO, not the SP. (A request for clarification has been filed in [2].) As soon as any of IDs are provided, drivers are expected to take them into account. In fact, csi-snapshotter always passes a snapshot ID in and only ever takes the first snapshot item from the list of snapshots returned, which means that our current implementation is buggy for cases where the account holds more than one snapshot (at least on Kubernetes; other COs could potentially behave differently). This change fixes the issue by retrieving the snapshot by direct lookup if a snapshot ID is given. If a source volume ID is given, we do additional filtering by only returning the snapshots that were sourced by the same volume. The existing csi-sanity tests did not catch this bug. A PR to that project was submitted [3] to close the gap. Once it is merged, we should upgrade our version of the test package. [1]: https://kubernetes.slack.com/archives/C8EJ01Z46/p1587038433091900 [2]: container-storage-interface/spec#426 [3]: kubernetes-csi/csi-test#259
volReq := MakeCreateVolumeReq(sc, "listSnapshots-volume-1") | ||
volume, err := c.CreateVolume(context.Background(), volReq) | ||
By("creating volumes") | ||
volReq := MakeCreateVolumeReq(sc, "listSnapshots-volume-unrelated1") |
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.
What does "unrelated" mean? Please add a comment.
pkg/sanity/controller.go
Outdated
By("creating a snapshot") | ||
snapshotReq := MakeCreateSnapshotReq(sc, "listSnapshots-snapshot-1", volume.GetVolume().GetVolumeId()) | ||
snapshot, err := c.CreateSnapshot(context.Background(), snapshotReq) | ||
volReq = MakeCreateVolumeReq(sc, "listSnapshots-volume-target") |
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.
Add a comment
pkg/sanity/controller.go
Outdated
volumeTarget, err := c.CreateVolume(context.Background(), volReq) | ||
Expect(err).NotTo(HaveOccurred()) | ||
|
||
volReq = MakeCreateVolumeReq(sc, "listSnapshots-volume-unrelated2") |
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.
Add comment
Expect(err).NotTo(HaveOccurred()) | ||
|
||
By("creating snapshots") | ||
snapshotReq := MakeCreateSnapshotReq(sc, "listSnapshots-snapshot-unrelated1", volumeUnrelated1.GetVolume().GetVolumeId()) |
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.
Comments
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.
Can you move this up to right after create volume.
Expect(err).NotTo(HaveOccurred()) | ||
|
||
snapshotReq = MakeCreateSnapshotReq(sc, "listSnapshots-snapshot-unrelated2", volumeUnrelated2.GetVolume().GetVolumeId()) |
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.
Comments
/ok-to-test |
@xing-yang I addressed the comments. However, the "should return snapshots that match the specified source volume id" test still fails, apparently because the (mock) driver used in the tests does not support multiple snapshots sourced by the same volume ID. I'm trying to understand if the driver needs to be extended or the test reduced. |
Then the mock driver should be modified to handle that test. |
I simplified the test for now just to see if it passes before I modify the mock driver. Looking into that next. |
@@ -1340,35 +1340,71 @@ var _ = DescribeSanity("ListSnapshots [Controller Server]", func(sc *TestContext | |||
}) | |||
|
|||
It("should return snapshots that match the specified snapshot id", func() { | |||
// The test creates three snapshots: one that we intend to find by | |||
// snapshot ID, and two unrelated ones that must not be returned by |
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.
When you say "unrelated", do you mean they won't be returned when filtering by snapshot id or filtering by source volume id? Please clarify in the comments.
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.
As this is the test for snapshot IDs, the "unrelatedness" is with regards to filtering by snapshot IDs. I'll amend the comments.
@xing-yang I addressed your last comment and brought back the version of the source volume ID test that expects multiple snapshots to be returned. The mock was updated accordingly. I also did a few drive-by improvements in the mock for things I needed to touch anymore. (See the commit description for details.) Please take another look. |
Uh, I don't understand this: |
I don't think this is flakiness, but anyway: /retest |
a2f85df
to
14a3965
Compare
We provide tests on ListSnapshots for filtering by snapshot IDs and source volume IDs. However, the tests do not cover the case were snapshot listing functionality exists in general but is missing filtering capabilities: for this scenario the tests yield false positives because the fixtures set up a single snapshot only. We improve the tests by creating a number of snapshots of which a subset is expected to be found.
14a3965
to
abd502a
Compare
I think I understand now why the tests kept failing: I missed to see that the CI runs the tests both against the mocked as all as the hostpath driver, and the latter wasn't updated yet. I briefly looked at what would need to be changed about the hostpath driver to return multiple snapshots. While the necessary changes are pretty clear, at this point I'd definitely favor getting the PR approved and merged in the simplified version that doesn't require changing any CSI drivers. (I updated the PR to reflect this accordingly.) I'd happy to create an issue to track the extension and work on it afterwards. @xing-yang what do you think, does that sound like a reasonable approach to you? |
@timoreimann sounds good to me. |
The tests look good to me. |
@xing-yang 👍 done |
/lgtm |
This one still needs an /approve I suppose? |
/assign @pohly |
By("creating first unrelated snapshot") | ||
// Create volume source and afterwards the first unrelated snapshot. | ||
volReq := MakeCreateVolumeReq(sc, "listSnapshots-volume-unrelated1") | ||
volumeUnrelated1, err := c.CreateVolume(context.Background(), volReq) |
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.
As pointed out elsewhere (issue #260), all created resources like volumes must be registered with the cl
instance, otherwise they can leak in case of an assertion failure.
Not sure whether you want to address that already in this PR or do it separately - up to you.
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.
If you don't mind, I'd prefer to merge this one as-is and do the proper registration for resource cleanup in a follow-up PR. As noted in #260, I'd be happy to work on that.
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.
/approve
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: pohly, timoreimann The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
90efb2c Merge pull request kubernetes-csi#272 from andyzhangx/patch-3 9b616fe Bump golang to 1.23.6 to fix CVE-2024-45336, CVE-2025-22866 0496593 Merge pull request kubernetes-csi#268 from huww98/cloudbuild 119aee1 Merge pull request kubernetes-csi#266 from jsafrane/bump-sanity-5.3.1 0ae5e52 Update cloudbuild image with go 1.21+ 406a79a Merge pull request kubernetes-csi#267 from huww98/gomodcache 9cec273 Set GOMODCACHE to avoid re-download toolchain 98f2307 Merge pull request kubernetes-csi#260 from TerryHowe/update-csi-driver-version e9d8712 Merge pull request kubernetes-csi#259 from stmcginnis/deprecated-kind-kube-root faf79ff Remove --kube-root deprecated kind argument 43bde06 Bump csi-sanity to 5.3.1 18b6ac6 chore: update CSI driver version to 1.15 git-subtree-dir: release-tools git-subtree-split: 90efb2ca59900f19eba05e65da28beda79c5bb28
What type of PR is this?
What this PR does / why we need it:
We provide tests on
ListSnapshots
for filtering by snapshot IDs and source volume IDs. However, the tests do not cover the case were snapshot listing functionality exists in general but is missingfiltering capabilities: for this scenario the existing tests yield false positives because the fixtures set up a single snapshot only.
We improve the tests by creating a number of snapshots of which a subset is expected to be found.
Does this PR introduce a user-facing change?: