Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
小 白蛋
Kube OVN
Commits
68ee5eb9
Commit
68ee5eb9
authored
2 years ago
by
马洪贞
Browse files
Options
Download
Email Patches
Plain Diff
delete and recreate netem qos when update process
parent
e13c4ef1
qos
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
pkg/ovs/ovs-vsctl.go
+0
-11
pkg/ovs/ovs-vsctl.go
pkg/ovs/ovs-vsctl_linux.go
+74
-26
pkg/ovs/ovs-vsctl_linux.go
with
74 additions
and
37 deletions
+74
-37
pkg/ovs/ovs-vsctl.go
+
0
-
11
View file @
68ee5eb9
...
...
@@ -109,17 +109,6 @@ func ovsGet(table, record, column, key string) (string, error) {
return
Exec
(
args
...
)
}
func
ovsRemove
(
table
,
record
,
column
,
key
string
)
error
{
args
:=
[]
string
{
"remove"
}
if
key
==
""
{
args
=
append
(
args
,
table
,
record
,
column
)
}
else
{
args
=
append
(
args
,
table
,
record
,
column
,
key
)
}
_
,
err
:=
Exec
(
args
...
)
return
err
}
// Bridges returns bridges created by Kube-OVN
func
Bridges
()
([]
string
,
error
)
{
return
ovsFind
(
"bridge"
,
"name"
,
fmt
.
Sprintf
(
"external-ids:vendor=%s"
,
util
.
CniTypeName
))
...
...
This diff is collapsed.
Click to expand it.
pkg/ovs/ovs-vsctl_linux.go
+
74
-
26
View file @
68ee5eb9
...
...
@@ -3,6 +3,7 @@ package ovs
import
(
"fmt"
"strconv"
"strings"
"k8s.io/klog/v2"
...
...
@@ -315,42 +316,43 @@ func SetNetemQos(podName, podNamespace, iface, latency, limit, loss string) erro
return
nil
}
if
err
:=
ovsSet
(
"qos"
,
qos
,
qosCommandValues
...
);
err
!=
nil
{
latencyVal
,
lossVal
,
limitVal
,
err
:=
getNetemQosConfig
(
qos
)
if
err
!=
nil
{
klog
.
Errorf
(
"failed to get other_config for qos %s: %v"
,
qos
,
err
)
return
err
}
if
latencyMs
==
0
{
if
err
:=
ovsRemove
(
"qos"
,
qos
,
"other_config"
,
"latency"
);
err
!=
nil
{
return
err
}
if
latencyVal
==
strconv
.
Itoa
(
latencyUs
)
&&
limitVal
==
limit
&&
lossVal
==
loss
{
klog
.
Infof
(
"no value changed for netem qos, ignore"
)
continue
}
if
limitPkts
==
0
{
if
err
:=
ovsRemove
(
"qos"
,
qos
,
"other_config"
,
"limit"
);
err
!=
nil
{
return
err
}
if
err
=
deleteNetemQosById
(
qos
,
iface
,
podName
,
podNamespace
);
err
!=
nil
{
klog
.
Errorf
(
"failed to delete netem qos: %v"
,
err
)
return
err
}
qosCommandValues
=
append
(
qosCommandValues
,
"type=linux-netem"
,
fmt
.
Sprintf
(
`external-ids:iface-id="%s"`
,
iface
))
if
podNamespace
!=
""
&&
podName
!=
""
{
qosCommandValues
=
append
(
qosCommandValues
,
fmt
.
Sprintf
(
"external-ids:pod=%s/%s"
,
podNamespace
,
podName
))
}
if
lossPercent
==
0
{
if
err
:=
ovsRemove
(
"qos"
,
qos
,
"other_config"
,
"loss"
);
err
!=
nil
{
return
err
}
qos
,
err
:=
ovsCreate
(
"qos"
,
qosCommandValues
...
)
if
err
!=
nil
{
klog
.
Errorf
(
"failed to create netem qos: %v"
,
err
)
return
err
}
err
=
ovsSet
(
"port"
,
ifName
,
fmt
.
Sprintf
(
"qos=%s"
,
qos
))
if
err
!=
nil
{
klog
.
Errorf
(
"failed to set netem qos to port: %v"
,
err
)
return
err
}
}
}
}
else
{
for
_
,
qos
:=
range
qosList
{
qosType
,
_
:=
ovsGet
(
"qos"
,
qos
,
"type"
,
""
)
if
qosType
!=
util
.
NetemQos
{
continue
}
if
err
=
ClearPortQosBinding
(
iface
);
err
!=
nil
{
klog
.
Errorf
(
"failed to delete qos bingding info for interface %s: %v"
,
iface
,
err
)
return
err
}
// reuse this function to delete qos record
if
err
=
ClearPodBandwidth
(
podName
,
podNamespace
,
iface
);
err
!=
nil
{
klog
.
Errorf
(
"failed to delete netemqos record for pod %s/%s: %v"
,
podNamespace
,
podName
,
err
)
if
err
:=
deleteNetemQosById
(
qos
,
iface
,
podName
,
podNamespace
);
err
!=
nil
{
klog
.
Errorf
(
"failed to delete netem qos: %v"
,
err
)
return
err
}
}
...
...
@@ -359,6 +361,52 @@ func SetNetemQos(podName, podNamespace, iface, latency, limit, loss string) erro
return
nil
}
func
getNetemQosConfig
(
qosId
string
)
(
string
,
string
,
string
,
error
)
{
var
latency
,
loss
,
limit
string
config
,
err
:=
ovsGet
(
"qos"
,
qosId
,
"other_config"
,
""
)
if
err
!=
nil
{
klog
.
Errorf
(
"failed to get other_config for qos %s: %v"
,
qosId
,
err
)
return
latency
,
loss
,
limit
,
err
}
if
len
(
config
)
==
0
{
return
latency
,
loss
,
limit
,
nil
}
values
:=
strings
.
Split
(
strings
.
Trim
(
config
,
"{}"
),
","
)
for
_
,
value
:=
range
values
{
records
:=
strings
.
Split
(
value
,
"="
)
switch
strings
.
TrimSpace
(
records
[
0
])
{
case
"latency"
:
latency
=
strings
.
TrimSpace
(
records
[
1
])
case
"loss"
:
loss
=
strings
.
TrimSpace
(
records
[
1
])
case
"limit"
:
limit
=
strings
.
TrimSpace
(
records
[
1
])
}
}
return
latency
,
loss
,
limit
,
nil
}
func
deleteNetemQosById
(
qosId
,
iface
,
podName
,
podNamespace
string
)
error
{
qosType
,
_
:=
ovsGet
(
"qos"
,
qosId
,
"type"
,
""
)
if
qosType
!=
util
.
NetemQos
{
return
nil
}
if
err
:=
ClearPortQosBinding
(
iface
);
err
!=
nil
{
klog
.
Errorf
(
"failed to delete qos bingding info for interface %s: %v"
,
iface
,
err
)
return
err
}
// reuse this function to delete qos record
if
err
:=
ClearPodBandwidth
(
podName
,
podNamespace
,
iface
);
err
!=
nil
{
klog
.
Errorf
(
"failed to delete netemqos record for pod %s/%s: %v"
,
podNamespace
,
podName
,
err
)
return
err
}
return
nil
}
func
IsUserspaceDataPath
()
(
is
bool
,
err
error
)
{
dp
,
err
:=
ovsFind
(
"bridge"
,
"datapath_type"
,
"name=br-int"
)
if
err
!=
nil
{
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment
Menu
Projects
Groups
Snippets
Help