Prevent segfault in persistent volume claims (#9549)
This commit is contained in:
parent
5843b27d75
commit
fdec5f1f31
|
|
@ -39,11 +39,13 @@ func (ki *KubernetesInventory) gatherPersistentVolumeClaim(pvc corev1.Persistent
|
||||||
"phase": string(pvc.Status.Phase),
|
"phase": string(pvc.Status.Phase),
|
||||||
"storageclass": *pvc.Spec.StorageClassName,
|
"storageclass": *pvc.Spec.StorageClassName,
|
||||||
}
|
}
|
||||||
|
if pvc.Spec.Selector != nil {
|
||||||
for key, val := range pvc.Spec.Selector.MatchLabels {
|
for key, val := range pvc.Spec.Selector.MatchLabels {
|
||||||
if ki.selectorFilter.Match(key) {
|
if ki.selectorFilter.Match(key) {
|
||||||
tags["selector_"+key] = val
|
tags["selector_"+key] = val
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
acc.AddFields(persistentVolumeClaimMeasurement, fields, tags)
|
acc.AddFields(persistentVolumeClaimMeasurement, fields, tags)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -88,6 +88,52 @@ func TestPersistentVolumeClaim(t *testing.T) {
|
||||||
},
|
},
|
||||||
hasError: false,
|
hasError: false,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "no label selectors",
|
||||||
|
hasError: false,
|
||||||
|
handler: &mockHandler{
|
||||||
|
responseMap: map[string]interface{}{
|
||||||
|
"/persistentvolumeclaims/": &corev1.PersistentVolumeClaimList{
|
||||||
|
Items: []corev1.PersistentVolumeClaim{
|
||||||
|
{
|
||||||
|
Status: corev1.PersistentVolumeClaimStatus{
|
||||||
|
Phase: "bound",
|
||||||
|
},
|
||||||
|
Spec: corev1.PersistentVolumeClaimSpec{
|
||||||
|
VolumeName: "pvc-dc870fd6-1e08-11e8-b226-02aa4bc06eb8",
|
||||||
|
StorageClassName: toStrPtr("ebs-1"),
|
||||||
|
Selector: nil,
|
||||||
|
},
|
||||||
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
|
Namespace: "ns1",
|
||||||
|
Name: "pc1",
|
||||||
|
Labels: map[string]string{
|
||||||
|
"lab1": "v1",
|
||||||
|
"lab2": "v2",
|
||||||
|
},
|
||||||
|
CreationTimestamp: metav1.Time{Time: now},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
output: []telegraf.Metric{
|
||||||
|
testutil.MustMetric(
|
||||||
|
"kubernetes_persistentvolumeclaim",
|
||||||
|
map[string]string{
|
||||||
|
"pvc_name": "pc1",
|
||||||
|
"namespace": "ns1",
|
||||||
|
"storageclass": "ebs-1",
|
||||||
|
"phase": "bound",
|
||||||
|
},
|
||||||
|
map[string]interface{}{
|
||||||
|
"phase_type": 0,
|
||||||
|
},
|
||||||
|
time.Unix(0, 0),
|
||||||
|
),
|
||||||
|
},
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, v := range tests {
|
for _, v := range tests {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue