Skip to content

Conversation

@Rakshith-R
Copy link
Contributor

Describe what this PR does

This commit modifies listSnapAndChildren() to make use of ListChildrenAttributes() instead of ListChildren() which allows us to filter out images in trash.
This commit also order the alive images so that temp clone images are followed by images backing volume snapshots so that temp clone images are flattened first.

Is the change backward compatible?
Yes

Are there concerns around backward compatibility?
No

Related issues

Fixes: #5173

Checklist:

  • Commit Message Formatting: Commit titles and messages follow
    guidelines in the developer
    guide
    .
  • Reviewed the developer guide on Submitting a Pull
    Request
  • Pending release
    notes

    updated with breaking and/or notable changes for the next major release.
  • Documentation has been updated, if necessary.
  • Unit tests have been added, if necessary.
  • Integration tests have been added, if necessary.

Show available bot commands

These commands are normally not required, but in case of issues, leave any of
the following bot commands in an otherwise empty comment in this PR:

  • /retest ci/centos/<job-name>: retest the <job-name> after unrelated
    failure (please report the failure too!)

@Rakshith-R
Copy link
Contributor Author

/test ci/centos/mini-e2e/k8s-1.31

@mergify mergify bot added the component/rbd Issues related to RBD label Mar 10, 2025
@Rakshith-R
Copy link
Contributor Author

/test ci/centos/mini-e2e-helm/k8s-1.31


// ListChildren() returns pools, images, err.
_, children, err := image.ListChildren()
// ListChildrenAttributes() returns child ImageSpec list, err.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can drop this comment, I think the function is rather clear

if child.Trash {
continue
}
if strings.HasSuffix(child.ImageName, "-temp") {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe consider adding a isTempImage(child) function?

}
}
// order the temp clone images first followed by the volume snapshots
// so that the temp clones are flattened first.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the 2nd comment about temp clones are flattened first. I don't get why that is the case. If that is a requirement of the returned list, mention something about the order. Or wherever the list is consumed, use some other way of inspecting the list. Might be cleaner to return two lists, so that the distinction is very clear.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the 2nd comment about temp clones are flattened first. I don't get why that is the case. If that is a requirement of the returned list, mention something about the order. Or wherever the list is consumed, use some other way of inspecting the list. Might be cleaner to return two lists, so that the distinction is very clear.

I've removed it from the function definition, since we still are returning full list of child images which are not in trash.

I've expanded the comment in this section with reasons why such ordering is done so it can be understood in the future.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, that makes things a little bit clearer. I don't understand (yet) if, and why callers need to care about the order in the list that is returned. If callers need to care, or benefit from it, why not return separate lists? Or, a struct like { snaps, tempChildren, volSnapChildren } so that callers of the function are very aware of the differences, and can decide how to handle them?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, that makes things a little bit clearer. I don't understand (yet) if, and why callers need to care about the order in the list that is returned. If callers need to care, or benefit from it, why not return separate lists? Or, a struct like { snaps, tempChildren, volSnapChildren } so that callers of the function are very aware of the differences, and can decide how to handle them?

I've moved the logic to order images into the caller and added a struct for returned parameters.
PTAL

@Rakshith-R Rakshith-R force-pushed the list-child-images-with-attributes branch from 72596fb to a3dd6d2 Compare March 11, 2025 09:17
@Rakshith-R Rakshith-R requested review from a team and nixpanic March 11, 2025 09:17
@Rakshith-R Rakshith-R force-pushed the list-child-images-with-attributes branch 2 times, most recently from ee0e32a to db3dd12 Compare March 11, 2025 10:18
Copy link
Member

@nixpanic nixpanic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, makes it much cleaner. Just a nit that needs addressing.


