Skip to content

Commit ebc0e18

Browse files
authored
Merge pull request #1814 from nabokihms/local-storage-labels
feat: Add local storage labels to kube_persistentvolume_info
2 parents 6dfeab3 + 9e639b2 commit ebc0e18

File tree

3 files changed

+140
-13
lines changed

3 files changed

+140
-13
lines changed

docs/persistentvolume-metrics.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@
77
| kube_persistentvolume_status_phase | Gauge | | | `persistentvolume`=&lt;pv-name&gt; <br>`phase`=&lt;Bound\|Failed\|Pending\|Available\|Released&gt; | STABLE |
88
| kube_persistentvolume_claim_ref | Gauge | | | `persistentvolume`=&lt;pv-name&gt; <br>`claim_namespace`=&lt;<namespace>&gt; <br>`name`=&lt;<name>&gt; | STABLE |
99
| kube_persistentvolume_labels | Gauge | | | `persistentvolume`=&lt;persistentvolume-name&gt; <br> `label_PERSISTENTVOLUME_LABEL`=&lt;PERSISTENTVOLUME_LABEL&gt; | STABLE |
10-
| kube_persistentvolume_info | Gauge | | | `persistentvolume`=&lt;pv-name&gt; <br> `storageclass`=&lt;storageclass-name&gt; <br> `gce_persistent_disk_name`=&lt;pd-name&gt; <br> `ebs_volume_id`=&lt;ebs-volume-id&gt; <br> `azure_disk_name`=&lt;azure-disk-name&gt; <br> `fc_wwids`=&lt;fc-wwids-comma-separated&gt; <br> `fc_lun`=&lt;fc-lun&gt; <br> `fc_target_wwns`=&lt;fc-target-wwns-comma-separated&gt; <br> `iscsi_target_portal`=&lt;iscsi-target-portal&gt; <br> `iscsi_iqn`=&lt;iscsi-iqn&gt; <br> `iscsi_lun`=&lt;iscsi-lun&gt; <br> `iscsi_initiator_name`=&lt;iscsi-initiator-name&gt; <br> `nfs_server`=&lt;nfs-server&gt; <br> `nfs_path`=&lt;nfs-path&gt; <br> `csi_driver`=&lt;csi-driver&gt; <br> `csi_volume_handle`=&lt;csi-volume-handle&gt; | STABLE |
10+
| kube_persistentvolume_info | Gauge | | | `persistentvolume`=&lt;pv-name&gt; <br> `storageclass`=&lt;storageclass-name&gt; <br> `gce_persistent_disk_name`=&lt;pd-name&gt; <br> `host_path`=&lt;path-of-a-host-volume&gt; <br> `host_path_type`=&lt;host-mount-type&gt; <br> `ebs_volume_id`=&lt;ebs-volume-id&gt; <br> `azure_disk_name`=&lt;azure-disk-name&gt; <br> `fc_wwids`=&lt;fc-wwids-comma-separated&gt; <br> `fc_lun`=&lt;fc-lun&gt; <br> `fc_target_wwns`=&lt;fc-target-wwns-comma-separated&gt; <br> `iscsi_target_portal`=&lt;iscsi-target-portal&gt; <br> `iscsi_iqn`=&lt;iscsi-iqn&gt; <br> `iscsi_lun`=&lt;iscsi-lun&gt; <br> `iscsi_initiator_name`=&lt;iscsi-initiator-name&gt; <br> `local_path`=&lt;path-of-a-local-volume&gt; <br> `local_fs`=&lt;local-volume-fs-type&gt; <br> `nfs_server`=&lt;nfs-server&gt; <br> `nfs_path`=&lt;nfs-path&gt; <br> `csi_driver`=&lt;csi-driver&gt; <br> `csi_volume_handle`=&lt;csi-volume-handle&gt; | STABLE |
1111
| kube_persistentvolume_created | Gauge | Unix Creation Timestamp | seconds | `persistentvolume`=&lt;persistentvolume-name&gt; <br> | EXPERIMENTAL |
1212

