Skip to content
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

Refactor get device by volumeID routines #940

Merged
merged 9 commits into from
Apr 24, 2024

Conversation

huww98
Copy link
Contributor

@huww98 huww98 commented Jan 8, 2024

What type of PR is this?

/kind cleanup

What this PR does / why we need it:

  • Extract logic to gain testability
  • Try device link first
  • Support NVMe device link
  • Return the disk/by-id path if found
  • Support for NVMe device in getDeviceBySerial
  • Remove search disk by udevadm
  • Merge in the logic of GetRootSubDevicePath into adaptDevicePartition
  • Add unit test

See commit message for details

Which issue(s) this PR fixes:

Fixes the confusing error message when AD controller enabled but disk not found:

Old: NodeStageVolume: ADController Enabled, but device can't be found:d-2ze08oskojgoeh7vceblvolumeID link path "/dev/disk/by-id/virtio-2ze08oskojgoeh7vcebl" not found

New: NodeStageVolume: ADController Enabled, but disk d-2ze08oskojgoeh7vceblvolume can't be found: [get by link "/dev/disk/by-id/virtio-2ze08oskojgoeh7vcebl" failed: file does not exist, get by link "/dev/disk/by-id/nvme-Alibaba_Cloud_Elastic_Block_Storage_2ze08oskojgoeh7vcebl" failed: file does not exist, find by serial: device not found]

Special notes for your reviewer:

Does this PR introduce a user-facing change?

NONE

Additional documentation e.g., KEPs (Kubernetes Enhancement Proposals), usage docs, etc.:


@k8s-ci-robot k8s-ci-robot added do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels Jan 8, 2024
@k8s-ci-robot
Copy link
Contributor

Hi @huww98. Thanks for your PR.

I'm waiting for a kubernetes-sigs member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

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.

@k8s-ci-robot k8s-ci-robot added needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Jan 8, 2024
@huww98 huww98 marked this pull request as ready for review January 8, 2024 10:24
@k8s-ci-robot k8s-ci-robot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Jan 8, 2024
@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Feb 22, 2024
@k8s-ci-robot k8s-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Mar 4, 2024
@huww98 huww98 force-pushed the refine-find-by-id branch 2 times, most recently from e0e2fad to 49c755c Compare March 4, 2024 09:48
@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Mar 5, 2024
@k8s-ci-robot k8s-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Apr 17, 2024
@huww98 huww98 force-pushed the refine-find-by-id branch 3 times, most recently from 41a9f4b to 630230b Compare April 17, 2024 12:40
pkg/disk/device_manager.go Outdated Show resolved Hide resolved
}

// this is danger in Bdf mode
if !m.DisableSerial {
Copy link
Contributor

Choose a reason for hiding this comment

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

same as above

log.Infof("AttachDisk: Successful attach bdf disk %s to node %s device %s by DiskID/Device mapping", diskID, nodeID, deviceName)
return deviceName, nil
_, err := DefaultDeviceManager.GetRootBlockByVolumeID(diskID)
if err != nil && bdf != "" {
Copy link
Contributor

Choose a reason for hiding this comment

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

these nest ifs are very confused, try to clarify 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.

I think this is out of the scope of this PR. I've reverted some changes here

Try device link first, since it is the most efficient.

Report aggregated error message if device is not found.
Currently we only report the confusing "virtio-" link not found.
to gain testablilty
If udev is working, we should be able to find the disk by /dev/disk/by-id link.
If it is not working, we should directly query the kernel by sysfs.
@huww98 huww98 force-pushed the refine-find-by-id branch 2 times, most recently from 7b01d3c to 2ff265a Compare April 23, 2024 13:47
Return the disk/by-id path if found, it is safer if disk is detached when we are processing.
The path is auto removed with the device, and cannot be reused by another disk.

Avoid filepath.EvalSymlinks(). This function is complex. It resolves ALL symlinks in the path, not just the link pointed by the path.
We instead verify the link by stat this path to see it is really a block special file.

Extract every global dependency into instanced field for testablity.

Add unit test for every function.
@huww98
Copy link
Contributor Author

huww98 commented Apr 23, 2024

/ok-to-test
@mowangdk I've refactored some nested branches. And some more. PTAL again~

@k8s-ci-robot k8s-ci-robot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Apr 23, 2024
@mowangdk
Copy link
Contributor

/lgtm
/approve

Please add partition disk e2e test.

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Apr 24, 2024
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: huww98, mowangdk

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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Apr 24, 2024
@k8s-ci-robot k8s-ci-robot merged commit a6b5c98 into kubernetes-sigs:master Apr 24, 2024
7 checks passed
@huww98 huww98 deleted the refine-find-by-id branch April 26, 2024 16:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. lgtm "Looks good to me", indicates that a PR is ready to be merged. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants