-
Notifications
You must be signed in to change notification settings - Fork 615
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
[cinder-csi-plugin] NodeGetVolumeStats() implementation #941
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,6 +24,9 @@ import ( | |
"strings" | ||
"time" | ||
|
||
"k8s.io/cloud-provider-openstack/pkg/util/blockdevice" | ||
|
||
"golang.org/x/sys/unix" | ||
"k8s.io/apimachinery/pkg/util/wait" | ||
"k8s.io/klog" | ||
"k8s.io/utils/exec" | ||
|
@@ -49,6 +52,66 @@ type IMount interface { | |
GetInstanceID() (string, error) | ||
MakeFile(pathname string) error | ||
MakeDir(pathname string) error | ||
PathExists(path string) (bool, error) | ||
GetDeviceStats(path string) (*DeviceStats, error) | ||
} | ||
|
||
type DeviceStats struct { | ||
Block bool | ||
|
||
AvailableBytes int64 | ||
TotalBytes int64 | ||
UsedBytes int64 | ||
AvailableInodes int64 | ||
TotalInodes int64 | ||
UsedInodes int64 | ||
} | ||
|
||
func (m *Mount) PathExists(volumePath string) (bool, error) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. :nit: i think this func exists in k8s.io/util/ There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It has an additional check for a "corrupted mount". I'm not sure that this is required and this may introduce a potential false-positive. |
||
_, err := os.Stat(volumePath) | ||
if err != nil { | ||
if os.IsNotExist(err) { | ||
return false, nil | ||
} | ||
return false, fmt.Errorf("failed to stat target, err: %s", err) | ||
} | ||
|
||
return true, nil | ||
} | ||
|
||
func (m *Mount) GetDeviceStats(path string) (*DeviceStats, error) { | ||
isBlock, err := blockdevice.IsBlockDevice(path) | ||
|
||
if isBlock { | ||
size, err := blockdevice.GetBlockDeviceSize(path) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return &DeviceStats{ | ||
Block: true, | ||
TotalBytes: size, | ||
}, nil | ||
} | ||
|
||
var statfs unix.Statfs_t | ||
// See http://man7.org/linux/man-pages/man2/statfs.2.html for details. | ||
err = unix.Statfs(path, &statfs) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return &DeviceStats{ | ||
Block: false, | ||
|
||
AvailableBytes: int64(statfs.Bavail) * statfs.Bsize, | ||
TotalBytes: int64(statfs.Blocks) * statfs.Bsize, | ||
UsedBytes: (int64(statfs.Blocks) - int64(statfs.Bfree)) * statfs.Bsize, | ||
|
||
AvailableInodes: int64(statfs.Ffree), | ||
TotalInodes: int64(statfs.Files), | ||
UsedInodes: int64(statfs.Files) - int64(statfs.Ffree), | ||
}, nil | ||
} | ||
|
||
type Mount struct { | ||
|
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.
This function should comply with csi spec on required fields etc.
please run
make test-cinder-csi-sanity
and fix the issues respective to this function.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.
All sanity test errors related to
NodeGetVolumeStats
are fixed. Some tests fail on other methods, but it seems to be out of the scope of this PR.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.
+1, Awesome!! Thanks.