• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

kubeovn / kube-ovn / 19527788804

20 Nov 2025 06:25AM UTC coverage: 21.99% (+0.08%) from 21.909%
19527788804

Pull #5543

github

zbb88888
fix: 使用 any 替换 interface{} (Go 1.18+)

- 修复 golangci-lint modernize 检查
- 在 subnet_bigint_test.go 中替换 3 处 interface{}
- 在 subnet_bigint_e2e_test.go 中替换 4 处 interface{}
- 保持测试逻辑不变

Signed-off-by: zbb88888 <jmdxjsjgcxy@gmail.com>
Pull Request #5543: Controller gen

66 of 123 new or added lines in 9 files covered. (53.66%)

2 existing lines in 1 file now uncovered.

11187 of 50873 relevant lines covered (21.99%)

0.26 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/pkg/controller/exporter.go
1
package controller
2

3
import (
4
        "math"
5
        "strconv"
6
        "strings"
7
        "sync"
8

9
        "k8s.io/apimachinery/pkg/labels"
10
        "k8s.io/klog/v2"
11

12
        kubeovnv1 "github.com/kubeovn/kube-ovn/pkg/apis/kubeovn/v1"
13
        "github.com/kubeovn/kube-ovn/pkg/ovsdb/ovnnb"
14
)
15

16
var registerMetricsOnce sync.Once
17

18
// registerSubnetMetrics register subnet metrics
19
func (c *Controller) registerSubnetMetrics() {
×
20
        registerMetricsOnce.Do(func() {
×
21
                registerMetrics()
×
22
        })
×
23
}
24

25
func resetSubnetMetrics() {
×
26
        metricSubnetAvailableIPs.Reset()
×
27
        metricSubnetUsedIPs.Reset()
×
28
        metricCentralSubnetInfo.Reset()
×
29
        metricSubnetIPAMInfo.Reset()
×
30
        metricSubnetIPAssignedInfo.Reset()
×
31
}
×
32

33
func (c *Controller) exportSubnetMetrics() {
×
34
        subnets, err := c.subnetsLister.List(labels.Everything())
×
35
        if err != nil {
×
36
                klog.Errorf("failed to list subnet, %v", err)
×
37
                return
×
38
        }
×
39

40
        resetSubnetMetrics()
×
41
        for _, subnet := range subnets {
×
42
                if !subnet.Status.IsValidated() {
×
43
                        continue
×
44
                }
45

46
                c.exportSubnetAvailableIPsGauge(subnet)
×
47
                c.exportSubnetUsedIPsGauge(subnet)
×
48
                c.exportSubnetIPAMInfo(subnet)
×
49
                c.exportSubnetIPAssignedInfo(subnet)
×
50

×
51
                if subnet.Spec.GatewayType == kubeovnv1.GWCentralizedType {
×
52
                        c.exportCentralizedSubnetInfo(subnet)
×
53
                }
×
54
        }
55
}
56

57
func (c *Controller) exportSubnetAvailableIPsGauge(subnet *kubeovnv1.Subnet) {
×
58
        var availableIPs float64
×
59
        switch subnet.Spec.Protocol {
×
60
        case kubeovnv1.ProtocolIPv4:
×
NEW
61
                availableIPs = subnet.Status.V4AvailableIPs.Float64()
×
62
        case kubeovnv1.ProtocolIPv6:
×
NEW
63
                availableIPs = subnet.Status.V6AvailableIPs.Float64()
×
64
        default:
×
NEW
65
                availableIPs = math.Min(subnet.Status.V4AvailableIPs.Float64(), subnet.Status.V6AvailableIPs.Float64())
×
66
        }
67
        metricSubnetAvailableIPs.WithLabelValues(subnet.Name, subnet.Spec.Protocol, subnet.Spec.CIDRBlock).Set(availableIPs)
×
68
}
69

70
func (c *Controller) exportSubnetUsedIPsGauge(subnet *kubeovnv1.Subnet) {
×
71
        var usingIPs float64
×
72
        if subnet.Spec.Protocol == kubeovnv1.ProtocolIPv6 {
×
NEW
73
                usingIPs = subnet.Status.V6UsingIPs.Float64()
×
74
        } else {
×
NEW
75
                usingIPs = subnet.Status.V4UsingIPs.Float64()
×
76
        }
×
77
        metricSubnetUsedIPs.WithLabelValues(subnet.Name, subnet.Spec.Protocol, subnet.Spec.CIDRBlock).Set(usingIPs)
×
78
}
79

