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
cc8a4da0
Commit
cc8a4da0
authored
3 years ago
by
zhangzujian
Browse files
Options
Download
Email Patches
Plain Diff
fix pinger in dual stack cluster
parent
9364d2a2
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
dist/images/install.sh
+5
-1
dist/images/install.sh
pkg/pinger/config.go
+11
-0
pkg/pinger/config.go
pkg/pinger/ping.go
+70
-56
pkg/pinger/ping.go
yamls/kube-ovn-ipv6.yaml
+4
-0
yamls/kube-ovn-ipv6.yaml
yamls/kube-ovn.yaml
+4
-0
yamls/kube-ovn.yaml
with
94 additions
and
57 deletions
+94
-57
dist/images/install.sh
+
5
-
1
View file @
cc8a4da0
...
...
@@ -41,7 +41,7 @@ if [ "$DUAL_STACK" = "true" ]; then
POD_GATEWAY
=
"10.16.0.1,fd00:10:16::1"
SVC_CIDR
=
"10.96.0.0/12"
# Do NOT overlap with NODE/POD/JOIN CIDR
JOIN_CIDR
=
"100.64.0.0/16,fd00:100:64::/64"
# Do NOT overlap with NODE/POD/SVC CIDR
PINGER_EXTERNAL_ADDRESS
=
"114.114.114.114"
PINGER_EXTERNAL_ADDRESS
=
"114.114.114.114
,2400:3200::1
"
PINGER_EXTERNAL_DOMAIN
=
"google.com"
SVC_YAML_IPFAMILYPOLICY
=
"ipFamilyPolicy: PreferDualStack"
fi
...
...
@@ -2056,6 +2056,10 @@ spec:
valueFrom:
fieldRef:
fieldPath: status.podIP
- name: POD_IPS
valueFrom:
fieldRef:
fieldPath: status.podIPs
- name: HOST_IP
valueFrom:
fieldRef:
...
...
This diff is collapsed.
Click to expand it.
pkg/pinger/config.go
+
11
-
0
View file @
cc8a4da0
...
...
@@ -3,6 +3,7 @@ package pinger
import
(
"flag"
"os"
"strings"
"time"
"github.com/spf13/pflag"
...
...
@@ -10,6 +11,8 @@ import (
"k8s.io/client-go/rest"
"k8s.io/client-go/tools/clientcmd"
"k8s.io/klog"
"github.com/kubeovn/kube-ovn/pkg/util"
)
type
Configuration
struct
{
...
...
@@ -27,6 +30,8 @@ type Configuration struct {
HostIP
string
PodName
string
PodIP
string
PodIPs
[]
string
PodProtocols
[]
string
ExternalAddress
string
NetworkMode
string
...
...
@@ -106,6 +111,7 @@ func ParseFlags() (*Configuration, error) {
InternalDNS
:
*
argInternalDns
,
ExternalDNS
:
*
argExternalDns
,
PodIP
:
os
.
Getenv
(
"POD_IP"
),
PodIPs
:
strings
.
Split
(
os
.
Getenv
(
"POD_IPS"
),
","
),
HostIP
:
os
.
Getenv
(
"HOST_IP"
),
NodeName
:
os
.
Getenv
(
"NODE_NAME"
),
PodName
:
os
.
Getenv
(
"POD_NAME"
),
...
...
@@ -127,6 +133,11 @@ func ParseFlags() (*Configuration, error) {
ServiceOvnControllerFileLogPath
:
*
argServiceOvnControllerFileLogPath
,
ServiceOvnControllerFilePidPath
:
*
argServiceOvnControllerFilePidPath
,
}
config
.
PodProtocols
=
make
([]
string
,
len
(
config
.
PodIPs
))
for
i
,
podIP
:=
range
config
.
PodIPs
{
config
.
PodProtocols
[
i
]
=
util
.
CheckProtocol
(
podIP
)
}
if
err
:=
config
.
initKubeClient
();
err
!=
nil
{
return
nil
,
err
}
...
...
This diff is collapsed.
Click to expand it.
pkg/pinger/ping.go
+
70
-
56
View file @
cc8a4da0
...
...
@@ -6,6 +6,7 @@ import (
"math"
"net"
"os"
"strings"
"time"
goping
"github.com/oilbeater/go-ping"
...
...
@@ -13,6 +14,8 @@ import (
metav1
"k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/labels"
"k8s.io/klog"
"github.com/kubeovn/kube-ovn/pkg/util"
)
func
StartPinger
(
config
*
Configuration
,
e
*
Exporter
)
{
...
...
@@ -87,7 +90,7 @@ func pingNodes(config *Configuration) error {
var
pingErr
error
for
_
,
no
:=
range
nodes
.
Items
{
for
_
,
addr
:=
range
no
.
Status
.
Addresses
{
if
addr
.
Type
==
v1
.
NodeInternalIP
{
if
addr
.
Type
==
v1
.
NodeInternalIP
&&
util
.
ContainsString
(
config
.
PodProtocols
,
util
.
CheckProtocol
(
addr
.
Address
))
{
func
(
nodeIP
,
nodeName
string
)
{
pinger
,
err
:=
goping
.
NewPinger
(
nodeIP
)
if
err
!=
nil
{
...
...
@@ -137,37 +140,39 @@ func pingPods(config *Configuration) error {
var
pingErr
error
for
_
,
pod
:=
range
pods
.
Items
{
if
pod
.
Status
.
PodIP
!=
""
{
func
(
podIp
,
podName
,
nodeIP
,
nodeName
string
)
{
pinger
,
err
:=
goping
.
NewPinger
(
podIp
)
if
err
!=
nil
{
klog
.
Errorf
(
"failed to init pinger, %v"
,
err
)
pingErr
=
err
return
}
pinger
.
SetPrivileged
(
true
)
pinger
.
Timeout
=
1
*
time
.
Second
pinger
.
Debug
=
true
pinger
.
Count
=
3
pinger
.
Interval
=
1
*
time
.
Millisecond
pinger
.
Run
()
stats
:=
pinger
.
Statistics
()
klog
.
Infof
(
"ping pod: %s %s, count: %d, loss count %d, average rtt %.2fms"
,
podName
,
podIp
,
pinger
.
Count
,
int
(
math
.
Abs
(
float64
(
stats
.
PacketsSent
-
stats
.
PacketsRecv
))),
float64
(
stats
.
AvgRtt
)
/
float64
(
time
.
Millisecond
))
if
int
(
math
.
Abs
(
float64
(
stats
.
PacketsSent
-
stats
.
PacketsRecv
)))
!=
0
{
pingErr
=
fmt
.
Errorf
(
"ping failed"
)
}
SetPodPingMetrics
(
config
.
NodeName
,
config
.
HostIP
,
config
.
PodName
,
nodeName
,
nodeIP
,
podIp
,
float64
(
stats
.
AvgRtt
)
/
float64
(
time
.
Millisecond
),
int
(
math
.
Abs
(
float64
(
stats
.
PacketsSent
-
stats
.
PacketsRecv
))),
int
(
float64
(
stats
.
PacketsSent
)))
}(
pod
.
Status
.
PodIP
,
pod
.
Name
,
pod
.
Status
.
HostIP
,
pod
.
Spec
.
NodeName
)
for
_
,
podIP
:=
range
pod
.
Status
.
PodIPs
{
if
util
.
ContainsString
(
config
.
PodProtocols
,
util
.
CheckProtocol
(
podIP
.
IP
))
{
func
(
podIp
,
podName
,
nodeIP
,
nodeName
string
)
{
pinger
,
err
:=
goping
.
NewPinger
(
podIp
)
if
err
!=
nil
{
klog
.
Errorf
(
"failed to init pinger, %v"
,
err
)
pingErr
=
err
return
}
pinger
.
SetPrivileged
(
true
)
pinger
.
Timeout
=
1
*
time
.
Second
pinger
.
Debug
=
true
pinger
.
Count
=
3
pinger
.
Interval
=
1
*
time
.
Millisecond
pinger
.
Run
()
stats
:=
pinger
.
Statistics
()
klog
.
Infof
(
"ping pod: %s %s, count: %d, loss count %d, average rtt %.2fms"
,
podName
,
podIp
,
pinger
.
Count
,
int
(
math
.
Abs
(
float64
(
stats
.
PacketsSent
-
stats
.
PacketsRecv
))),
float64
(
stats
.
AvgRtt
)
/
float64
(
time
.
Millisecond
))
if
int
(
math
.
Abs
(
float64
(
stats
.
PacketsSent
-
stats
.
PacketsRecv
)))
!=
0
{
pingErr
=
fmt
.
Errorf
(
"ping failed"
)
}
SetPodPingMetrics
(
config
.
NodeName
,
config
.
HostIP
,
config
.
PodName
,
nodeName
,
nodeIP
,
podIp
,
float64
(
stats
.
AvgRtt
)
/
float64
(
time
.
Millisecond
),
int
(
math
.
Abs
(
float64
(
stats
.
PacketsSent
-
stats
.
PacketsRecv
))),
int
(
float64
(
stats
.
PacketsSent
)))
}(
podIP
.
IP
,
pod
.
Name
,
pod
.
Status
.
HostIP
,
pod
.
Spec
.
NodeName
)
}
}
}
return
pingErr
...
...
@@ -177,31 +182,40 @@ func pingExternal(config *Configuration) error {
if
config
.
ExternalAddress
==
""
{
return
nil
}
klog
.
Infof
(
"start to check ping external to %s"
,
config
.
ExternalAddress
)
pinger
,
err
:=
goping
.
NewPinger
(
config
.
ExternalAddress
)
if
err
!=
nil
{
klog
.
Errorf
(
"failed to init pinger, %v"
,
err
)
return
err
}
pinger
.
SetPrivileged
(
true
)
pinger
.
Timeout
=
5
*
time
.
Second
pinger
.
Debug
=
true
pinger
.
Count
=
3
pinger
.
Interval
=
1
*
time
.
Millisecond
pinger
.
Run
()
stats
:=
pinger
.
Statistics
()
klog
.
Infof
(
"ping external address: %s, total count: %d, loss count %d, average rtt %.2fms"
,
config
.
ExternalAddress
,
pinger
.
Count
,
int
(
math
.
Abs
(
float64
(
stats
.
PacketsSent
-
stats
.
PacketsRecv
))),
float64
(
stats
.
AvgRtt
)
/
float64
(
time
.
Millisecond
))
SetExternalPingMetrics
(
config
.
NodeName
,
config
.
HostIP
,
config
.
PodIP
,
config
.
ExternalAddress
,
float64
(
stats
.
AvgRtt
)
/
float64
(
time
.
Millisecond
),
int
(
math
.
Abs
(
float64
(
stats
.
PacketsSent
-
stats
.
PacketsRecv
))))
if
int
(
math
.
Abs
(
float64
(
stats
.
PacketsSent
-
stats
.
PacketsRecv
)))
!=
0
{
return
fmt
.
Errorf
(
"ping failed"
)
addresses
:=
strings
.
Split
(
config
.
ExternalAddress
,
","
)
for
_
,
addr
:=
range
addresses
{
if
!
util
.
ContainsString
(
config
.
PodProtocols
,
util
.
CheckProtocol
(
addr
))
{
continue
}
klog
.
Infof
(
"start to check ping external to %s"
,
addr
)
pinger
,
err
:=
goping
.
NewPinger
(
addr
)
if
err
!=
nil
{
klog
.
Errorf
(
"failed to init pinger, %v"
,
err
)
return
err
}
pinger
.
SetPrivileged
(
true
)
pinger
.
Timeout
=
5
*
time
.
Second
pinger
.
Debug
=
true
pinger
.
Count
=
3
pinger
.
Interval
=
1
*
time
.
Millisecond
pinger
.
Run
()
stats
:=
pinger
.
Statistics
()
klog
.
Infof
(
"ping external address: %s, total count: %d, loss count %d, average rtt %.2fms"
,
addr
,
pinger
.
Count
,
int
(
math
.
Abs
(
float64
(
stats
.
PacketsSent
-
stats
.
PacketsRecv
))),
float64
(
stats
.
AvgRtt
)
/
float64
(
time
.
Millisecond
))
SetExternalPingMetrics
(
config
.
NodeName
,
config
.
HostIP
,
config
.
PodIP
,
addr
,
float64
(
stats
.
AvgRtt
)
/
float64
(
time
.
Millisecond
),
int
(
math
.
Abs
(
float64
(
stats
.
PacketsSent
-
stats
.
PacketsRecv
))))
if
int
(
math
.
Abs
(
float64
(
stats
.
PacketsSent
-
stats
.
PacketsRecv
)))
!=
0
{
return
fmt
.
Errorf
(
"ping failed"
)
}
}
return
nil
}
...
...
This diff is collapsed.
Click to expand it.
yamls/kube-ovn-ipv6.yaml
+
4
-
0
View file @
cc8a4da0
...
...
@@ -256,6 +256,10 @@ spec:
valueFrom
:
fieldRef
:
fieldPath
:
status.podIP
-
name
:
POD_IPS
valueFrom
:
fieldRef
:
fieldPath
:
status.podIPs
-
name
:
HOST_IP
valueFrom
:
fieldRef
:
...
...
This diff is collapsed.
Click to expand it.
yamls/kube-ovn.yaml
+
4
-
0
View file @
cc8a4da0
...
...
@@ -281,6 +281,10 @@ spec:
valueFrom
:
fieldRef
:
fieldPath
:
status.podIP
-
name
:
POD_IPS
valueFrom
:
fieldRef
:
fieldPath
:
status.podIPs
-
name
:
HOST_IP
valueFrom
:
fieldRef
:
...
...
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