From a6984e00ef12f55a145f8a5373f4e53581dbf1ea Mon Sep 17 00:00:00 2001 From: "m.nabokikh" Date: Tue, 23 Aug 2022 15:45:07 +0400 Subject: [PATCH 1/3] feat: Add local storage labels to kube_persistentvolume_info Signed-off-by: m.nabokikh --- docs/persistentvolume-metrics.md | 18 +++---- internal/store/persistentvolume.go | 11 +++- internal/store/persistentvolume_test.go | 70 +++++++++++++++++++++---- 3 files changed, 78 insertions(+), 21 deletions(-) diff --git a/docs/persistentvolume-metrics.md b/docs/persistentvolume-metrics.md index 631b67a9fe..64ca4f76da 100644 --- a/docs/persistentvolume-metrics.md +++ b/docs/persistentvolume-metrics.md @@ -1,12 +1,12 @@ # PersistentVolume Metrics -| Metric name | Metric type | Description | Unit (where applicable) | Labels/tags | Status | -| ----------- | ----------- | ----------- | ----------- | ----------- | ------------ | -| kube_persistentvolume_annotations | Gauge | | | `persistentvolume`=<persistentvolume-name>
`annotation_PERSISTENTVOLUME_ANNOTATION`=<PERSISTENTVOLUME_ANNOTATION> | EXPERIMENTAL | -| kube_persistentvolume_capacity_bytes | Gauge | | | `persistentvolume`=<pv-name> | STABLE | -| kube_persistentvolume_status_phase | Gauge | | | `persistentvolume`=<pv-name>
`phase`=<Bound\|Failed\|Pending\|Available\|Released> | STABLE | -| kube_persistentvolume_claim_ref | Gauge | | | `persistentvolume`=<pv-name>
`claim_namespace`=<>
`name`=<> | STABLE | -| kube_persistentvolume_labels | Gauge | | | `persistentvolume`=<persistentvolume-name>
`label_PERSISTENTVOLUME_LABEL`=<PERSISTENTVOLUME_LABEL> | STABLE | -| kube_persistentvolume_info | Gauge | | | `persistentvolume`=<pv-name>
`storageclass`=<storageclass-name>
`gce_persistent_disk_name`=<pd-name>
`ebs_volume_id`=<ebs-volume-id>
`azure_disk_name`=<azure-disk-name>
`fc_wwids`=<fc-wwids-comma-separated>
`fc_lun`=<fc-lun>
`fc_target_wwns`=<fc-target-wwns-comma-separated>
`iscsi_target_portal`=<iscsi-target-portal>
`iscsi_iqn`=<iscsi-iqn>
`iscsi_lun`=<iscsi-lun>
`iscsi_initiator_name`=<iscsi-initiator-name>
`nfs_server`=<nfs-server>
`nfs_path`=<nfs-path>
`csi_driver`=<csi-driver>
`csi_volume_handle`=<csi-volume-handle> | STABLE | -| kube_persistentvolume_created | Gauge | Unix Creation Timestamp | seconds | `persistentvolume`=<persistentvolume-name>
| EXPERIMENTAL | +| Metric name | Metric type | Description | Unit (where applicable) | Labels/tags | Status | +| ----------- | ----------- | ----------- | ----------- |-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| ------------ | +| kube_persistentvolume_annotations | Gauge | | | `persistentvolume`=<persistentvolume-name>
`annotation_PERSISTENTVOLUME_ANNOTATION`=<PERSISTENTVOLUME_ANNOTATION> | EXPERIMENTAL | +| kube_persistentvolume_capacity_bytes | Gauge | | | `persistentvolume`=<pv-name> | STABLE | +| kube_persistentvolume_status_phase | Gauge | | | `persistentvolume`=<pv-name>
`phase`=<Bound\ |Failed\|Pending\|Available\|Released> | STABLE | +| kube_persistentvolume_claim_ref | Gauge | | | `persistentvolume`=<pv-name>
`claim_namespace`=<>
`name`=<> | STABLE | +| kube_persistentvolume_labels | Gauge | | | `persistentvolume`=<persistentvolume-name>
`label_PERSISTENTVOLUME_LABEL`=<PERSISTENTVOLUME_LABEL> | STABLE | +| kube_persistentvolume_info | Gauge | | | `persistentvolume`=<pv-name>
`storageclass`=<storageclass-name>
`gce_persistent_disk_name`=<pd-name>
`ebs_volume_id`=<ebs-volume-id>
`azure_disk_name`=<azure-disk-name>
`fc_wwids`=<fc-wwids-comma-separated>
`fc_lun`=<fc-lun>
`fc_target_wwns`=<fc-target-wwns-comma-separated>
`iscsi_target_portal`=<iscsi-target-portal>
`iscsi_iqn`=<iscsi-iqn>
`iscsi_lun`=<iscsi-lun>
`iscsi_initiator_name`=<iscsi-initiator-name>
`local_path`=<path-of-a-local-volume>
`local_fs`=<local-volume-fs-type>
`nfs_server`=<nfs-server>
`nfs_path`=<nfs-path>
`csi_driver`=<csi-driver>
`csi_volume_handle`=<csi-volume-handle> | STABLE | +| kube_persistentvolume_created | Gauge | Unix Creation Timestamp | seconds | `persistentvolume`=<persistentvolume-name>
| EXPERIMENTAL | diff --git a/internal/store/persistentvolume.go b/internal/store/persistentvolume.go index 54b0251dd5..e4e1d3f97c 100644 --- a/internal/store/persistentvolume.go +++ b/internal/store/persistentvolume.go @@ -164,7 +164,7 @@ func persistentVolumeMetricFamilies(allowAnnotationsList, allowLabelsList []stri metric.Gauge, "", wrapPersistentVolumeFunc(func(p *v1.PersistentVolume) *metric.Family { - var gcePDDiskName, ebsVolumeID, azureDiskName, fcWWIDs, fcLun, fcTargetWWNs, iscsiTargetPortal, iscsiIQN, iscsiLun, iscsiInitiatorName, nfsServer, nfsPath, csiDriver, csiVolumeHandle string + var gcePDDiskName, ebsVolumeID, azureDiskName, fcWWIDs, fcLun, fcTargetWWNs, iscsiTargetPortal, iscsiIQN, iscsiLun, iscsiInitiatorName, nfsServer, nfsPath, csiDriver, csiVolumeHandle, localFS, localPath string switch { case p.Spec.PersistentVolumeSource.GCEPersistentDisk != nil: @@ -202,6 +202,11 @@ func persistentVolumeMetricFamilies(allowAnnotationsList, allowLabelsList []stri case p.Spec.PersistentVolumeSource.CSI != nil: csiDriver = p.Spec.PersistentVolumeSource.CSI.Driver csiVolumeHandle = p.Spec.PersistentVolumeSource.CSI.VolumeHandle + case p.Spec.Local != nil: + localPath = p.Spec.Local.Path + if p.Spec.Local.FSType != nil { + localFS = *p.Spec.Local.FSType + } } return &metric.Family{ @@ -223,6 +228,8 @@ func persistentVolumeMetricFamilies(allowAnnotationsList, allowLabelsList []stri "nfs_path", "csi_driver", "csi_volume_handle", + "local_path", + "local_fs", }, LabelValues: []string{ p.Spec.StorageClassName, @@ -240,6 +247,8 @@ func persistentVolumeMetricFamilies(allowAnnotationsList, allowLabelsList []stri nfsPath, csiDriver, csiVolumeHandle, + localPath, + localFS, }, Value: 1, }, diff --git a/internal/store/persistentvolume_test.go b/internal/store/persistentvolume_test.go index ebbc9bf2bd..7e7450cdcf 100644 --- a/internal/store/persistentvolume_test.go +++ b/internal/store/persistentvolume_test.go @@ -23,6 +23,7 @@ import ( v1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/api/resource" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/utils/pointer" generator "k8s.io/kube-state-metrics/v2/pkg/metric_generator" ) @@ -171,7 +172,7 @@ func TestPersistentVolumeStore(t *testing.T) { Want: ` # HELP kube_persistentvolume_info Information about persistentvolume. # TYPE kube_persistentvolume_info gauge - kube_persistentvolume_info{azure_disk_name="",ebs_volume_id="",fc_lun="",fc_target_wwns="",fc_wwids="",gce_persistent_disk_name="",iscsi_initiator_name="",iscsi_iqn="",iscsi_lun="",iscsi_target_portal="",nfs_path="",nfs_server="",csi_driver="",csi_volume_handle="",persistentvolume="test-pv-available",storageclass=""} 1 + kube_persistentvolume_info{azure_disk_name="",ebs_volume_id="",fc_lun="",fc_target_wwns="",fc_wwids="",gce_persistent_disk_name="",iscsi_initiator_name="",iscsi_iqn="",iscsi_lun="",iscsi_target_portal="",local_path="",local_fs="",nfs_path="",nfs_server="",csi_driver="",csi_volume_handle="",persistentvolume="test-pv-available",storageclass=""} 1 `, MetricNames: []string{"kube_persistentvolume_info"}, }, @@ -190,7 +191,7 @@ func TestPersistentVolumeStore(t *testing.T) { Want: ` # HELP kube_persistentvolume_info Information about persistentvolume. # TYPE kube_persistentvolume_info gauge - kube_persistentvolume_info{azure_disk_name="",ebs_volume_id="",fc_lun="",fc_target_wwns="",fc_wwids="",gce_persistent_disk_name="",iscsi_initiator_name="",iscsi_iqn="",iscsi_lun="",iscsi_target_portal="",nfs_path="",nfs_server="",csi_driver="",csi_volume_handle="",persistentvolume="test-pv-available",storageclass=""} 1 + kube_persistentvolume_info{azure_disk_name="",ebs_volume_id="",fc_lun="",fc_target_wwns="",fc_wwids="",gce_persistent_disk_name="",iscsi_initiator_name="",iscsi_iqn="",iscsi_lun="",iscsi_target_portal="",local_path="",local_fs="",nfs_path="",nfs_server="",csi_driver="",csi_volume_handle="",persistentvolume="test-pv-available",storageclass=""} 1 `, MetricNames: []string{"kube_persistentvolume_info"}, }, @@ -213,7 +214,7 @@ func TestPersistentVolumeStore(t *testing.T) { Want: ` # HELP kube_persistentvolume_info Information about persistentvolume. # TYPE kube_persistentvolume_info gauge - kube_persistentvolume_info{azure_disk_name="",ebs_volume_id="",fc_lun="",fc_target_wwns="",fc_wwids="",gce_persistent_disk_name="name",iscsi_initiator_name="",iscsi_iqn="",iscsi_lun="",iscsi_target_portal="",nfs_path="",nfs_server="",csi_driver="",csi_volume_handle="",persistentvolume="test-pv-available",storageclass=""} 1 + kube_persistentvolume_info{azure_disk_name="",ebs_volume_id="",fc_lun="",fc_target_wwns="",fc_wwids="",gce_persistent_disk_name="name",iscsi_initiator_name="",iscsi_iqn="",iscsi_lun="",iscsi_target_portal="",local_path="",local_fs="",nfs_path="",nfs_server="",csi_driver="",csi_volume_handle="",persistentvolume="test-pv-available",storageclass=""} 1 `, MetricNames: []string{"kube_persistentvolume_info"}, }, @@ -236,7 +237,7 @@ func TestPersistentVolumeStore(t *testing.T) { Want: ` # HELP kube_persistentvolume_info Information about persistentvolume. # TYPE kube_persistentvolume_info gauge - kube_persistentvolume_info{azure_disk_name="",ebs_volume_id="aws://eu-west-1c/vol-012d34d567890123b",fc_lun="",fc_target_wwns="",fc_wwids="",gce_persistent_disk_name="",iscsi_initiator_name="",iscsi_iqn="",iscsi_lun="",iscsi_target_portal="",nfs_path="",nfs_server="",csi_driver="",csi_volume_handle="",persistentvolume="test-pv-available",storageclass=""} 1 + kube_persistentvolume_info{azure_disk_name="",ebs_volume_id="aws://eu-west-1c/vol-012d34d567890123b",fc_lun="",fc_target_wwns="",fc_wwids="",gce_persistent_disk_name="",iscsi_initiator_name="",iscsi_iqn="",iscsi_lun="",iscsi_target_portal="",local_path="",local_fs="",nfs_path="",nfs_server="",csi_driver="",csi_volume_handle="",persistentvolume="test-pv-available",storageclass=""} 1 `, MetricNames: []string{"kube_persistentvolume_info"}, }, @@ -259,7 +260,7 @@ func TestPersistentVolumeStore(t *testing.T) { Want: ` # HELP kube_persistentvolume_info Information about persistentvolume. # TYPE kube_persistentvolume_info gauge - kube_persistentvolume_info{azure_disk_name="azure_disk_1",ebs_volume_id="",fc_lun="",fc_target_wwns="",fc_wwids="",gce_persistent_disk_name="",iscsi_initiator_name="",iscsi_iqn="",iscsi_lun="",iscsi_target_portal="",nfs_path="",nfs_server="",csi_driver="",csi_volume_handle="",persistentvolume="test-pv-available",storageclass=""} 1 + kube_persistentvolume_info{azure_disk_name="azure_disk_1",ebs_volume_id="",fc_lun="",fc_target_wwns="",fc_wwids="",gce_persistent_disk_name="",iscsi_initiator_name="",iscsi_iqn="",iscsi_lun="",iscsi_target_portal="",local_path="",local_fs="",nfs_path="",nfs_server="",csi_driver="",csi_volume_handle="",persistentvolume="test-pv-available",storageclass=""} 1 `, MetricNames: []string{"kube_persistentvolume_info"}, }, @@ -283,7 +284,7 @@ func TestPersistentVolumeStore(t *testing.T) { Want: ` # HELP kube_persistentvolume_info Information about persistentvolume. # TYPE kube_persistentvolume_info gauge - kube_persistentvolume_info{azure_disk_name="",ebs_volume_id="",fc_lun="123",fc_target_wwns="0123456789abcdef,abcdef0123456789",fc_wwids="",gce_persistent_disk_name="",iscsi_initiator_name="",iscsi_iqn="",iscsi_lun="",iscsi_target_portal="",nfs_path="",nfs_server="",csi_driver="",csi_volume_handle="",persistentvolume="test-pv-available",storageclass=""} 1 + kube_persistentvolume_info{azure_disk_name="",ebs_volume_id="",fc_lun="123",fc_target_wwns="0123456789abcdef,abcdef0123456789",fc_wwids="",gce_persistent_disk_name="",iscsi_initiator_name="",iscsi_iqn="",iscsi_lun="",iscsi_target_portal="",local_path="",local_fs="",nfs_path="",nfs_server="",csi_driver="",csi_volume_handle="",persistentvolume="test-pv-available",storageclass=""} 1 `, MetricNames: []string{"kube_persistentvolume_info"}, }, @@ -306,7 +307,7 @@ func TestPersistentVolumeStore(t *testing.T) { Want: ` # HELP kube_persistentvolume_info Information about persistentvolume. # TYPE kube_persistentvolume_info gauge - kube_persistentvolume_info{azure_disk_name="",ebs_volume_id="",fc_lun="",fc_target_wwns="",fc_wwids="0123456789abcdef,abcdef0123456789",gce_persistent_disk_name="",iscsi_initiator_name="",iscsi_iqn="",iscsi_lun="",iscsi_target_portal="",nfs_path="",nfs_server="",csi_driver="",csi_volume_handle="",persistentvolume="test-pv-available",storageclass=""} 1 + kube_persistentvolume_info{azure_disk_name="",ebs_volume_id="",fc_lun="",fc_target_wwns="",fc_wwids="0123456789abcdef,abcdef0123456789",gce_persistent_disk_name="",iscsi_initiator_name="",iscsi_iqn="",iscsi_lun="",iscsi_target_portal="",local_path="",local_fs="",nfs_path="",nfs_server="",csi_driver="",csi_volume_handle="",persistentvolume="test-pv-available",storageclass=""} 1 `, MetricNames: []string{"kube_persistentvolume_info"}, }, @@ -331,7 +332,7 @@ func TestPersistentVolumeStore(t *testing.T) { Want: ` # HELP kube_persistentvolume_info Information about persistentvolume. # TYPE kube_persistentvolume_info gauge - kube_persistentvolume_info{azure_disk_name="",ebs_volume_id="",fc_lun="",fc_target_wwns="",fc_wwids="",gce_persistent_disk_name="",iscsi_initiator_name="",iscsi_iqn="iqn.my.test.server.target00",iscsi_lun="123",iscsi_target_portal="1.2.3.4:3260",nfs_path="",nfs_server="",csi_driver="",csi_volume_handle="",persistentvolume="test-pv-available",storageclass=""} 1 + kube_persistentvolume_info{azure_disk_name="",ebs_volume_id="",fc_lun="",fc_target_wwns="",fc_wwids="",gce_persistent_disk_name="",iscsi_initiator_name="",iscsi_iqn="iqn.my.test.server.target00",iscsi_lun="123",iscsi_target_portal="1.2.3.4:3260",local_path="",local_fs="",nfs_path="",nfs_server="",csi_driver="",csi_volume_handle="",persistentvolume="test-pv-available",storageclass=""} 1 `, MetricNames: []string{"kube_persistentvolume_info"}, }, @@ -357,7 +358,7 @@ func TestPersistentVolumeStore(t *testing.T) { Want: ` # HELP kube_persistentvolume_info Information about persistentvolume. # TYPE kube_persistentvolume_info gauge - kube_persistentvolume_info{azure_disk_name="",ebs_volume_id="",fc_lun="",fc_target_wwns="",fc_wwids="",gce_persistent_disk_name="",iscsi_initiator_name="iqn.my.test.initiator:112233",iscsi_iqn="iqn.my.test.server.target00",iscsi_lun="123",iscsi_target_portal="1.2.3.4:3260",nfs_path="",nfs_server="",csi_driver="",csi_volume_handle="",persistentvolume="test-pv-available",storageclass=""} 1 + kube_persistentvolume_info{azure_disk_name="",ebs_volume_id="",fc_lun="",fc_target_wwns="",fc_wwids="",gce_persistent_disk_name="",iscsi_initiator_name="iqn.my.test.initiator:112233",iscsi_iqn="iqn.my.test.server.target00",iscsi_lun="123",iscsi_target_portal="1.2.3.4:3260",local_path="",local_fs="",nfs_path="",nfs_server="",csi_driver="",csi_volume_handle="",persistentvolume="test-pv-available",storageclass=""} 1 `, MetricNames: []string{"kube_persistentvolume_info"}, }, @@ -381,7 +382,7 @@ func TestPersistentVolumeStore(t *testing.T) { Want: ` # HELP kube_persistentvolume_info Information about persistentvolume. # TYPE kube_persistentvolume_info gauge - kube_persistentvolume_info{azure_disk_name="",ebs_volume_id="",fc_lun="",fc_target_wwns="",fc_wwids="",gce_persistent_disk_name="",iscsi_initiator_name="",iscsi_iqn="",iscsi_lun="",iscsi_target_portal="",nfs_path="/myPath",nfs_server="1.2.3.4",csi_driver="",csi_volume_handle="",persistentvolume="test-pv-available",storageclass=""} 1 + kube_persistentvolume_info{azure_disk_name="",ebs_volume_id="",fc_lun="",fc_target_wwns="",fc_wwids="",gce_persistent_disk_name="",iscsi_initiator_name="",iscsi_iqn="",iscsi_lun="",iscsi_target_portal="",local_path="",local_fs="",nfs_path="/myPath",nfs_server="1.2.3.4",csi_driver="",csi_volume_handle="",persistentvolume="test-pv-available",storageclass=""} 1 `, MetricNames: []string{"kube_persistentvolume_info"}, }, @@ -405,7 +406,54 @@ func TestPersistentVolumeStore(t *testing.T) { Want: ` # HELP kube_persistentvolume_info Information about persistentvolume. # TYPE kube_persistentvolume_info gauge - kube_persistentvolume_info{azure_disk_name="",ebs_volume_id="",fc_lun="",fc_target_wwns="",fc_wwids="",gce_persistent_disk_name="",iscsi_initiator_name="",iscsi_iqn="",iscsi_lun="",iscsi_target_portal="",nfs_path="",nfs_server="",csi_driver="test-driver",csi_volume_handle="test-volume-handle",persistentvolume="test-pv-available",storageclass=""} 1 + kube_persistentvolume_info{azure_disk_name="",ebs_volume_id="",fc_lun="",fc_target_wwns="",fc_wwids="",gce_persistent_disk_name="",iscsi_initiator_name="",iscsi_iqn="",iscsi_lun="",iscsi_target_portal="",local_path="",local_fs="",nfs_path="",nfs_server="",csi_driver="test-driver",csi_volume_handle="test-volume-handle",persistentvolume="test-pv-available",storageclass=""} 1 + `, + MetricNames: []string{"kube_persistentvolume_info"}, + }, + { + Obj: &v1.PersistentVolume{ + Spec: v1.PersistentVolumeSpec{ + PersistentVolumeSource: v1.PersistentVolumeSource{ + Local: &v1.LocalVolumeSource{ + FSType: pointer.String("ext4"), + Path: "/mnt/data", + }, + }, + }, + ObjectMeta: metav1.ObjectMeta{ + Name: "test-pv-available", + }, + Status: v1.PersistentVolumeStatus{ + Phase: v1.VolumeAvailable, + }, + }, + Want: ` + # HELP kube_persistentvolume_info Information about persistentvolume. + # TYPE kube_persistentvolume_info gauge + kube_persistentvolume_info{azure_disk_name="",ebs_volume_id="",fc_lun="",fc_target_wwns="",fc_wwids="",gce_persistent_disk_name="",iscsi_initiator_name="",iscsi_iqn="",iscsi_lun="",iscsi_target_portal="",local_path="/mnt/data",local_fs="ext4",nfs_path="",nfs_server="",csi_driver="",csi_volume_handle="",persistentvolume="test-pv-available",storageclass=""} 1 + `, + MetricNames: []string{"kube_persistentvolume_info"}, + }, + { + Obj: &v1.PersistentVolume{ + Spec: v1.PersistentVolumeSpec{ + PersistentVolumeSource: v1.PersistentVolumeSource{ + Local: &v1.LocalVolumeSource{ + Path: "/mnt/data", + }, + }, + }, + ObjectMeta: metav1.ObjectMeta{ + Name: "test-pv-available", + }, + Status: v1.PersistentVolumeStatus{ + Phase: v1.VolumeAvailable, + }, + }, + Want: ` + # HELP kube_persistentvolume_info Information about persistentvolume. + # TYPE kube_persistentvolume_info gauge + kube_persistentvolume_info{azure_disk_name="",ebs_volume_id="",fc_lun="",fc_target_wwns="",fc_wwids="",gce_persistent_disk_name="",iscsi_initiator_name="",iscsi_iqn="",iscsi_lun="",iscsi_target_portal="",local_path="/mnt/data",local_fs="",nfs_path="",nfs_server="",csi_driver="",csi_volume_handle="",persistentvolume="test-pv-available",storageclass=""} 1 `, MetricNames: []string{"kube_persistentvolume_info"}, }, From 9939059be5529a843e06d570387419c459c1aa3d Mon Sep 17 00:00:00 2001 From: "m.nabokikh" Date: Tue, 23 Aug 2022 17:03:40 +0400 Subject: [PATCH 2/3] Make code inline with the other parts Signed-off-by: m.nabokikh --- internal/store/persistentvolume.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/internal/store/persistentvolume.go b/internal/store/persistentvolume.go index e4e1d3f97c..f4d8b81cb2 100644 --- a/internal/store/persistentvolume.go +++ b/internal/store/persistentvolume.go @@ -202,10 +202,10 @@ func persistentVolumeMetricFamilies(allowAnnotationsList, allowLabelsList []stri case p.Spec.PersistentVolumeSource.CSI != nil: csiDriver = p.Spec.PersistentVolumeSource.CSI.Driver csiVolumeHandle = p.Spec.PersistentVolumeSource.CSI.VolumeHandle - case p.Spec.Local != nil: - localPath = p.Spec.Local.Path - if p.Spec.Local.FSType != nil { - localFS = *p.Spec.Local.FSType + case p.Spec.PersistentVolumeSource.Local != nil: + localPath = p.Spec.PersistentVolumeSource.Local.Path + if p.Spec.PersistentVolumeSource.Local.FSType != nil { + localFS = *p.Spec.PersistentVolumeSource.Local.FSType } } From 9e639b2ff9e0c2831373bdb6e5144152e43cfc23 Mon Sep 17 00:00:00 2001 From: "m.nabokikh" Date: Wed, 24 Aug 2022 11:17:08 +0400 Subject: [PATCH 3/3] Add host path metrics, fix table formatting Signed-off-by: m.nabokikh --- docs/persistentvolume-metrics.md | 18 +++--- internal/store/persistentvolume.go | 21 ++++++- internal/store/persistentvolume_test.go | 77 ++++++++++++++++++++----- 3 files changed, 93 insertions(+), 23 deletions(-) diff --git a/docs/persistentvolume-metrics.md b/docs/persistentvolume-metrics.md index 64ca4f76da..a80e045768 100644 --- a/docs/persistentvolume-metrics.md +++ b/docs/persistentvolume-metrics.md @@ -1,12 +1,12 @@ # PersistentVolume Metrics -| Metric name | Metric type | Description | Unit (where applicable) | Labels/tags | Status | -| ----------- | ----------- | ----------- | ----------- |-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| ------------ | -| kube_persistentvolume_annotations | Gauge | | | `persistentvolume`=<persistentvolume-name>
`annotation_PERSISTENTVOLUME_ANNOTATION`=<PERSISTENTVOLUME_ANNOTATION> | EXPERIMENTAL | -| kube_persistentvolume_capacity_bytes | Gauge | | | `persistentvolume`=<pv-name> | STABLE | -| kube_persistentvolume_status_phase | Gauge | | | `persistentvolume`=<pv-name>
`phase`=<Bound\ |Failed\|Pending\|Available\|Released> | STABLE | -| kube_persistentvolume_claim_ref | Gauge | | | `persistentvolume`=<pv-name>
`claim_namespace`=<>
`name`=<> | STABLE | -| kube_persistentvolume_labels | Gauge | | | `persistentvolume`=<persistentvolume-name>
`label_PERSISTENTVOLUME_LABEL`=<PERSISTENTVOLUME_LABEL> | STABLE | -| kube_persistentvolume_info | Gauge | | | `persistentvolume`=<pv-name>
`storageclass`=<storageclass-name>
`gce_persistent_disk_name`=<pd-name>
`ebs_volume_id`=<ebs-volume-id>
`azure_disk_name`=<azure-disk-name>
`fc_wwids`=<fc-wwids-comma-separated>
`fc_lun`=<fc-lun>
`fc_target_wwns`=<fc-target-wwns-comma-separated>
`iscsi_target_portal`=<iscsi-target-portal>
`iscsi_iqn`=<iscsi-iqn>
`iscsi_lun`=<iscsi-lun>
`iscsi_initiator_name`=<iscsi-initiator-name>
`local_path`=<path-of-a-local-volume>
`local_fs`=<local-volume-fs-type>
`nfs_server`=<nfs-server>
`nfs_path`=<nfs-path>
`csi_driver`=<csi-driver>
`csi_volume_handle`=<csi-volume-handle> | STABLE | -| kube_persistentvolume_created | Gauge | Unix Creation Timestamp | seconds | `persistentvolume`=<persistentvolume-name>
| EXPERIMENTAL | +| Metric name | Metric type | Description | Unit (where applicable) | Labels/tags | Status | +| ----------- | ----------- | ----------- | ----------- | ----------- | ------------ | +| kube_persistentvolume_annotations | Gauge | | | `persistentvolume`=<persistentvolume-name>
`annotation_PERSISTENTVOLUME_ANNOTATION`=<PERSISTENTVOLUME_ANNOTATION> | EXPERIMENTAL | +| kube_persistentvolume_capacity_bytes | Gauge | | | `persistentvolume`=<pv-name> | STABLE | +| kube_persistentvolume_status_phase | Gauge | | | `persistentvolume`=<pv-name>
`phase`=<Bound\|Failed\|Pending\|Available\|Released> | STABLE | +| kube_persistentvolume_claim_ref | Gauge | | | `persistentvolume`=<pv-name>
`claim_namespace`=<>
`name`=<> | STABLE | +| kube_persistentvolume_labels | Gauge | | | `persistentvolume`=<persistentvolume-name>
`label_PERSISTENTVOLUME_LABEL`=<PERSISTENTVOLUME_LABEL> | STABLE | +| kube_persistentvolume_info | Gauge | | | `persistentvolume`=<pv-name>
`storageclass`=<storageclass-name>
`gce_persistent_disk_name`=<pd-name>
`host_path`=<path-of-a-host-volume>
`host_path_type`=<host-mount-type>
`ebs_volume_id`=<ebs-volume-id>
`azure_disk_name`=<azure-disk-name>
`fc_wwids`=<fc-wwids-comma-separated>
`fc_lun`=<fc-lun>
`fc_target_wwns`=<fc-target-wwns-comma-separated>
`iscsi_target_portal`=<iscsi-target-portal>
`iscsi_iqn`=<iscsi-iqn>
`iscsi_lun`=<iscsi-lun>
`iscsi_initiator_name`=<iscsi-initiator-name>
`local_path`=<path-of-a-local-volume>
`local_fs`=<local-volume-fs-type>
`nfs_server`=<nfs-server>
`nfs_path`=<nfs-path>
`csi_driver`=<csi-driver>
`csi_volume_handle`=<csi-volume-handle> | STABLE | +| kube_persistentvolume_created | Gauge | Unix Creation Timestamp | seconds | `persistentvolume`=<persistentvolume-name>
| EXPERIMENTAL | diff --git a/internal/store/persistentvolume.go b/internal/store/persistentvolume.go index f4d8b81cb2..8354d0972e 100644 --- a/internal/store/persistentvolume.go +++ b/internal/store/persistentvolume.go @@ -164,7 +164,17 @@ func persistentVolumeMetricFamilies(allowAnnotationsList, allowLabelsList []stri metric.Gauge, "", wrapPersistentVolumeFunc(func(p *v1.PersistentVolume) *metric.Family { - var gcePDDiskName, ebsVolumeID, azureDiskName, fcWWIDs, fcLun, fcTargetWWNs, iscsiTargetPortal, iscsiIQN, iscsiLun, iscsiInitiatorName, nfsServer, nfsPath, csiDriver, csiVolumeHandle, localFS, localPath string + var ( + gcePDDiskName, + ebsVolumeID, + azureDiskName, + fcWWIDs, fcLun, fcTargetWWNs, + iscsiTargetPortal, iscsiIQN, iscsiLun, iscsiInitiatorName, + nfsServer, nfsPath, + csiDriver, csiVolumeHandle, + localFS, localPath, + hostPath, hostPathType string + ) switch { case p.Spec.PersistentVolumeSource.GCEPersistentDisk != nil: @@ -207,6 +217,11 @@ func persistentVolumeMetricFamilies(allowAnnotationsList, allowLabelsList []stri if p.Spec.PersistentVolumeSource.Local.FSType != nil { localFS = *p.Spec.PersistentVolumeSource.Local.FSType } + case p.Spec.PersistentVolumeSource.HostPath != nil: + hostPath = p.Spec.PersistentVolumeSource.HostPath.Path + if p.Spec.PersistentVolumeSource.HostPath.Type != nil { + hostPathType = string(*p.Spec.PersistentVolumeSource.HostPath.Type) + } } return &metric.Family{ @@ -230,6 +245,8 @@ func persistentVolumeMetricFamilies(allowAnnotationsList, allowLabelsList []stri "csi_volume_handle", "local_path", "local_fs", + "host_path", + "host_path_type", }, LabelValues: []string{ p.Spec.StorageClassName, @@ -249,6 +266,8 @@ func persistentVolumeMetricFamilies(allowAnnotationsList, allowLabelsList []stri csiVolumeHandle, localPath, localFS, + hostPath, + hostPathType, }, Value: 1, }, diff --git a/internal/store/persistentvolume_test.go b/internal/store/persistentvolume_test.go index 7e7450cdcf..87ee21f665 100644 --- a/internal/store/persistentvolume_test.go +++ b/internal/store/persistentvolume_test.go @@ -172,7 +172,7 @@ func TestPersistentVolumeStore(t *testing.T) { Want: ` # HELP kube_persistentvolume_info Information about persistentvolume. # TYPE kube_persistentvolume_info gauge - kube_persistentvolume_info{azure_disk_name="",ebs_volume_id="",fc_lun="",fc_target_wwns="",fc_wwids="",gce_persistent_disk_name="",iscsi_initiator_name="",iscsi_iqn="",iscsi_lun="",iscsi_target_portal="",local_path="",local_fs="",nfs_path="",nfs_server="",csi_driver="",csi_volume_handle="",persistentvolume="test-pv-available",storageclass=""} 1 + kube_persistentvolume_info{azure_disk_name="",ebs_volume_id="",fc_lun="",fc_target_wwns="",fc_wwids="",gce_persistent_disk_name="",host_path="",host_path_type="",iscsi_initiator_name="",iscsi_iqn="",iscsi_lun="",iscsi_target_portal="",local_path="",local_fs="",nfs_path="",nfs_server="",csi_driver="",csi_volume_handle="",persistentvolume="test-pv-available",storageclass=""} 1 `, MetricNames: []string{"kube_persistentvolume_info"}, }, @@ -191,7 +191,7 @@ func TestPersistentVolumeStore(t *testing.T) { Want: ` # HELP kube_persistentvolume_info Information about persistentvolume. # TYPE kube_persistentvolume_info gauge - kube_persistentvolume_info{azure_disk_name="",ebs_volume_id="",fc_lun="",fc_target_wwns="",fc_wwids="",gce_persistent_disk_name="",iscsi_initiator_name="",iscsi_iqn="",iscsi_lun="",iscsi_target_portal="",local_path="",local_fs="",nfs_path="",nfs_server="",csi_driver="",csi_volume_handle="",persistentvolume="test-pv-available",storageclass=""} 1 + kube_persistentvolume_info{azure_disk_name="",ebs_volume_id="",fc_lun="",fc_target_wwns="",fc_wwids="",gce_persistent_disk_name="",host_path="",host_path_type="",iscsi_initiator_name="",iscsi_iqn="",iscsi_lun="",iscsi_target_portal="",local_path="",local_fs="",nfs_path="",nfs_server="",csi_driver="",csi_volume_handle="",persistentvolume="test-pv-available",storageclass=""} 1 `, MetricNames: []string{"kube_persistentvolume_info"}, }, @@ -214,7 +214,7 @@ func TestPersistentVolumeStore(t *testing.T) { Want: ` # HELP kube_persistentvolume_info Information about persistentvolume. # TYPE kube_persistentvolume_info gauge - kube_persistentvolume_info{azure_disk_name="",ebs_volume_id="",fc_lun="",fc_target_wwns="",fc_wwids="",gce_persistent_disk_name="name",iscsi_initiator_name="",iscsi_iqn="",iscsi_lun="",iscsi_target_portal="",local_path="",local_fs="",nfs_path="",nfs_server="",csi_driver="",csi_volume_handle="",persistentvolume="test-pv-available",storageclass=""} 1 + kube_persistentvolume_info{azure_disk_name="",ebs_volume_id="",fc_lun="",fc_target_wwns="",fc_wwids="",gce_persistent_disk_name="name",host_path="",host_path_type="",iscsi_initiator_name="",iscsi_iqn="",iscsi_lun="",iscsi_target_portal="",local_path="",local_fs="",nfs_path="",nfs_server="",csi_driver="",csi_volume_handle="",persistentvolume="test-pv-available",storageclass=""} 1 `, MetricNames: []string{"kube_persistentvolume_info"}, }, @@ -237,7 +237,7 @@ func TestPersistentVolumeStore(t *testing.T) { Want: ` # HELP kube_persistentvolume_info Information about persistentvolume. # TYPE kube_persistentvolume_info gauge - kube_persistentvolume_info{azure_disk_name="",ebs_volume_id="aws://eu-west-1c/vol-012d34d567890123b",fc_lun="",fc_target_wwns="",fc_wwids="",gce_persistent_disk_name="",iscsi_initiator_name="",iscsi_iqn="",iscsi_lun="",iscsi_target_portal="",local_path="",local_fs="",nfs_path="",nfs_server="",csi_driver="",csi_volume_handle="",persistentvolume="test-pv-available",storageclass=""} 1 + kube_persistentvolume_info{azure_disk_name="",ebs_volume_id="aws://eu-west-1c/vol-012d34d567890123b",fc_lun="",fc_target_wwns="",fc_wwids="",gce_persistent_disk_name="",host_path="",host_path_type="",iscsi_initiator_name="",iscsi_iqn="",iscsi_lun="",iscsi_target_portal="",local_path="",local_fs="",nfs_path="",nfs_server="",csi_driver="",csi_volume_handle="",persistentvolume="test-pv-available",storageclass=""} 1 `, MetricNames: []string{"kube_persistentvolume_info"}, }, @@ -260,7 +260,7 @@ func TestPersistentVolumeStore(t *testing.T) { Want: ` # HELP kube_persistentvolume_info Information about persistentvolume. # TYPE kube_persistentvolume_info gauge - kube_persistentvolume_info{azure_disk_name="azure_disk_1",ebs_volume_id="",fc_lun="",fc_target_wwns="",fc_wwids="",gce_persistent_disk_name="",iscsi_initiator_name="",iscsi_iqn="",iscsi_lun="",iscsi_target_portal="",local_path="",local_fs="",nfs_path="",nfs_server="",csi_driver="",csi_volume_handle="",persistentvolume="test-pv-available",storageclass=""} 1 + kube_persistentvolume_info{azure_disk_name="azure_disk_1",ebs_volume_id="",fc_lun="",fc_target_wwns="",fc_wwids="",gce_persistent_disk_name="",host_path="",host_path_type="",iscsi_initiator_name="",iscsi_iqn="",iscsi_lun="",iscsi_target_portal="",local_path="",local_fs="",nfs_path="",nfs_server="",csi_driver="",csi_volume_handle="",persistentvolume="test-pv-available",storageclass=""} 1 `, MetricNames: []string{"kube_persistentvolume_info"}, }, @@ -284,7 +284,7 @@ func TestPersistentVolumeStore(t *testing.T) { Want: ` # HELP kube_persistentvolume_info Information about persistentvolume. # TYPE kube_persistentvolume_info gauge - kube_persistentvolume_info{azure_disk_name="",ebs_volume_id="",fc_lun="123",fc_target_wwns="0123456789abcdef,abcdef0123456789",fc_wwids="",gce_persistent_disk_name="",iscsi_initiator_name="",iscsi_iqn="",iscsi_lun="",iscsi_target_portal="",local_path="",local_fs="",nfs_path="",nfs_server="",csi_driver="",csi_volume_handle="",persistentvolume="test-pv-available",storageclass=""} 1 + kube_persistentvolume_info{azure_disk_name="",ebs_volume_id="",fc_lun="123",fc_target_wwns="0123456789abcdef,abcdef0123456789",fc_wwids="",gce_persistent_disk_name="",host_path="",host_path_type="",iscsi_initiator_name="",iscsi_iqn="",iscsi_lun="",iscsi_target_portal="",local_path="",local_fs="",nfs_path="",nfs_server="",csi_driver="",csi_volume_handle="",persistentvolume="test-pv-available",storageclass=""} 1 `, MetricNames: []string{"kube_persistentvolume_info"}, }, @@ -307,7 +307,7 @@ func TestPersistentVolumeStore(t *testing.T) { Want: ` # HELP kube_persistentvolume_info Information about persistentvolume. # TYPE kube_persistentvolume_info gauge - kube_persistentvolume_info{azure_disk_name="",ebs_volume_id="",fc_lun="",fc_target_wwns="",fc_wwids="0123456789abcdef,abcdef0123456789",gce_persistent_disk_name="",iscsi_initiator_name="",iscsi_iqn="",iscsi_lun="",iscsi_target_portal="",local_path="",local_fs="",nfs_path="",nfs_server="",csi_driver="",csi_volume_handle="",persistentvolume="test-pv-available",storageclass=""} 1 + kube_persistentvolume_info{azure_disk_name="",ebs_volume_id="",fc_lun="",fc_target_wwns="",fc_wwids="0123456789abcdef,abcdef0123456789",gce_persistent_disk_name="",host_path="",host_path_type="",iscsi_initiator_name="",iscsi_iqn="",iscsi_lun="",iscsi_target_portal="",local_path="",local_fs="",nfs_path="",nfs_server="",csi_driver="",csi_volume_handle="",persistentvolume="test-pv-available",storageclass=""} 1 `, MetricNames: []string{"kube_persistentvolume_info"}, }, @@ -332,7 +332,7 @@ func TestPersistentVolumeStore(t *testing.T) { Want: ` # HELP kube_persistentvolume_info Information about persistentvolume. # TYPE kube_persistentvolume_info gauge - kube_persistentvolume_info{azure_disk_name="",ebs_volume_id="",fc_lun="",fc_target_wwns="",fc_wwids="",gce_persistent_disk_name="",iscsi_initiator_name="",iscsi_iqn="iqn.my.test.server.target00",iscsi_lun="123",iscsi_target_portal="1.2.3.4:3260",local_path="",local_fs="",nfs_path="",nfs_server="",csi_driver="",csi_volume_handle="",persistentvolume="test-pv-available",storageclass=""} 1 + kube_persistentvolume_info{azure_disk_name="",ebs_volume_id="",fc_lun="",fc_target_wwns="",fc_wwids="",gce_persistent_disk_name="",host_path="",host_path_type="",iscsi_initiator_name="",iscsi_iqn="iqn.my.test.server.target00",iscsi_lun="123",iscsi_target_portal="1.2.3.4:3260",local_path="",local_fs="",nfs_path="",nfs_server="",csi_driver="",csi_volume_handle="",persistentvolume="test-pv-available",storageclass=""} 1 `, MetricNames: []string{"kube_persistentvolume_info"}, }, @@ -358,7 +358,7 @@ func TestPersistentVolumeStore(t *testing.T) { Want: ` # HELP kube_persistentvolume_info Information about persistentvolume. # TYPE kube_persistentvolume_info gauge - kube_persistentvolume_info{azure_disk_name="",ebs_volume_id="",fc_lun="",fc_target_wwns="",fc_wwids="",gce_persistent_disk_name="",iscsi_initiator_name="iqn.my.test.initiator:112233",iscsi_iqn="iqn.my.test.server.target00",iscsi_lun="123",iscsi_target_portal="1.2.3.4:3260",local_path="",local_fs="",nfs_path="",nfs_server="",csi_driver="",csi_volume_handle="",persistentvolume="test-pv-available",storageclass=""} 1 + kube_persistentvolume_info{azure_disk_name="",ebs_volume_id="",fc_lun="",fc_target_wwns="",fc_wwids="",gce_persistent_disk_name="",host_path="",host_path_type="",iscsi_initiator_name="iqn.my.test.initiator:112233",iscsi_iqn="iqn.my.test.server.target00",iscsi_lun="123",iscsi_target_portal="1.2.3.4:3260",local_path="",local_fs="",nfs_path="",nfs_server="",csi_driver="",csi_volume_handle="",persistentvolume="test-pv-available",storageclass=""} 1 `, MetricNames: []string{"kube_persistentvolume_info"}, }, @@ -382,7 +382,7 @@ func TestPersistentVolumeStore(t *testing.T) { Want: ` # HELP kube_persistentvolume_info Information about persistentvolume. # TYPE kube_persistentvolume_info gauge - kube_persistentvolume_info{azure_disk_name="",ebs_volume_id="",fc_lun="",fc_target_wwns="",fc_wwids="",gce_persistent_disk_name="",iscsi_initiator_name="",iscsi_iqn="",iscsi_lun="",iscsi_target_portal="",local_path="",local_fs="",nfs_path="/myPath",nfs_server="1.2.3.4",csi_driver="",csi_volume_handle="",persistentvolume="test-pv-available",storageclass=""} 1 + kube_persistentvolume_info{azure_disk_name="",ebs_volume_id="",fc_lun="",fc_target_wwns="",fc_wwids="",gce_persistent_disk_name="",host_path="",host_path_type="",iscsi_initiator_name="",iscsi_iqn="",iscsi_lun="",iscsi_target_portal="",local_path="",local_fs="",nfs_path="/myPath",nfs_server="1.2.3.4",csi_driver="",csi_volume_handle="",persistentvolume="test-pv-available",storageclass=""} 1 `, MetricNames: []string{"kube_persistentvolume_info"}, }, @@ -406,7 +406,7 @@ func TestPersistentVolumeStore(t *testing.T) { Want: ` # HELP kube_persistentvolume_info Information about persistentvolume. # TYPE kube_persistentvolume_info gauge - kube_persistentvolume_info{azure_disk_name="",ebs_volume_id="",fc_lun="",fc_target_wwns="",fc_wwids="",gce_persistent_disk_name="",iscsi_initiator_name="",iscsi_iqn="",iscsi_lun="",iscsi_target_portal="",local_path="",local_fs="",nfs_path="",nfs_server="",csi_driver="test-driver",csi_volume_handle="test-volume-handle",persistentvolume="test-pv-available",storageclass=""} 1 + kube_persistentvolume_info{azure_disk_name="",ebs_volume_id="",fc_lun="",fc_target_wwns="",fc_wwids="",gce_persistent_disk_name="",host_path="",host_path_type="",iscsi_initiator_name="",iscsi_iqn="",iscsi_lun="",iscsi_target_portal="",local_path="",local_fs="",nfs_path="",nfs_server="",csi_driver="test-driver",csi_volume_handle="test-volume-handle",persistentvolume="test-pv-available",storageclass=""} 1 `, MetricNames: []string{"kube_persistentvolume_info"}, }, @@ -430,7 +430,7 @@ func TestPersistentVolumeStore(t *testing.T) { Want: ` # HELP kube_persistentvolume_info Information about persistentvolume. # TYPE kube_persistentvolume_info gauge - kube_persistentvolume_info{azure_disk_name="",ebs_volume_id="",fc_lun="",fc_target_wwns="",fc_wwids="",gce_persistent_disk_name="",iscsi_initiator_name="",iscsi_iqn="",iscsi_lun="",iscsi_target_portal="",local_path="/mnt/data",local_fs="ext4",nfs_path="",nfs_server="",csi_driver="",csi_volume_handle="",persistentvolume="test-pv-available",storageclass=""} 1 + kube_persistentvolume_info{azure_disk_name="",ebs_volume_id="",fc_lun="",fc_target_wwns="",fc_wwids="",gce_persistent_disk_name="",host_path="",host_path_type="",iscsi_initiator_name="",iscsi_iqn="",iscsi_lun="",iscsi_target_portal="",local_path="/mnt/data",local_fs="ext4",nfs_path="",nfs_server="",csi_driver="",csi_volume_handle="",persistentvolume="test-pv-available",storageclass=""} 1 `, MetricNames: []string{"kube_persistentvolume_info"}, }, @@ -453,7 +453,54 @@ func TestPersistentVolumeStore(t *testing.T) { Want: ` # HELP kube_persistentvolume_info Information about persistentvolume. # TYPE kube_persistentvolume_info gauge - kube_persistentvolume_info{azure_disk_name="",ebs_volume_id="",fc_lun="",fc_target_wwns="",fc_wwids="",gce_persistent_disk_name="",iscsi_initiator_name="",iscsi_iqn="",iscsi_lun="",iscsi_target_portal="",local_path="/mnt/data",local_fs="",nfs_path="",nfs_server="",csi_driver="",csi_volume_handle="",persistentvolume="test-pv-available",storageclass=""} 1 + kube_persistentvolume_info{azure_disk_name="",ebs_volume_id="",fc_lun="",fc_target_wwns="",fc_wwids="",gce_persistent_disk_name="",host_path="",host_path_type="",iscsi_initiator_name="",iscsi_iqn="",iscsi_lun="",iscsi_target_portal="",local_path="/mnt/data",local_fs="",nfs_path="",nfs_server="",csi_driver="",csi_volume_handle="",persistentvolume="test-pv-available",storageclass=""} 1 + `, + MetricNames: []string{"kube_persistentvolume_info"}, + }, + { + Obj: &v1.PersistentVolume{ + Spec: v1.PersistentVolumeSpec{ + PersistentVolumeSource: v1.PersistentVolumeSource{ + HostPath: &v1.HostPathVolumeSource{ + Path: "/mnt/data", + Type: hostPathTypePointer(v1.HostPathDirectory), + }, + }, + }, + ObjectMeta: metav1.ObjectMeta{ + Name: "test-pv-available", + }, + Status: v1.PersistentVolumeStatus{ + Phase: v1.VolumeAvailable, + }, + }, + Want: ` + # HELP kube_persistentvolume_info Information about persistentvolume. + # TYPE kube_persistentvolume_info gauge + kube_persistentvolume_info{azure_disk_name="",ebs_volume_id="",fc_lun="",fc_target_wwns="",fc_wwids="",gce_persistent_disk_name="",host_path="/mnt/data",host_path_type="Directory",iscsi_initiator_name="",iscsi_iqn="",iscsi_lun="",iscsi_target_portal="",local_path="",local_fs="",nfs_path="",nfs_server="",csi_driver="",csi_volume_handle="",persistentvolume="test-pv-available",storageclass=""} 1 + `, + MetricNames: []string{"kube_persistentvolume_info"}, + }, + { + Obj: &v1.PersistentVolume{ + Spec: v1.PersistentVolumeSpec{ + PersistentVolumeSource: v1.PersistentVolumeSource{ + HostPath: &v1.HostPathVolumeSource{ + Path: "/mnt/data", + }, + }, + }, + ObjectMeta: metav1.ObjectMeta{ + Name: "test-pv-available", + }, + Status: v1.PersistentVolumeStatus{ + Phase: v1.VolumeAvailable, + }, + }, + Want: ` + # HELP kube_persistentvolume_info Information about persistentvolume. + # TYPE kube_persistentvolume_info gauge + kube_persistentvolume_info{azure_disk_name="",ebs_volume_id="",fc_lun="",fc_target_wwns="",fc_wwids="",gce_persistent_disk_name="",host_path="/mnt/data",host_path_type="",iscsi_initiator_name="",iscsi_iqn="",iscsi_lun="",iscsi_target_portal="",local_path="",local_fs="",nfs_path="",nfs_server="",csi_driver="",csi_volume_handle="",persistentvolume="test-pv-available",storageclass=""} 1 `, MetricNames: []string{"kube_persistentvolume_info"}, }, @@ -645,3 +692,7 @@ func TestPersistentVolumeStore(t *testing.T) { } } } + +func hostPathTypePointer(p v1.HostPathType) *v1.HostPathType { + return &p +}