Commit ea89d627 authored by Kubernetes Submit Queue's avatar Kubernetes Submit Queue Committed by GitHub

Merge pull request #48486 from cofyc/rbd_metrics

Automatic merge from submit-queue (batch tested with PRs 49081, 49318, 49219, 48989, 48486) Use MetricsStatsFs to expose RBD volume plugin metrics. **What this PR does / why we need it**: We need to monitor RBD volume usage of our cluster and configure alerts if RBD volume is nearly full. Users of cluster also need to see usage history graph on Grafana. This PR use MetricsStatsFs to implement MetricsProvider interface of RBD plugin (same as `gce_pd`), so kubelet /stat/summary can expose RBD volume stats. **Special notes for your reviewer**: cc @rootfs **Release note**: ```release-note NONE ```
parents ab3d36b9 777595ef
...@@ -66,6 +66,10 @@ const ( ...@@ -66,6 +66,10 @@ const (
rbdDefaultUserId = rbdDefaultAdminId rbdDefaultUserId = rbdDefaultAdminId
) )
func getPath(uid types.UID, volName string, host volume.VolumeHost) string {
return host.GetPodVolumeDir(uid, strings.EscapeQualifiedNameForDisk(rbdPluginName), volName)
}
func (plugin *rbdPlugin) Init(host volume.VolumeHost) error { func (plugin *rbdPlugin) Init(host volume.VolumeHost) error {
plugin.host = host plugin.host = host
return nil return nil
...@@ -148,14 +152,15 @@ func (plugin *rbdPlugin) newMounterInternal(spec *volume.Spec, podUID types.UID, ...@@ -148,14 +152,15 @@ func (plugin *rbdPlugin) newMounterInternal(spec *volume.Spec, podUID types.UID,
return &rbdMounter{ return &rbdMounter{
rbd: &rbd{ rbd: &rbd{
podUID: podUID, podUID: podUID,
volName: spec.Name(), volName: spec.Name(),
Image: source.RBDImage, Image: source.RBDImage,
Pool: pool, Pool: pool,
ReadOnly: readOnly, ReadOnly: readOnly,
manager: manager, manager: manager,
mounter: &mount.SafeFormatAndMount{Interface: mounter, Runner: exec.New()}, mounter: &mount.SafeFormatAndMount{Interface: mounter, Runner: exec.New()},
plugin: plugin, plugin: plugin,
MetricsProvider: volume.NewMetricsStatFS(getPath(podUID, spec.Name(), plugin.host)),
}, },
Mon: source.CephMonitors, Mon: source.CephMonitors,
Id: id, Id: id,
...@@ -175,11 +180,12 @@ func (plugin *rbdPlugin) newUnmounterInternal(volName string, podUID types.UID, ...@@ -175,11 +180,12 @@ func (plugin *rbdPlugin) newUnmounterInternal(volName string, podUID types.UID,
return &rbdUnmounter{ return &rbdUnmounter{
rbdMounter: &rbdMounter{ rbdMounter: &rbdMounter{
rbd: &rbd{ rbd: &rbd{
podUID: podUID, podUID: podUID,
volName: volName, volName: volName,
manager: manager, manager: manager,
mounter: &mount.SafeFormatAndMount{Interface: mounter, Runner: exec.New()}, mounter: &mount.SafeFormatAndMount{Interface: mounter, Runner: exec.New()},
plugin: plugin, plugin: plugin,
MetricsProvider: volume.NewMetricsStatFS(getPath(podUID, volName, plugin.host)),
}, },
Mon: make([]string, 0), Mon: make([]string, 0),
}, },
...@@ -381,8 +387,7 @@ type rbdVolumeDeleter struct { ...@@ -381,8 +387,7 @@ type rbdVolumeDeleter struct {
} }
func (r *rbdVolumeDeleter) GetPath() string { func (r *rbdVolumeDeleter) GetPath() string {
name := rbdPluginName return getPath(r.podUID, r.volName, r.plugin.host)
return r.plugin.host.GetPodVolumeDir(r.podUID, strings.EscapeQualifiedNameForDisk(name), r.volName)
} }
func (r *rbdVolumeDeleter) Delete() error { func (r *rbdVolumeDeleter) Delete() error {
...@@ -399,13 +404,12 @@ type rbd struct { ...@@ -399,13 +404,12 @@ type rbd struct {
mounter *mount.SafeFormatAndMount mounter *mount.SafeFormatAndMount
// Utility interface that provides API calls to the provider to attach/detach disks. // Utility interface that provides API calls to the provider to attach/detach disks.
manager diskManager manager diskManager
volume.MetricsNil volume.MetricsProvider
} }
func (rbd *rbd) GetPath() string { func (rbd *rbd) GetPath() string {
name := rbdPluginName
// safe to use PodVolumeDir now: volume teardown occurs before pod is cleaned up // safe to use PodVolumeDir now: volume teardown occurs before pod is cleaned up
return rbd.plugin.host.GetPodVolumeDir(rbd.podUID, strings.EscapeQualifiedNameForDisk(name), rbd.volName) return getPath(rbd.podUID, rbd.volName, rbd.plugin.host)
} }
type rbdMounter struct { type rbdMounter struct {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment