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

kubeovn / kube-ovn / 15703224874

17 Jun 2025 09:16AM UTC coverage: 21.733% (-0.02%) from 21.755%
15703224874

Pull #5364

github

zbb88888
fix: allow any subnet is deleted before pod deletion

Signed-off-by: zbb88888 <jmdxjsjgcxy@gmail.com>
Pull Request #5364: fix ip cr not delete with pod in the case of subnet not exist

0 of 58 new or added lines in 5 files covered. (0.0%)

145 existing lines in 1 file now uncovered.

10441 of 48043 relevant lines covered (21.73%)

0.25 hits per line

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

0.0
/pkg/pinger/util.go
1
package pinger
2

3
import (
4
        "fmt"
5
        "os/exec"
6
        "strconv"
7
        "strings"
8
        "sync/atomic"
9

10
        "github.com/kubeovn/ovsdb"
11
        "k8s.io/klog/v2"
12
)
13

14
// IncrementErrorCounter increases the counter of failed queries to OVN server.
15
func (e *Exporter) IncrementErrorCounter() {
×
16
        e.errorsLocker.Lock()
×
17
        defer e.errorsLocker.Unlock()
×
18
        atomic.AddInt64(&e.errors, 1)
×
19
}
×
20

21
func (e *Exporter) getOvsStatus() map[string]bool {
×
22
        components := []string{
×
23
                "ovsdb-server",
×
24
                "ovs-vswitchd",
×
25
        }
×
26
        result := make(map[string]bool)
×
27
        for _, component := range components {
×
28
                _, err := e.Client.GetProcessInfo(component)
×
29
                if err != nil {
×
30
                        klog.Errorf("%s: pid-%v", component, err)
×
31
                        e.IncrementErrorCounter()
×
32
                        result[component] = false
×
33
                        continue
×
34
                }
35
                result[component] = true
×
36
        }
37

38
        return result
×
39
}
40

41
func (e *Exporter) getOvsDatapath() ([]string, error) {
×
42
        var datapathsList []string
×
43
        cmdstr := fmt.Sprintf("ovs-appctl -T %v dpctl/dump-dps", e.Client.Timeout)
×
44
        cmd := exec.Command("sh", "-c", cmdstr) // #nosec G204
×
45
        output, err := cmd.CombinedOutput()
×
46
        if err != nil {
×
47
                return nil, fmt.Errorf("failed to get output of dpctl/dump-dps: %w", err)
×
48
        }
×
49

50
        for kvPair := range strings.SplitSeq(string(output), "\n") {
×
51
                var datapathType, datapathName string
×
52
                line := strings.TrimSpace(strings.TrimSuffix(kvPair, "\n"))
×
53
                if strings.Contains(line, "@") {
×
54
                        datapath := strings.Split(line, "@")
×
55
                        datapathType, datapathName = datapath[0], datapath[1]
×
56
                } else {
×
57
                        // There is two line for "system@ovs-system\n", the second line is nil, ignore this situation
×
58
                        continue
×
59
                }
60
                metricOvsDp.WithLabelValues(e.Client.System.Hostname, datapathName, datapathType).Set(1)
×
61
                datapathsList = append(datapathsList, datapathName)
×
62
        }
63
        metricOvsDpTotal.WithLabelValues(e.Client.System.Hostname).Set(float64(len(datapathsList)))
×
64

×
65
        return datapathsList, nil
×
66
}
67

68
func (e *Exporter) setOvsDpIfMetric(datapathName string) error {
×
69
        cmdstr := fmt.Sprintf("ovs-appctl -T %v dpctl/show %s", e.Client.Timeout, datapathName)
×
70
        cmd := exec.Command("sh", "-c", cmdstr) // #nosec G204
×
71
        output, err := cmd.CombinedOutput()
×
72
        if err != nil {
×
73
                return fmt.Errorf("failed to get output of dpctl/show %s: %w", datapathName, err)
×
74
        }
×
75

76
        var datapathPortCount float64
×
77
        for kvPair := range strings.SplitSeq(string(output), "\n") {
×
78
                line := strings.TrimSpace(kvPair)
×
79
                switch {
×
80
                case strings.HasPrefix(line, "lookups:"):
×
81
                        e.ovsDatapathLookupsMetrics(line, datapathName)
×
82
                case strings.HasPrefix(line, "masks:"):
×
83
                        e.ovsDatapathMasksMetrics(line, datapathName)
×
84
                case strings.HasPrefix(line, "port "):
×
85
                        e.ovsDatapathPortMetrics(line, datapathName)
×
86
                        datapathPortCount++
×
87
                case strings.HasPrefix(line, "flows:"):
×
88
                        flowFields := strings.Fields(line)
×
89
                        value, _ := strconv.ParseFloat(flowFields[1], 64)
×
90
                        metricOvsDpFlowsTotal.WithLabelValues(e.Client.System.Hostname, datapathName).Set(value)
×
91
                }
92
        }
93
        metricOvsDpIfTotal.WithLabelValues(e.Client.System.Hostname, datapathName).Set(datapathPortCount)
×
94

×
95
        return nil
×
96
}
97