internal/store/persistentvolume.go

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,17 @@ func persistentVolumeMetricFamilies(allowAnnotationsList, allowLabelsList []stri
164164
metric.Gauge,
165165
"",
166166
wrapPersistentVolumeFunc(func(p *v1.PersistentVolume) *metric.Family {
167-
var gcePDDiskName, ebsVolumeID, azureDiskName, fcWWIDs, fcLun, fcTargetWWNs, iscsiTargetPortal, iscsiIQN, iscsiLun, iscsiInitiatorName, nfsServer, nfsPath, csiDriver, csiVolumeHandle string
167+
var (
168+
gcePDDiskName,
169+
ebsVolumeID,
170+
azureDiskName,
171+
fcWWIDs, fcLun, fcTargetWWNs,
172+
iscsiTargetPortal, iscsiIQN, iscsiLun, iscsiInitiatorName,
173+
nfsServer, nfsPath,
174+
csiDriver, csiVolumeHandle,
175+
localFS, localPath,
176+
hostPath, hostPathType string
177+
)
168178

169179
switch {
170180
case p.Spec.PersistentVolumeSource.GCEPersistentDisk != nil:
@@ -202,6 +212,16 @@ func persistentVolumeMetricFamilies(allowAnnotationsList, allowLabelsList []stri
202212
case p.Spec.PersistentVolumeSource.CSI != nil:
203213
csiDriver = p.Spec.PersistentVolumeSource.CSI.Driver
204214
csiVolumeHandle = p.Spec.PersistentVolumeSource.CSI.VolumeHandle
215+
case p.Spec.PersistentVolumeSource.Local != nil:
216+
localPath = p.Spec.PersistentVolumeSource.Local.Path
217+
if p.Spec.PersistentVolumeSource.Local.FSType != nil {
218+
localFS = *p.Spec.PersistentVolumeSource.Local.FSType
219+
}
220+
case p.Spec.PersistentVolumeSource.HostPath != nil:
221+
hostPath = p.Spec.PersistentVolumeSource.HostPath.Path
222+
if p.Spec.PersistentVolumeSource.HostPath.Type != nil {
223+
hostPathType = string(*p.Spec.PersistentVolumeSource.HostPath.Type)
224+
}
205225
}
206226

207227
return &metric.Family{
@@ -223,6 +243,10 @@ func persistentVolumeMetricFamilies(allowAnnotationsList, allowLabelsList []stri
223243
"nfs_path",
224244
"csi_driver",
225245
"csi_volume_handle",
246+
"local_path",
247+
"local_fs",
248+
"host_path",
249+
"host_path_type",
226250
},
227251
LabelValues: []string{
228252
p.Spec.StorageClassName,
@@ -240,6 +264,10 @@ func persistentVolumeMetricFamilies(allowAnnotationsList, allowLabelsList []stri
240264
nfsPath,
241265
csiDriver,
242266
csiVolumeHandle,
267+
localPath,
268+
localFS,
269+
hostPath,
270+
hostPathType,
243271
},
244272
Value: 1,
245273
},

internal/store/persistentvolume_test.go

Lines changed: 110 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
v1 "k8s.io/api/core/v1"
2424
"k8s.io/apimachinery/pkg/api/resource"
2525
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
26+
"k8s.io/utils/pointer"
2627

2728
generator "k8s.io/kube-state-metrics/v2/pkg/metric_generator"
2829
)
@@ -171,7 +172,7 @@ func TestPersistentVolumeStore(t *testing.T) {
171172
Want: `
172173
# HELP kube_persistentvolume_info Information about persistentvolume.
173174
# TYPE kube_persistentvolume_info gauge
174-
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
175+
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
175176
`,
176177
MetricNames: []string{"kube_persistentvolume_info"},
177178
},
@@ -190,7 +191,7 @@ func TestPersistentVolumeStore(t *testing.T) {
190191
Want: `
191192
# HELP kube_persistentvolume_info Information about persistentvolume.
192193
# TYPE kube_persistentvolume_info gauge
193-
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
194+
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
194195
`,
195196
MetricNames: []string{"kube_persistentvolume_info"},
196197
},
@@ -213,7 +214,7 @@ func TestPersistentVolumeStore(t *testing.T) {
213214
Want: `
214215
# HELP kube_persistentvolume_info Information about persistentvolume.
215216
# TYPE kube_persistentvolume_info gauge
216-
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
217+
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
217218
`,
218219
MetricNames: []string{"kube_persistentvolume_info"},
219220
},
@@ -236,7 +237,7 @@ func TestPersistentVolumeStore(t *testing.T) {
236237
Want: `
237238
# HELP kube_persistentvolume_info Information about persistentvolume.
238239
# TYPE kube_persistentvolume_info gauge
239-
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
240+
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
240241
`,
241242
MetricNames: []string{"kube_persistentvolume_info"},
242243
},
@@ -259,7 +260,7 @@ func TestPersistentVolumeStore(t *testing.T) {
259260
Want: `
260261
# HELP kube_persistentvolume_info Information about persistentvolume.
261262
# TYPE kube_persistentvolume_info gauge
262-
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
263+
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
263264
`,
264265
MetricNames: []string{"kube_persistentvolume_info"},
265266
},
@@ -283,7 +284,7 @@ func TestPersistentVolumeStore(t *testing.T) {
283284
Want: `
284285
# HELP kube_persistentvolume_info Information about persistentvolume.
285286
# TYPE kube_persistentvolume_info gauge
286-
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
287+
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
287288
`,
288289
MetricNames: []string{"kube_persistentvolume_info"},
289290
},
@@ -306,7 +307,7 @@ func TestPersistentVolumeStore(t *testing.T) {
306307
Want: `
307308
# HELP kube_persistentvolume_info Information about persistentvolume.
308309
# TYPE kube_persistentvolume_info gauge
309-
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
310+
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
310311
`,
311312
MetricNames: []string{"kube_persistentvolume_info"},
312313
},
@@ -331,7 +332,7 @@ func TestPersistentVolumeStore(t *testing.T) {
331332
Want: `
332333
# HELP kube_persistentvolume_info Information about persistentvolume.
333334
# TYPE kube_persistentvolume_info gauge
334-
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
335+
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
335336
`,
336337
MetricNames: []string{"kube_persistentvolume_info"},
337338
},
@@ -357,7 +358,7 @@ func TestPersistentVolumeStore(t *testing.T) {
357358
Want: `
358359
# HELP kube_persistentvolume_info Information about persistentvolume.
359360
# TYPE kube_persistentvolume_info gauge
360-
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
361+
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
361362
`,
362363
MetricNames: []string{"kube_persistentvolume_info"},
363364
},
@@ -381,7 +382,7 @@ func TestPersistentVolumeStore(t *testing.T) {
381382
Want: `
382383
# HELP kube_persistentvolume_info Information about persistentvolume.
383384
# TYPE kube_persistentvolume_info gauge
384-
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
385+
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
385386
`,
386387
MetricNames: []string{"kube_persistentvolume_info"},
387388
},
@@ -405,7 +406,101 @@ func TestPersistentVolumeStore(t *testing.T) {
405406
Want: `
406407
# HELP kube_persistentvolume_info Information about persistentvolume.
407408
# TYPE kube_persistentvolume_info gauge
408-
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
409+
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
410+
`,
411+
MetricNames: []string{"kube_persistentvolume_info"},
412+
},
413+
{
414+
Obj: &v1.PersistentVolume{
415+
Spec: v1.PersistentVolumeSpec{
416+
PersistentVolumeSource: v1.PersistentVolumeSource{
417+
Local: &v1.LocalVolumeSource{
418+
FSType: pointer.String("ext4"),
419+
Path: "/mnt/data",
420+
},
421+
},
422+
},
423+
ObjectMeta: metav1.ObjectMeta{
424+
Name: "test-pv-available",
425+
},
426+
Status: v1.PersistentVolumeStatus{
427+
Phase: v1.VolumeAvailable,
428+
},
429+
},
430+
Want: `
431+
# HELP kube_persistentvolume_info Information about persistentvolume.
432+
# TYPE kube_persistentvolume_info gauge
433+
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
434+
`,
435+
MetricNames: []string{"kube_persistentvolume_info"},
436+
},
437+
{
438+
Obj: &v1.PersistentVolume{
439+
Spec: v1.PersistentVolumeSpec{
440+
PersistentVolumeSource: v1.PersistentVolumeSource{
441+
Local: &v1.LocalVolumeSource{
442+
Path: "/mnt/data",
443+
},
444+
},
445+
},
446+
ObjectMeta: metav1.ObjectMeta{
447+
Name: "test-pv-available",
448+
},
449+
Status: v1.PersistentVolumeStatus{
450+
Phase: v1.VolumeAvailable,
451+
},
452+
},
453+
Want: `
454+
# HELP kube_persistentvolume_info Information about persistentvolume.
455+
# TYPE kube_persistentvolume_info gauge
456+
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
457+
`,
458+
MetricNames: []string{"kube_persistentvolume_info"},
459+
},
460+
{
461+
Obj: &v1.PersistentVolume{
462+
Spec: v1.PersistentVolumeSpec{
463+
PersistentVolumeSource: v1.PersistentVolumeSource{
464+
HostPath: &v1.HostPathVolumeSource{
465+
Path: "/mnt/data",
466+
Type: hostPathTypePointer(v1.HostPathDirectory),
467+
},
468+
},
469+
},
470+
ObjectMeta: metav1.ObjectMeta{
471+
Name: "test-pv-available",
472+
},
473+
Status: v1.PersistentVolumeStatus{
474+
Phase: v1.VolumeAvailable,
475+
},
476+
},
477+
Want: `
478+
# HELP kube_persistentvolume_info Information about persistentvolume.
479+
# TYPE kube_persistentvolume_info gauge
480+
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
481+
`,
482+
MetricNames: []string{"kube_persistentvolume_info"},
483+
},
484+
{
485+
Obj: &v1.PersistentVolume{
486+
Spec: v1.PersistentVolumeSpec{
487+
PersistentVolumeSource: v1.PersistentVolumeSource{
488+
HostPath: &v1.HostPathVolumeSource{
489+
Path: "/mnt/data",
490+
},
491+
},
492+
},
493+
ObjectMeta: metav1.ObjectMeta{
494+
Name: "test-pv-available",
495+
},
496+
Status: v1.PersistentVolumeStatus{
497+
Phase: v1.VolumeAvailable,
498+
},
499+
},
500+
Want: `
501+
# HELP kube_persistentvolume_info Information about persistentvolume.
502+
# TYPE kube_persistentvolume_info gauge
503+
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
409504
`,
410505
MetricNames: []string{"kube_persistentvolume_info"},
411506
},
@@ -597,3 +692,7 @@ func TestPersistentVolumeStore(t *testing.T) {
597692
}
598693
}
599694
}
695+
696+
func hostPathTypePointer(p v1.HostPathType) *v1.HostPathType {
697+
return &p
698+
}

0 commit comments

Comments
 (0)