-
Notifications
You must be signed in to change notification settings - Fork 3
Add support for MutableCSINodeAllocatableCount #1066
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
nschad
wants to merge
11
commits into
main
Choose a base branch
from
dynamic-volume-limits
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.
Open
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
5726292
Add support for MutableCSINodeAllocatableCount
nschad a2bc65c
fix imports for linux
nschad 101b731
subtract one from maxVolumes for root partition
nschad e6e983c
WIP
nschad 7f0c7bf
parse Body instead of ErrorMessage field in IsTooManyDevicesError()
nschad 16bfec0
cleanup
nschad ed9e7bb
address linter feedback
nschad e104889
add unit tests and restructure into helper function
breuerfelix 09065c9
rewrite tests with ginkgo
breuerfelix 9173dea
fix golint
breuerfelix d084be2
add volumeDevice counting
breuerfelix 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
This file was deleted.
Oops, something went wrong.
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,116 @@ | ||
| package mount | ||
|
|
||
| import ( | ||
| "encoding/json" | ||
| "fmt" | ||
| "os" | ||
| "path/filepath" | ||
| "strings" | ||
|
|
||
| "k8s.io/klog/v2" | ||
| ) | ||
|
|
||
| const ( | ||
| // pciClassBridgePCI matches the Linux PCI-to-PCI bridge class prefix. | ||
| pciClassBridgePCI = "0x0604" | ||
| globalMountDir = "globalmount" | ||
| volumeDevicesDir = "volumeDevices" | ||
| volumeDataDir = "data" | ||
| volumeDataFile = "vol_data.json" | ||
| driverNameKey = "driverName" | ||
| ) | ||
|
|
||
| func countFreePCIeSlotsAt(devicesPath string) (int64, error) { | ||
| devices, err := os.ReadDir(devicesPath) | ||
| if err != nil { | ||
| return 0, fmt.Errorf("failed to read PCI bus: %w", err) | ||
| } | ||
|
|
||
| var freePCIeSlots int64 | ||
|
|
||
| for _, dev := range devices { | ||
| devPath := filepath.Join(devicesPath, dev.Name()) | ||
|
|
||
| classBuf, err := os.ReadFile(filepath.Join(devPath, "class")) | ||
| if err != nil { | ||
| klog.Errorf("failed to read PCI device class %s: %v", devPath, err) | ||
| continue | ||
| } | ||
|
|
||
| class := strings.TrimSpace(string(classBuf)) | ||
| if !strings.HasPrefix(class, pciClassBridgePCI) { | ||
| continue | ||
| } | ||
|
|
||
| children, err := filepath.Glob(filepath.Join(devPath, "????:??:??.?")) | ||
| if err != nil { | ||
| return 0, fmt.Errorf("failed to glob PCI children for %s: %w", devPath, err) | ||
| } | ||
|
|
||
| if len(children) == 0 { | ||
| freePCIeSlots++ | ||
| } | ||
| } | ||
|
|
||
| return freePCIeSlots, nil | ||
| } | ||
|
|
||
| func countLocalCSIVolumesAt(driverPluginDir, csiPluginDir, driverName string) (int64, error) { | ||
| filesystemVolumes, err := countLocalCSIFilesystemVolumesAt(driverPluginDir) | ||
| if err != nil { | ||
| return 0, err | ||
| } | ||
|
|
||
| blockVolumes, err := countLocalCSIBlockVolumesAt(csiPluginDir, driverName) | ||
| if err != nil { | ||
| return 0, err | ||
| } | ||
|
|
||
| return filesystemVolumes + blockVolumes, nil | ||
| } | ||
|
|
||
| func countLocalCSIFilesystemVolumesAt(driverPluginDir string) (int64, error) { | ||
| volumeMounts, err := filepath.Glob(filepath.Join(driverPluginDir, "*", globalMountDir)) | ||
| if err != nil { | ||
| return 0, fmt.Errorf("failed to glob CSI volume mounts in %s: %w", driverPluginDir, err) | ||
| } | ||
|
|
||
| return int64(len(volumeMounts)), nil | ||
| } | ||
|
|
||
| func countLocalCSIBlockVolumesAt(csiPluginDir, driverName string) (int64, error) { | ||
| volumeMetadataFiles, err := filepath.Glob(filepath.Join(csiPluginDir, volumeDevicesDir, "*", volumeDataDir, volumeDataFile)) | ||
| if err != nil { | ||
| return 0, fmt.Errorf("failed to glob CSI block volume metadata in %s: %w", csiPluginDir, err) | ||
| } | ||
|
|
||
| var blockVolumes int64 | ||
|
|
||
| for _, metadataPath := range volumeMetadataFiles { | ||
| metadata, err := readCSIVolumeDeviceMetadata(metadataPath) | ||
| if err != nil { | ||
| klog.Errorf("failed to read CSI block volume metadata %s: %v", metadataPath, err) | ||
| continue | ||
| } | ||
|
|
||
| if metadata[driverNameKey] == driverName { | ||
| blockVolumes++ | ||
| } | ||
| } | ||
|
|
||
| return blockVolumes, nil | ||
| } | ||
|
|
||
| func readCSIVolumeDeviceMetadata(metadataPath string) (map[string]string, error) { | ||
| metadataBuf, err := os.ReadFile(metadataPath) | ||
| if err != nil { | ||
| return nil, fmt.Errorf("read file: %w", err) | ||
| } | ||
|
|
||
| var metadata map[string]string | ||
| if err := json.Unmarshal(metadataBuf, &metadata); err != nil { | ||
| return nil, fmt.Errorf("parse JSON: %w", err) | ||
| } | ||
|
|
||
| return metadata, nil | ||
| } |
Oops, something went wrong.
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.
why the receiver? AFAIK we don't use it?