98
func (e *Exporter) ovsDatapathLookupsMetrics(line, datapath string) {
×
99
        s := strings.TrimPrefix(line, "lookups:")
×
NEW
100
        for _, field := range strings.Fields(s) {
×
101
                elem := strings.Split(field, ":")
×
102
                if len(elem) != 2 {
×
103
                        continue
×
104
                }
105
                value, err := strconv.ParseFloat(elem[1], 64)
×
106
                if err != nil {
×
107
                        klog.Errorf("Failed to parse value %v into float in DpFlowsLookup:(%v)", value, err)
×
108
                        value = 0
×
109
                }
×
110
                switch elem[0] {
×
111
                case "hit":
×
112
                        metricOvsDpFlowsLookupHit.WithLabelValues(e.Client.System.Hostname, datapath).Set(value)
×
113
                case "missed":
×
114
                        metricOvsDpFlowsLookupMissed.WithLabelValues(e.Client.System.Hostname, datapath).Set(value)
×
115
                case "lost":
×
116
                        metricOvsDpFlowsLookupLost.WithLabelValues(e.Client.System.Hostname, datapath).Set(value)
×
117
                }
118
        }
119
}
120

121
func (e *Exporter) ovsDatapathMasksMetrics(line, datapath string) {
×
122
        s := strings.TrimPrefix(line, "masks:")
×
NEW
123
        for _, field := range strings.Fields(s) {
×
124
                elem := strings.Split(field, ":")
×
125
                if len(elem) != 2 {
×
126
                        continue
×
127
                }
128
                value, err := strconv.ParseFloat(elem[1], 64)
×
129
                if err != nil {
×
130
                        klog.Errorf("Failed to parse value %v into float in OvsDpMasks:(%v)", value, err)
×
131
                        value = 0
×
132
                }
×
133
                switch elem[0] {
×
134
                case "hit":
×
135
                        metricOvsDpMasksHit.WithLabelValues(e.Client.System.Hostname, datapath).Set(value)
×
136
                case "total":
×
137
                        metricOvsDpMasksTotal.WithLabelValues(e.Client.System.Hostname, datapath).Set(value)
×
138
                case "hit/pkt":
×
139
                        metricOvsDpMasksHitRatio.WithLabelValues(e.Client.System.Hostname, datapath).Set(value)
×
140
                }
141
        }
142
}
143

144
func (e *Exporter) ovsDatapathPortMetrics(line, datapath string) {
×
145
        portFields := strings.Fields(line)
×
146
        portType := "system"
×
147
        if len(portFields) > 3 {
×
148
                portType = strings.Trim(portFields[3], "():")
×
149
        }
×
150

151
        portName := strings.TrimSpace(portFields[2])
×
152
        portNumber := strings.Trim(portFields[1], ":")
×
153
        metricOvsDpIf.WithLabelValues(e.Client.System.Hostname, datapath, portName, portType, portNumber).Set(1)
×
154
}
155

156
func (e *Exporter) getInterfaceInfo() ([]*ovsdb.OvsInterface, error) {
×
157
        intfs, err := e.Client.GetDbInterfaces()
×
158
        if err != nil {
×
159
                klog.Errorf("GetDbInterfaces error: %v", err)
×
160
                e.IncrementErrorCounter()
×
161
                return nil, err
×
162
        }
×
163

164
        return intfs, nil
×
165
}
166

167
func (e *Exporter) setOvsInterfaceMetric(intf *ovsdb.OvsInterface) {
×
168
        interfaceMain.WithLabelValues(e.Client.System.Hostname, intf.UUID, intf.Name).Set(1)
×
169
        e.setOvsInterfaceStateMetric(intf)
×
170
        interfaceMacInUse.WithLabelValues(e.Client.System.Hostname, intf.Name, intf.MacInUse).Set(1)
×
171
        interfaceMtu.WithLabelValues(e.Client.System.Hostname, intf.Name).Set(intf.Mtu)
×
172
        interfaceOfPort.WithLabelValues(e.Client.System.Hostname, intf.Name).Set(intf.OfPort)
×
173
        interfaceIfIndex.WithLabelValues(e.Client.System.Hostname, intf.Name).Set(intf.IfIndex)
×
174
        e.setOvsInterfaceStatisticsMetric(intf)
×
175
}
×
176

177
func (e *Exporter) setOvsInterfaceStateMetric(intf *ovsdb.OvsInterface) {
×
178
        var adminState float64
×
179
        switch intf.AdminState {
×
180
        case "down":
×
181
                adminState = 0
×
182
        case "up":
×
183
                adminState = 1
×
184
        default:
×
185
                adminState = 2
×
186
        }
187
        interfaceAdminState.WithLabelValues(e.Client.System.Hostname, intf.Name).Set(adminState)
×
188

×
189
        var linkState float64
×
190
        switch intf.LinkState {
×
191
        case "down":
×
192
                linkState = 0
×
193
        case "up":
×
194
                linkState = 1
×
195
        default:
×
196
                linkState = 2
×
197
        }
198
        interfaceLinkState.WithLabelValues(e.Client.System.Hostname, intf.Name).Set(linkState)
×
199
}
200

