mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-09-19 17:16:12 +00:00
Add SupportsMetrics() for Block-mode volumes
Volumes that are provisioned with `VolumeMode: Block` often have a MetrucsProvider interface declared in their type. However, the MetricsProvider should implement a GetMetrics() function. In the cases where the storage drivers do not implement GetMetrics(), a panic can occur. Usual type-assertions are not sufficient in this case. All assertions assume the interface is present. There is no straight forward way to verify that a valid GetMetrics() function is provided. By adding SupportsMetrics(), storage driver implementations require careful reviewing for metrics support.
This commit is contained in:
@@ -112,7 +112,12 @@ func (s *volumeStatCalculator) calcAndStoreStats() {
|
||||
for name, v := range blockVolumes {
|
||||
// Only add the blockVolume if it implements the MetricsProvider interface
|
||||
if _, ok := v.(volume.MetricsProvider); ok {
|
||||
metricVolumes[name] = v
|
||||
// Some drivers inherit the MetricsProvider interface from Filesystem
|
||||
// mode volumes, but do not implement it for Block mode. Checking
|
||||
// SupportsMetrics() will prevent panics in that case.
|
||||
if v.SupportsMetrics() {
|
||||
metricVolumes[name] = v
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -246,6 +246,8 @@ func (v *fakeBlockVolume) GetGlobalMapPath(*volume.Spec) (string, error) { retur
|
||||
|
||||
func (v *fakeBlockVolume) GetPodDeviceMapPath() (string, string) { return "", "" }
|
||||
|
||||
func (v *fakeBlockVolume) SupportsMetrics() bool { return true }
|
||||
|
||||
func (v *fakeBlockVolume) GetMetrics() (*volume.Metrics, error) {
|
||||
return expectedBlockMetrics(), nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user