forked from kubevirt/ssp-operator
/
rbd_metrics.go
59 lines (49 loc) · 1.92 KB
/
rbd_metrics.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package metrics
import (
"strings"
"github.com/machadovilaca/operator-observability/pkg/operatormetrics"
k8sv1 "k8s.io/api/core/v1"
kubevirtv1 "kubevirt.io/api/core/v1"
)
var (
rbdMetrics = []operatormetrics.Metric{
vmRbdVolume,
}
vmRbdVolume = operatormetrics.NewGaugeVec(
operatormetrics.MetricOpts{
Name: metricPrefix + "vm_rbd_block_volume_without_rxbounce",
Help: "VM with RBD mounted Block volume (without rxbounce option set)",
ExtraFields: map[string]string{
"StabilityLevel": "ALPHA",
},
},
[]string{"name", "namespace"},
)
)
func SetVmWithVolume(vm *kubevirtv1.VirtualMachine, pvc *k8sv1.PersistentVolumeClaim, pv *k8sv1.PersistentVolume) {
if pv == nil || pvc == nil {
vmRbdVolume.WithLabelValues(vm.Name, vm.Namespace).Set(0)
return
}
// If the volume is not using the RBD CSI driver, or if it is not using the block mode, it is not impacted by https://bugzilla.redhat.com/2109455
if !usesRbdCsiDriver(pv) || *pvc.Spec.VolumeMode != k8sv1.PersistentVolumeBlock {
vmRbdVolume.WithLabelValues(vm.Name, vm.Namespace).Set(0)
return
}
mounter, ok := pv.Spec.PersistentVolumeSource.CSI.VolumeAttributes["mounter"]
// If mounter is not set, it is using the default mounter, which is "rbd"
if ok && mounter != "rbd" {
vmRbdVolume.WithLabelValues(vm.Name, vm.Namespace).Set(0)
return
}
rxbounce, ok := pv.Spec.PersistentVolumeSource.CSI.VolumeAttributes["mapOptions"]
// If mapOptions is not set, or if it is set but does not contain "krbd:rxbounce", it might be impacted by https://bugzilla.redhat.com/2109455
if !ok || !strings.Contains(rxbounce, "krbd:rxbounce") {
vmRbdVolume.WithLabelValues(vm.Name, vm.Namespace).Set(1)
return
}
vmRbdVolume.WithLabelValues(vm.Name, vm.Namespace).Set(0)
}
func usesRbdCsiDriver(pv *k8sv1.PersistentVolume) bool {
return pv.Spec.PersistentVolumeSource.CSI != nil && strings.Contains(pv.Spec.PersistentVolumeSource.CSI.Driver, "rbd.csi.ceph.com")
}