201
func (e *Exporter) setOvsInterfaceStatisticsMetric(intf *ovsdb.OvsInterface) {
×
202
        for key, value := range intf.Statistics {
×
203
                switch key {
×
204
                case "rx_crc_err":
×
205
                        interfaceStatRxCrcError.WithLabelValues(e.Client.System.Hostname, intf.Name).Set(float64(value))
×
206
                case "rx_dropped":
×
207
                        interfaceStatRxDropped.WithLabelValues(e.Client.System.Hostname, intf.Name).Set(float64(value))
×
208
                case "rx_frame_err":
×
209
                        interfaceStatRxFrameError.WithLabelValues(e.Client.System.Hostname, intf.Name).Set(float64(value))
×
210
                case "rx_missed_errors":
×
211
                        interfaceStatRxMissedError.WithLabelValues(e.Client.System.Hostname, intf.Name).Set(float64(value))
×
212
                case "rx_over_err":
×
213
                        interfaceStatRxOverrunError.WithLabelValues(e.Client.System.Hostname, intf.Name).Set(float64(value))
×
214
                case "rx_errors":
×
215
                        interfaceStatRxErrorsTotal.WithLabelValues(e.Client.System.Hostname, intf.Name).Set(float64(value))
×
216
                case "rx_packets":
×
217
                        interfaceStatRxPackets.WithLabelValues(e.Client.System.Hostname, intf.Name).Set(float64(value))
×
218
                case "rx_bytes":
×
219
                        interfaceStatRxBytes.WithLabelValues(e.Client.System.Hostname, intf.Name).Set(float64(value))
×
220
                case "tx_packets":
×
221
                        interfaceStatTxPackets.WithLabelValues(e.Client.System.Hostname, intf.Name).Set(float64(value))
×
222
                case "tx_bytes":
×
223
                        interfaceStatTxBytes.WithLabelValues(e.Client.System.Hostname, intf.Name).Set(float64(value))
×
224
                case "tx_dropped":
×
225
                        interfaceStatTxDropped.WithLabelValues(e.Client.System.Hostname, intf.Name).Set(float64(value))
×
226
                case "tx_errors":
×
227
                        interfaceStatTxErrorsTotal.WithLabelValues(e.Client.System.Hostname, intf.Name).Set(float64(value))
×
228
                case "collisions":
×
229
                        interfaceStatCollisions.WithLabelValues(e.Client.System.Hostname, intf.Name).Set(float64(value))
×
230
                case "rx_multicast_packets":
×
231
                        interfaceStatRxMulticastPackets.WithLabelValues(e.Client.System.Hostname, intf.Name).Set(float64(value))
×
232
                default:
×
233
                        klog.V(3).Infof("unknown statistics %s with value %d on OVS interface %s", key, value, intf.Name)
×
234
                }
235
        }
236
}
237

238
func resetOvsDatapathMetrics() {
×
239
        metricOvsDpFlowsTotal.Reset()
×
240
        metricOvsDpFlowsLookupHit.Reset()
×
241
        metricOvsDpFlowsLookupMissed.Reset()
×
242
        metricOvsDpFlowsLookupLost.Reset()
×
243

×
244
        metricOvsDpMasksHit.Reset()
×
245
        metricOvsDpMasksTotal.Reset()
×
246
        metricOvsDpMasksHitRatio.Reset()
×
247

×
248
        metricOvsDp.Reset()
×
249
        metricOvsDpTotal.Reset()
×
250
        metricOvsDpIf.Reset()
×
251
        metricOvsDpIfTotal.Reset()
×
252
}
×
253

254
func resetOvsInterfaceMetrics() {
×
255
        interfaceMain.Reset()
×
256
        interfaceAdminState.Reset()
×
257
        interfaceLinkState.Reset()
×
258
        interfaceMacInUse.Reset()
×
259
        interfaceMtu.Reset()
×
260
        interfaceOfPort.Reset()
×
261
        interfaceIfIndex.Reset()
×
262

×
263
        interfaceStatRxCrcError.Reset()
×
264
        interfaceStatRxDropped.Reset()
×
265
        interfaceStatRxFrameError.Reset()
×
266
        interfaceStatRxMissedError.Reset()
×
267
        interfaceStatRxOverrunError.Reset()
×
268
        interfaceStatRxErrorsTotal.Reset()
×
269
        interfaceStatRxPackets.Reset()
×
270
        interfaceStatRxBytes.Reset()
×
271

×
272
        interfaceStatTxPackets.Reset()
×
273
        interfaceStatTxBytes.Reset()
×
274
        interfaceStatTxDropped.Reset()
×
275
        interfaceStatTxErrorsTotal.Reset()
×
276
        interfaceStatCollisions.Reset()
×
277
        interfaceStatRxMulticastPackets.Reset()
×
278
}
×
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