Provide Flex volume metrics if the plugin supports.

This commit is contained in:
Srini Brahmaroutu
2018-08-15 23:23:26 -07:00
parent 4414ae3d75
commit 6777dc7404
5 changed files with 33 additions and 12 deletions

View File

@@ -220,14 +220,16 @@ type DriverStatus struct {
} }
type DriverCapabilities struct { type DriverCapabilities struct {
Attach bool `json:"attach"` Attach bool `json:"attach"`
SELinuxRelabel bool `json:"selinuxRelabel"` SELinuxRelabel bool `json:"selinuxRelabel"`
SupportsMetrics bool `json:"supportsMetrics"`
} }
func defaultCapabilities() *DriverCapabilities { func defaultCapabilities() *DriverCapabilities {
return &DriverCapabilities{ return &DriverCapabilities{
Attach: true, Attach: true,
SELinuxRelabel: true, SELinuxRelabel: true,
SupportsMetrics: false,
} }
} }

View File

@@ -32,7 +32,6 @@ type flexVolumeMounter struct {
// the considered volume spec // the considered volume spec
spec *volume.Spec spec *volume.Spec
readOnly bool readOnly bool
volume.MetricsNil
} }
var _ volume.Mounter = &flexVolumeMounter{} var _ volume.Mounter = &flexVolumeMounter{}

View File

@@ -177,6 +177,14 @@ func (plugin *flexVolumePlugin) newMounterInternal(spec *volume.Spec, pod *api.P
return nil, err return nil, err
} }
var metricsProvider volume.MetricsProvider
if plugin.capabilities.SupportsMetrics {
metricsProvider = volume.NewMetricsStatFS(plugin.host.GetPodVolumeDir(
pod.UID, utilstrings.EscapeQualifiedNameForDisk(sourceDriver), spec.Name()))
} else {
metricsProvider = &volume.MetricsNil{}
}
return &flexVolumeMounter{ return &flexVolumeMounter{
flexVolume: &flexVolume{ flexVolume: &flexVolume{
driverName: sourceDriver, driverName: sourceDriver,
@@ -188,6 +196,7 @@ func (plugin *flexVolumePlugin) newMounterInternal(spec *volume.Spec, pod *api.P
podNamespace: pod.Namespace, podNamespace: pod.Namespace,
podServiceAccountName: pod.Spec.ServiceAccountName, podServiceAccountName: pod.Spec.ServiceAccountName,
volName: spec.Name(), volName: spec.Name(),
MetricsProvider: metricsProvider,
}, },
runner: runner, runner: runner,
spec: spec, spec: spec,
@@ -202,14 +211,23 @@ func (plugin *flexVolumePlugin) NewUnmounter(volName string, podUID types.UID) (
// newUnmounterInternal is the internal unmounter routine to clean the volume. // newUnmounterInternal is the internal unmounter routine to clean the volume.
func (plugin *flexVolumePlugin) newUnmounterInternal(volName string, podUID types.UID, mounter mount.Interface, runner exec.Interface) (volume.Unmounter, error) { func (plugin *flexVolumePlugin) newUnmounterInternal(volName string, podUID types.UID, mounter mount.Interface, runner exec.Interface) (volume.Unmounter, error) {
var metricsProvider volume.MetricsProvider
if plugin.capabilities.SupportsMetrics {
metricsProvider = volume.NewMetricsStatFS(plugin.host.GetPodVolumeDir(
podUID, utilstrings.EscapeQualifiedNameForDisk(plugin.driverName), volName))
} else {
metricsProvider = &volume.MetricsNil{}
}
return &flexVolumeUnmounter{ return &flexVolumeUnmounter{
flexVolume: &flexVolume{ flexVolume: &flexVolume{
driverName: plugin.driverName, driverName: plugin.driverName,
execPath: plugin.getExecutable(), execPath: plugin.getExecutable(),
mounter: mounter, mounter: mounter,
plugin: plugin, plugin: plugin,
podUID: podUID, podUID: podUID,
volName: volName, volName: volName,
MetricsProvider: metricsProvider,
}, },
runner: runner, runner: runner,
}, nil }, nil

View File

@@ -31,7 +31,6 @@ type flexVolumeUnmounter struct {
*flexVolume *flexVolume
// Runner used to teardown the volume. // Runner used to teardown the volume.
runner exec.Interface runner exec.Interface
volume.MetricsNil
} }
var _ volume.Unmounter = &flexVolumeUnmounter{} var _ volume.Unmounter = &flexVolumeUnmounter{}

View File

@@ -20,6 +20,7 @@ import (
"k8s.io/apimachinery/pkg/types" "k8s.io/apimachinery/pkg/types"
"k8s.io/kubernetes/pkg/util/mount" "k8s.io/kubernetes/pkg/util/mount"
utilstrings "k8s.io/kubernetes/pkg/util/strings" utilstrings "k8s.io/kubernetes/pkg/util/strings"
"k8s.io/kubernetes/pkg/volume"
) )
type flexVolume struct { type flexVolume struct {
@@ -42,6 +43,8 @@ type flexVolume struct {
volName string volName string
// the underlying plugin // the underlying plugin
plugin *flexVolumePlugin plugin *flexVolumePlugin
// the metric plugin
volume.MetricsProvider
} }
// volume.Volume interface // volume.Volume interface