From 2c8fe6e5933a3dad0eb658f0ac42a606ee2dd26a Mon Sep 17 00:00:00 2001 From: Jimmy K Seto Date: Thu, 17 Sep 2020 20:55:52 -0400 Subject: [PATCH] add iscsi initiator name to persistentvolume_info --- docs/persistentvolume-metrics.md | 2 +- internal/store/persistentvolume.go | 7 +++- internal/store/persistentvolume_test.go | 43 ++++++++++++++++++++----- 3 files changed, 42 insertions(+), 10 deletions(-) diff --git a/docs/persistentvolume-metrics.md b/docs/persistentvolume-metrics.md index 80eb97bc6e..e46748f296 100644 --- a/docs/persistentvolume-metrics.md +++ b/docs/persistentvolume-metrics.md @@ -5,5 +5,5 @@ | 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_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> `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>
`nfs_server`=<nfs-server>
`nfs_path`=<nfs-path> | STABLE | +| kube_persistentvolume_info | Gauge | `persistentvolume`=<pv-name>
`storageclass`=<storageclass-name>
`gce_persistent_disk_name`=<pd-name>
`ebs_volume_id`=<ebs-volume-id>
`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> | STABLE | diff --git a/internal/store/persistentvolume.go b/internal/store/persistentvolume.go index 7a0828fcf5..82dfa6b716 100644 --- a/internal/store/persistentvolume.go +++ b/internal/store/persistentvolume.go @@ -108,7 +108,7 @@ var ( metric.Gauge, "", wrapPersistentVolumeFunc(func(p *v1.PersistentVolume) *metric.Family { - var gcePDDiskName, ebsVolumeID, fcWWIDs, fcLun, fcTargetWWNs, iscsiTargetPortal, iscsiIQN, iscsiLun, nfsServer, nfsPath string + var gcePDDiskName, ebsVolumeID, fcWWIDs, fcLun, fcTargetWWNs, iscsiTargetPortal, iscsiIQN, iscsiLun, iscsiInitiatorName, nfsServer, nfsPath string switch { case p.Spec.PersistentVolumeSource.GCEPersistentDisk != nil: @@ -135,6 +135,9 @@ var ( iscsiTargetPortal = p.Spec.PersistentVolumeSource.ISCSI.TargetPortal iscsiIQN = p.Spec.PersistentVolumeSource.ISCSI.IQN iscsiLun = strconv.FormatInt(int64(p.Spec.PersistentVolumeSource.ISCSI.Lun), 10) + if p.Spec.PersistentVolumeSource.ISCSI.InitiatorName != nil { + iscsiInitiatorName = *p.Spec.PersistentVolumeSource.ISCSI.InitiatorName + } case p.Spec.PersistentVolumeSource.NFS != nil: nfsServer = p.Spec.PersistentVolumeSource.NFS.Server nfsPath = p.Spec.PersistentVolumeSource.NFS.Path @@ -153,6 +156,7 @@ var ( "iscsi_target_portal", "iscsi_iqn", "iscsi_lun", + "iscsi_initiator_name", "nfs_server", "nfs_path", }, @@ -166,6 +170,7 @@ var ( iscsiTargetPortal, iscsiIQN, iscsiLun, + iscsiInitiatorName, nfsServer, nfsPath, }, diff --git a/internal/store/persistentvolume_test.go b/internal/store/persistentvolume_test.go index e079185e72..f2d6b475c1 100644 --- a/internal/store/persistentvolume_test.go +++ b/internal/store/persistentvolume_test.go @@ -27,6 +27,7 @@ import ( ) func TestPersistentVolumeStore(t *testing.T) { + iscsiInitiatorName := "iqn.my.test.initiator:112233" cases := []generateMetricsTestCase{ // Verify phase enumerations. { @@ -169,7 +170,7 @@ func TestPersistentVolumeStore(t *testing.T) { Want: ` # HELP kube_persistentvolume_info Information about persistentvolume. # TYPE kube_persistentvolume_info gauge - kube_persistentvolume_info{ebs_volume_id="",fc_lun="",fc_target_wwns="",fc_wwids="",gce_persistent_disk_name="",iscsi_iqn="",iscsi_lun="",iscsi_target_portal="",nfs_path="",nfs_server="",persistentvolume="test-pv-available",storageclass=""} 1 + kube_persistentvolume_info{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="",persistentvolume="test-pv-available",storageclass=""} 1 `, MetricNames: []string{"kube_persistentvolume_info"}, }, @@ -188,7 +189,7 @@ func TestPersistentVolumeStore(t *testing.T) { Want: ` # HELP kube_persistentvolume_info Information about persistentvolume. # TYPE kube_persistentvolume_info gauge - kube_persistentvolume_info{ebs_volume_id="",fc_lun="",fc_target_wwns="",fc_wwids="",gce_persistent_disk_name="",iscsi_iqn="",iscsi_lun="",iscsi_target_portal="",nfs_path="",nfs_server="",persistentvolume="test-pv-available",storageclass=""} 1 + kube_persistentvolume_info{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="",persistentvolume="test-pv-available",storageclass=""} 1 `, MetricNames: []string{"kube_persistentvolume_info"}, }, @@ -211,7 +212,7 @@ func TestPersistentVolumeStore(t *testing.T) { Want: ` # HELP kube_persistentvolume_info Information about persistentvolume. # TYPE kube_persistentvolume_info gauge - kube_persistentvolume_info{ebs_volume_id="",fc_lun="",fc_target_wwns="",fc_wwids="",gce_persistent_disk_name="name",iscsi_iqn="",iscsi_lun="",iscsi_target_portal="",nfs_path="",nfs_server="",persistentvolume="test-pv-available",storageclass=""} 1 + kube_persistentvolume_info{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="",persistentvolume="test-pv-available",storageclass=""} 1 `, MetricNames: []string{"kube_persistentvolume_info"}, }, @@ -234,7 +235,7 @@ func TestPersistentVolumeStore(t *testing.T) { Want: ` # HELP kube_persistentvolume_info Information about persistentvolume. # TYPE kube_persistentvolume_info gauge - kube_persistentvolume_info{ebs_volume_id="aws://eu-west-1c/vol-012d34d567890123b",fc_lun="",fc_target_wwns="",fc_wwids="",gce_persistent_disk_name="",iscsi_iqn="",iscsi_lun="",iscsi_target_portal="",nfs_path="",nfs_server="",persistentvolume="test-pv-available",storageclass=""} 1 + kube_persistentvolume_info{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="",persistentvolume="test-pv-available",storageclass=""} 1 `, MetricNames: []string{"kube_persistentvolume_info"}, }, @@ -258,7 +259,7 @@ func TestPersistentVolumeStore(t *testing.T) { Want: ` # HELP kube_persistentvolume_info Information about persistentvolume. # TYPE kube_persistentvolume_info gauge - kube_persistentvolume_info{ebs_volume_id="",fc_lun="123",fc_target_wwns="0123456789abcdef,abcdef0123456789",fc_wwids="",gce_persistent_disk_name="",iscsi_iqn="",iscsi_lun="",iscsi_target_portal="",nfs_path="",nfs_server="",persistentvolume="test-pv-available",storageclass=""} 1 + kube_persistentvolume_info{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="",persistentvolume="test-pv-available",storageclass=""} 1 `, MetricNames: []string{"kube_persistentvolume_info"}, }, @@ -281,7 +282,7 @@ func TestPersistentVolumeStore(t *testing.T) { Want: ` # HELP kube_persistentvolume_info Information about persistentvolume. # TYPE kube_persistentvolume_info gauge - kube_persistentvolume_info{ebs_volume_id="",fc_lun="",fc_target_wwns="",fc_wwids="0123456789abcdef,abcdef0123456789",gce_persistent_disk_name="",iscsi_iqn="",iscsi_lun="",iscsi_target_portal="",nfs_path="",nfs_server="",persistentvolume="test-pv-available",storageclass=""} 1 + kube_persistentvolume_info{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="",persistentvolume="test-pv-available",storageclass=""} 1 `, MetricNames: []string{"kube_persistentvolume_info"}, }, @@ -306,7 +307,33 @@ func TestPersistentVolumeStore(t *testing.T) { Want: ` # HELP kube_persistentvolume_info Information about persistentvolume. # TYPE kube_persistentvolume_info gauge - kube_persistentvolume_info{ebs_volume_id="",fc_lun="",fc_target_wwns="",fc_wwids="",gce_persistent_disk_name="",iscsi_iqn="iqn.my.test.server.target00",iscsi_lun="123",iscsi_target_portal="1.2.3.4:3260",nfs_path="",nfs_server="",persistentvolume="test-pv-available",storageclass=""} 1 + kube_persistentvolume_info{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="",persistentvolume="test-pv-available",storageclass=""} 1 + `, + MetricNames: []string{"kube_persistentvolume_info"}, + }, + { + Obj: &v1.PersistentVolume{ + Spec: v1.PersistentVolumeSpec{ + PersistentVolumeSource: v1.PersistentVolumeSource{ + ISCSI: &v1.ISCSIPersistentVolumeSource{ + TargetPortal: "1.2.3.4:3260", + IQN: "iqn.my.test.server.target00", + Lun: int32(123), + InitiatorName: &iscsiInitiatorName, + }, + }, + }, + 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{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="",persistentvolume="test-pv-available",storageclass=""} 1 `, MetricNames: []string{"kube_persistentvolume_info"}, }, @@ -330,7 +357,7 @@ func TestPersistentVolumeStore(t *testing.T) { Want: ` # HELP kube_persistentvolume_info Information about persistentvolume. # TYPE kube_persistentvolume_info gauge - kube_persistentvolume_info{ebs_volume_id="",fc_lun="",fc_target_wwns="",fc_wwids="",gce_persistent_disk_name="",iscsi_iqn="",iscsi_lun="",iscsi_target_portal="",nfs_path="/myPath",nfs_server="1.2.3.4",persistentvolume="test-pv-available",storageclass=""} 1 + kube_persistentvolume_info{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",persistentvolume="test-pv-available",storageclass=""} 1 `, MetricNames: []string{"kube_persistentvolume_info"}, },