// listSnapAndChildren returns list of names of snapshots and child images.
func (ri *rbdImage) listSnapAndChildren() ([]librbd.SnapInfo, []string, error) {
type SnapAndChildrenInfo struct {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to export this, use snapAndChildrenInfo instead.

// changed block tracking(rbd snap diff).
// - favor scalability since multiple PVCs can be restored from same
// volumesnapshot versus just one PVC-PVC clone.
children := append(snapAndChildrenInfo.TempCloneChildren, snapAndChildrenInfo.VolumeSnapshotChildren...)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

golangci-lint complains about this. append() may modify the 1st parameter (snapAndChildrenInfo), which could cause confusion later on in case it is used again (docs).

Instead, you could do it like this:

children := make([]string, len(snapAndChildrenInfo.TempCloneChildren) + len(snapAndChildrenInfo.VolumeSnapshotChildren))
children = append(children, snapAndChildrenInfo.TempCloneChildren...)
children = append(children, snapAndChildrenInfo.VolumeSnapshotChildren...)

@Rakshith-R Rakshith-R force-pushed the list-child-images-with-attributes branch 2 times, most recently from 83e17f9 to a4ab561 Compare March 11, 2025 12:40
nixpanic
nixpanic previously approved these changes Mar 11, 2025
This commit modifies listSnapAndChildren() to make use of
ListChildrenAttributes() instead of ListChildren() which
allows us to filter out images in trash.
This commit also order the alive images so that temp clone
images are followed by images backing volume snapshots so
that temp clone images are flattened first.

Signed-off-by: Rakshith R <[email protected]>
@Rakshith-R Rakshith-R force-pushed the list-child-images-with-attributes branch from a4ab561 to 0a35f96 Compare March 11, 2025 12:50
@mergify mergify bot dismissed nixpanic’s stale review March 11, 2025 12:51

Pull request has been modified.

@Rakshith-R
Copy link
Contributor Author

Rakshith-R commented Mar 11, 2025

golangci-lint complains about this. append() may modify the 1st parameter (snapAndChildrenInfo), which could cause confusion later on in case it is used again (docs).

Instead, you could do it like this:

children := make([]string, len(snapAndChildrenInfo.TempCloneChildren) + len(snapAndChildrenInfo.VolumeSnapshotChildren))
children = append(children, snapAndChildrenInfo.TempCloneChildren...)
children = append(children, snapAndChildrenInfo.VolumeSnapshotChildren...)

It needs to be initialized with zero length :(
ci passes now
ptal

@Rakshith-R Rakshith-R requested a review from nixpanic March 11, 2025 12:55
@nixpanic nixpanic requested a review from a team March 11, 2025 15:02
@Rakshith-R
Copy link
Contributor Author

@Mergifyio queue

@mergify
Copy link
Contributor

mergify bot commented Mar 12, 2025

queue

🛑 The pull request has been removed from the queue default

The merge conditions cannot be satisfied due to failing checks.

You can take a look at Queue: Embarked in merge queue check runs for more details.

In case of a failure due to a flaky test, you should first retrigger the CI.
Then, re-embark the pull request into the merge queue by posting the comment
@mergifyio refresh on the pull request.

@mergify mergify bot added the ok-to-test Label to trigger E2E tests label Mar 12, 2025
@ceph-csi-bot
Copy link
Collaborator

/test ci/centos/k8s-e2e-external-storage/1.31

@ceph-csi-bot
Copy link
Collaborator

/test ci/centos/mini-e2e-helm/k8s-1.31

@ceph-csi-bot
Copy link
Collaborator

/test ci/centos/mini-e2e/k8s-1.31

@ceph-csi-bot
Copy link
Collaborator

/test ci/centos/upgrade-tests-cephfs

@ceph-csi-bot
Copy link
Collaborator

/test ci/centos/k8s-e2e-external-storage/1.30

@ceph-csi-bot
Copy link
Collaborator

/test ci/centos/upgrade-tests-rbd

@ceph-csi-bot
Copy link
Collaborator

/test ci/centos/mini-e2e-helm/k8s-1.30

@ceph-csi-bot
Copy link
Collaborator

/test ci/centos/mini-e2e/k8s-1.30

@ceph-csi-bot
Copy link
Collaborator

/test ci/centos/k8s-e2e-external-storage/1.32

@ceph-csi-bot
Copy link
Collaborator

/test ci/centos/mini-e2e-helm/k8s-1.32

@ceph-csi-bot
Copy link
Collaborator

/test ci/centos/mini-e2e/k8s-1.32

@ceph-csi-bot ceph-csi-bot removed the ok-to-test Label to trigger E2E tests label Mar 12, 2025
@mergify
Copy link
Contributor

mergify bot commented Mar 12, 2025

This pull request has been removed from the queue for the following reason: checks failed.

The merge conditions cannot be satisfied due to failing checks:

You may have to fix your CI before adding the pull request to the queue again.

If you want to requeue this pull request, you can post a @mergifyio requeue comment.

@Rakshith-R Rakshith-R added the ci/retry/e2e Label to retry e2e retesting on approved PR's label Mar 12, 2025
@ceph-csi-bot
Copy link
Collaborator

/retest ci/centos/upgrade-tests-rbd

@ceph-csi-bot
Copy link
Collaborator

@Rakshith-R "ci/centos/upgrade-tests-rbd" test failed. Logs are available at location for debugging

@ceph-csi-bot
Copy link
Collaborator

/retest ci/centos/upgrade-tests-cephfs

@ceph-csi-bot
Copy link
Collaborator

@Rakshith-R "ci/centos/upgrade-tests-cephfs" test failed. Logs are available at location for debugging

@ceph-csi-bot
Copy link
Collaborator

@Mergifyio requeue

@mergify
Copy link
Contributor

mergify bot commented Mar 12, 2025

requeue

✅ The queue state of this pull request has been cleaned. It can be re-embarked automatically

@ceph-csi-bot
Copy link
Collaborator

/retest ci/centos/upgrade-tests-cephfs

@ceph-csi-bot
Copy link
Collaborator

@Rakshith-R "ci/centos/upgrade-tests-cephfs" test failed. Logs are available at location for debugging

@ceph-csi-bot
Copy link
Collaborator

/retest ci/centos/upgrade-tests-rbd

@ceph-csi-bot
Copy link
Collaborator

@Rakshith-R "ci/centos/upgrade-tests-rbd" test failed. Logs are available at location for debugging

@ceph-csi-bot
Copy link
Collaborator

@Mergifyio requeue

@mergify
Copy link
Contributor

mergify bot commented Mar 12, 2025

requeue

☑️ This pull request is already queued

@Rakshith-R Rakshith-R removed the ci/retry/e2e Label to retry e2e retesting on approved PR's label Mar 12, 2025
@Rakshith-R
Copy link
Contributor Author

Upgrade tests are failing due to
#5211

@Rakshith-R
Copy link
Contributor Author

/retest ci/centos/upgrade-tests-rbd

@Rakshith-R
Copy link
Contributor Author

/retest ci/centos/upgrade-tests-cephfs

@Rakshith-R
Copy link
Contributor Author

@Mergifyio requeue

@mergify
Copy link
Contributor

mergify bot commented Mar 12, 2025

requeue

☑️ This pull request is already queued

@mergify mergify bot merged commit 796e6b6 into ceph:devel Mar 12, 2025
40 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

component/rbd Issues related to RBD

Projects

None yet

Development

Successfully merging this pull request may close these issues.

rbd: Avoid flattening child images which are in trash

4 participants