@@ -23,6 +23,7 @@ import (
23
23
v1 "k8s.io/api/core/v1"
24
24
"k8s.io/apimachinery/pkg/api/resource"
25
25
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
26
+ "k8s.io/utils/pointer"
26
27
27
28
generator "k8s.io/kube-state-metrics/v2/pkg/metric_generator"
28
29
)
@@ -171,7 +172,7 @@ func TestPersistentVolumeStore(t *testing.T) {
171
172
Want : `
172
173
# HELP kube_persistentvolume_info Information about persistentvolume.
173
174
# 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
175
176
` ,
176
177
MetricNames : []string {"kube_persistentvolume_info" },
177
178
},
@@ -190,7 +191,7 @@ func TestPersistentVolumeStore(t *testing.T) {
190
191
Want : `
191
192
# HELP kube_persistentvolume_info Information about persistentvolume.
192
193
# 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
194
195
` ,
195
196
MetricNames : []string {"kube_persistentvolume_info" },
196
197
},
@@ -213,7 +214,7 @@ func TestPersistentVolumeStore(t *testing.T) {
213
214
Want : `
214
215
# HELP kube_persistentvolume_info Information about persistentvolume.
215
216
# 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
217
218
` ,
218
219
MetricNames : []string {"kube_persistentvolume_info" },
219
220
},
@@ -236,7 +237,7 @@ func TestPersistentVolumeStore(t *testing.T) {
236
237
Want : `
237
238
# HELP kube_persistentvolume_info Information about persistentvolume.
238
239
# 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
240
241
` ,
241
242
MetricNames : []string {"kube_persistentvolume_info" },
242
243
},
@@ -259,7 +260,7 @@ func TestPersistentVolumeStore(t *testing.T) {
259
260
Want : `
260
261
# HELP kube_persistentvolume_info Information about persistentvolume.
261
262
# 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
263
264
` ,
264
265
MetricNames : []string {"kube_persistentvolume_info" },
265
266
},
@@ -283,7 +284,7 @@ func TestPersistentVolumeStore(t *testing.T) {
283
284
Want : `
284
285
# HELP kube_persistentvolume_info Information about persistentvolume.
285
286
# 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
287
288
` ,
288
289
MetricNames : []string {"kube_persistentvolume_info" },
289
290
},
@@ -306,7 +307,7 @@ func TestPersistentVolumeStore(t *testing.T) {
306
307
Want : `
307
308
# HELP kube_persistentvolume_info Information about persistentvolume.
308
309
# 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
310
311
` ,
311
312
MetricNames : []string {"kube_persistentvolume_info" },
312
313
},
@@ -331,7 +332,7 @@ func TestPersistentVolumeStore(t *testing.T) {
331
332
Want : `
332
333
# HELP kube_persistentvolume_info Information about persistentvolume.
333
334
# 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
335
336
` ,
336
337
MetricNames : []string {"kube_persistentvolume_info" },
337
338
},
@@ -357,7 +358,7 @@ func TestPersistentVolumeStore(t *testing.T) {
357
358
Want : `
358
359
# HELP kube_persistentvolume_info Information about persistentvolume.
359
360
# 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
361
362
` ,
362
363
MetricNames : []string {"kube_persistentvolume_info" },
363
364
},
@@ -381,7 +382,7 @@ func TestPersistentVolumeStore(t *testing.T) {
381
382
Want : `
382
383
# HELP kube_persistentvolume_info Information about persistentvolume.
383
384
# 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
385
386
` ,
386
387
MetricNames : []string {"kube_persistentvolume_info" },
387
388
},
@@ -405,7 +406,101 @@ func TestPersistentVolumeStore(t *testing.T) {
405
406
Want : `
406
407
# HELP kube_persistentvolume_info Information about persistentvolume.
407
408
# 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
409
504
` ,
410
505
MetricNames : []string {"kube_persistentvolume_info" },
411
506
},
@@ -597,3 +692,7 @@ func TestPersistentVolumeStore(t *testing.T) {
597
692
}
598
693
}
599
694
}
695
+
696
+ func hostPathTypePointer (p v1.HostPathType ) * v1.HostPathType {
697
+ return & p
698
+ }
0 commit comments