Skip to content

Commit e262b2f

Browse files
committed
cni-server: do not limit read-only ovs-vsctl commands (#6104)
Signed-off-by: zhangzujian <zhangzujian.7@gmail.com>
1 parent bf81a98 commit e262b2f

File tree

1 file changed

+49
-32
lines changed

1 file changed

+49
-32
lines changed

pkg/ovs/ovs-vsctl.go

Lines changed: 49 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,36 @@ import (
1111
"time"
1212

1313
"k8s.io/klog/v2"
14+
"k8s.io/utils/set"
1415

1516
"github.com/kubeovn/kube-ovn/pkg/util"
1617
)
1718

18-
var limiter *Limiter
19-
20-
func init() {
21-
limiter = new(Limiter)
22-
}
19+
var limiter = new(Limiter)
20+
21+
var readOnlyCommands = set.New(
22+
"", // no command specified
23+
"show", // print overview of database contents
24+
"list-br", // print the names of all the bridges
25+
"br-exists", // exit 2 if BRIDGE does not exist
26+
"br-to-vlan", // print the VLAN which BRIDGE is on
27+
"br-to-parent", // print the parent of BRIDGE
28+
"br-get-external-id", // print value of KEY on BRIDGE or list key-value pairs on BRIDGE
29+
"list-ports", // print the names of all the ports on BRIDGE
30+
"port-to-br", // print name of bridge that contains PORT
31+
"list-ifaces", // print the names of all interfaces on BRIDGE
32+
"iface-to-br", // print name of bridge that contains IFACE
33+
"get-controller", // print the controllers for BRIDGE
34+
"get-fail-mode", // print the fail-mode for BRIDGE
35+
"get-manager", // print the managers
36+
"get-ssl", // print the SSL configuration
37+
"get-aa-mapping", // get Auto Attach mappings from BRIDGE
38+
"list-zone-limits", // list all limits configured on DATAPATH
39+
"list", // list RECord (or all records) in TBL
40+
"find", // list records satisfying CONDITION in TBL
41+
"get", // print values of COLumns in RECord in TBL
42+
"wait-until", // wait until condition is true
43+
)
2344

2445
func UpdateOVSVsctlLimiter(c int32) {
2546
if c >= 0 {
@@ -34,40 +55,35 @@ func UpdateOVSVsctlLimiter(c int32) {
3455
var podNetNsRegexp = regexp.MustCompile(`pod_netns="([^"]+)"`)
3556

3657
func Exec(args ...string) (string, error) {
37-
ctx, cancel := context.WithTimeout(context.Background(), time.Second)
38-
defer cancel()
39-
40-
var (
41-
start time.Time
42-
elapsed float64
43-
output []byte
44-
method, code string
45-
err error
46-
)
47-
48-
if err = limiter.Wait(ctx); err != nil {
49-
klog.V(4).Infof("command %s %s waiting for execution timeout by concurrency limit of %d", OvsVsCtl, strings.Join(args, " "), limiter.Limit())
50-
return "", err
58+
var command string
59+
for arg := range slices.Values(args) {
60+
if !strings.HasPrefix(arg, "-") {
61+
command = arg
62+
break
63+
}
5164
}
52-
defer limiter.Done()
53-
klog.V(4).Infof("command %s %s waiting for execution concurrency %d/%d", OvsVsCtl, strings.Join(args, " "), limiter.Current(), limiter.Limit())
5465

55-
start = time.Now()
56-
args = append([]string{"--timeout=30"}, args...)
57-
output, err = exec.Command(OvsVsCtl, args...).CombinedOutput()
58-
elapsed = float64((time.Since(start)) / time.Millisecond)
59-
klog.V(4).Infof("command %s %s in %vms", OvsVsCtl, strings.Join(args, " "), elapsed)
66+
if !readOnlyCommands.Has(command) {
67+
ctx, cancel := context.WithTimeout(context.Background(), time.Second)
68+
defer cancel()
6069

61-
for _, arg := range args {
62-
if !strings.HasPrefix(arg, "--") {
63-
method = arg
64-
break
70+
if err := limiter.Wait(ctx); err != nil {
71+
klog.V(4).Infof("command %s %s waiting for execution timeout by concurrency limit of %d", OvsVsCtl, strings.Join(args, " "), limiter.Limit())
72+
return "", err
6573
}
74+
defer limiter.Done()
75+
klog.V(4).Infof("command %s %s waiting for execution concurrency %d/%d", OvsVsCtl, strings.Join(args, " "), limiter.Current(), limiter.Limit())
6676
}
6777

68-
code = "0"
78+
start := time.Now()
79+
args = slices.Insert(args, 0, "--timeout=30")
80+
output, err := exec.Command(OvsVsCtl, args...).CombinedOutput()
81+
elapsed := float64((time.Since(start)) / time.Millisecond)
82+
klog.V(4).Infof("command %s %s in %vms", OvsVsCtl, strings.Join(args, " "), elapsed)
83+
84+
code := "0"
6985
defer func() {
70-
ovsClientRequestLatency.WithLabelValues("ovsdb", method, code).Observe(elapsed)
86+
ovsClientRequestLatency.WithLabelValues("ovsdb", command, code).Observe(elapsed)
7187
}()
7288

7389
if err != nil {
@@ -77,6 +93,7 @@ func Exec(args ...string) (string, error) {
7793
} else if elapsed > 500 {
7894
klog.Warningf("ovs-vsctl command took too long: %s %s in %vms", OvsVsCtl, strings.Join(args, " "), elapsed)
7995
}
96+
8097
return trimCommandOutput(output), nil
8198
}
8299

0 commit comments

Comments
 (0)