80
func (c *Controller) exportCentralizedSubnetInfo(subnet *kubeovnv1.Subnet) {
×
81
        lrPolicyList, err := c.OVNNbClient.GetLogicalRouterPoliciesByExtID(c.config.ClusterRouter, "subnet", subnet.Name)
×
82
        if err != nil {
×
83
                klog.Errorf("failed to list lr policy for subnet %s: %v", subnet.Name, err)
×
84
                return
×
85
        }
×
86

87
        for _, lrPolicy := range lrPolicyList {
×
88
                if lrPolicy.Action == ovnnb.LogicalRouterPolicyActionReroute {
×
89
                        metricCentralSubnetInfo.WithLabelValues(subnet.Name, strconv.FormatBool(subnet.Spec.EnableEcmp), subnet.Spec.GatewayNode, subnet.Status.ActivateGateway, lrPolicy.Match, strings.Join(lrPolicy.Nexthops, ",")).Set(1)
×
90
                        break
×
91
                }
92
        }
93
}
94

95
func (c *Controller) exportSubnetIPAMInfo(subnet *kubeovnv1.Subnet) {
×
96
        ipamSubnet, ok := c.ipam.Subnets[subnet.Name]
×
97
        if !ok {
×
98
                klog.Errorf("failed to get subnet %s in ipam", subnet.Name)
×
99
                return
×
100
        }
×
101

102
        ipamSubnet.Mutex.RLock()
×
103
        defer ipamSubnet.Mutex.RUnlock()
×
104

×
105
        switch subnet.Spec.Protocol {
×
106
        case kubeovnv1.ProtocolIPv4:
×
107
                metricSubnetIPAMInfo.WithLabelValues(subnet.Name, subnet.Spec.CIDRBlock, ipamSubnet.V4Free.String(), ipamSubnet.V4Reserved.String(), ipamSubnet.V4Available.String(), ipamSubnet.V4Using.String()).Set(1)
×
108

109
        case kubeovnv1.ProtocolIPv6:
×
110
                metricSubnetIPAMInfo.WithLabelValues(subnet.Name, subnet.Spec.CIDRBlock, ipamSubnet.V6Free.String(), ipamSubnet.V6Reserved.String(), ipamSubnet.V6Available.String(), ipamSubnet.V6Using.String()).Set(1)
×
111

112
        case kubeovnv1.ProtocolDual:
×
113
                metricSubnetIPAMInfo.WithLabelValues(subnet.Name, subnet.Spec.CIDRBlock, ipamSubnet.V4Free.String(), ipamSubnet.V4Reserved.String(), ipamSubnet.V4Available.String(), ipamSubnet.V4Using.String()).Set(1)
×
114
                metricSubnetIPAMInfo.WithLabelValues(subnet.Name, subnet.Spec.CIDRBlock, ipamSubnet.V6Free.String(), ipamSubnet.V6Reserved.String(), ipamSubnet.V6Available.String(), ipamSubnet.V6Using.String()).Set(1)
×
115
        }
116
}
117

118
func (c *Controller) exportSubnetIPAssignedInfo(subnet *kubeovnv1.Subnet) {
×
119
        ipamSubnet, ok := c.ipam.Subnets[subnet.Name]
×
120
        if !ok {
×
121
                klog.Errorf("failed to get subnet %s in ipam", subnet.Name)
×
122
                return
×
123
        }
×
124

125
        ipamSubnet.Mutex.RLock()
×
126
        defer ipamSubnet.Mutex.RUnlock()
×
127

×
128
        if subnet.Spec.Protocol == kubeovnv1.ProtocolIPv4 || subnet.Spec.Protocol == kubeovnv1.ProtocolDual {
×
129
                for ip, pod := range ipamSubnet.V4IPToPod {
×
130
                        metricSubnetIPAssignedInfo.WithLabelValues(subnet.Name, ip, pod).Set(1)
×
131
                }
×
132
        }
133
        if subnet.Spec.Protocol == kubeovnv1.ProtocolIPv6 || subnet.Spec.Protocol == kubeovnv1.ProtocolDual {
×
134
                for ip, pod := range ipamSubnet.V6IPToPod {
×
135
                        metricSubnetIPAssignedInfo.WithLabelValues(subnet.Name, ip, pod).Set(1)
×
136
                }
×
137
        }
138
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc