Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
42832e76
Commit
42832e76
authored
Nov 13, 2017
by
m1093782566
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix ipvs proxier getLocalIPs() error
parent
338ee7f5
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
35 additions
and
9 deletions
+35
-9
proxier.go
pkg/proxy/iptables/proxier.go
+1
-1
proxier_test.go
pkg/proxy/iptables/proxier_test.go
+8
-0
proxier.go
pkg/proxy/ipvs/proxier.go
+10
-6
proxier_test.go
pkg/proxy/ipvs/proxier_test.go
+8
-0
endpoints.go
pkg/proxy/util/endpoints.go
+7
-2
endpoints_test.go
pkg/proxy/util/endpoints_test.go
+1
-0
No files found.
pkg/proxy/iptables/proxier.go
View file @
42832e76
...
@@ -798,7 +798,7 @@ func getLocalIPs(endpointsMap proxyEndpointsMap) map[types.NamespacedName]sets.S
...
@@ -798,7 +798,7 @@ func getLocalIPs(endpointsMap proxyEndpointsMap) map[types.NamespacedName]sets.S
for
svcPortName
:=
range
endpointsMap
{
for
svcPortName
:=
range
endpointsMap
{
for
_
,
ep
:=
range
endpointsMap
[
svcPortName
]
{
for
_
,
ep
:=
range
endpointsMap
[
svcPortName
]
{
if
ep
.
isLocal
{
if
ep
.
isLocal
{
// If the endpoint has a bad format,
ip
Part() will log an
// If the endpoint has a bad format,
utilproxy.IP
Part() will log an
// error and ep.IPPart() will return a null string.
// error and ep.IPPart() will return a null string.
if
ip
:=
ep
.
IPPart
();
ip
!=
""
{
if
ip
:=
ep
.
IPPart
();
ip
!=
""
{
nsn
:=
svcPortName
.
NamespacedName
nsn
:=
svcPortName
.
NamespacedName
...
...
pkg/proxy/iptables/proxier_test.go
View file @
42832e76
...
@@ -1264,6 +1264,14 @@ func Test_getLocalIPs(t *testing.T) {
...
@@ -1264,6 +1264,14 @@ func Test_getLocalIPs(t *testing.T) {
{
Namespace
:
"ns2"
,
Name
:
"ep2"
}
:
sets
.
NewString
(
"2.2.2.2"
,
"2.2.2.22"
,
"2.2.2.3"
),
{
Namespace
:
"ns2"
,
Name
:
"ep2"
}
:
sets
.
NewString
(
"2.2.2.2"
,
"2.2.2.22"
,
"2.2.2.3"
),
{
Namespace
:
"ns4"
,
Name
:
"ep4"
}
:
sets
.
NewString
(
"4.4.4.4"
,
"4.4.4.6"
),
{
Namespace
:
"ns4"
,
Name
:
"ep4"
}
:
sets
.
NewString
(
"4.4.4.4"
,
"4.4.4.6"
),
},
},
},
{
// Case[5]: named port local and bad endpoints IP
endpointsMap
:
map
[
proxy
.
ServicePortName
][]
*
endpointsInfo
{
makeServicePortName
(
"ns1"
,
"ep1"
,
"p11"
)
:
{
{
endpoint
:
"bad ip:11"
,
isLocal
:
true
},
},
},
expected
:
map
[
types
.
NamespacedName
]
sets
.
String
{},
}}
}}
for
tci
,
tc
:=
range
testCases
{
for
tci
,
tc
:=
range
testCases
{
...
...
pkg/proxy/ipvs/proxier.go
View file @
42832e76
...
@@ -1466,14 +1466,18 @@ func writeLine(buf *bytes.Buffer, words ...string) {
...
@@ -1466,14 +1466,18 @@ func writeLine(buf *bytes.Buffer, words ...string) {
func
getLocalIPs
(
endpointsMap
proxyEndpointsMap
)
map
[
types
.
NamespacedName
]
sets
.
String
{
func
getLocalIPs
(
endpointsMap
proxyEndpointsMap
)
map
[
types
.
NamespacedName
]
sets
.
String
{
localIPs
:=
make
(
map
[
types
.
NamespacedName
]
sets
.
String
)
localIPs
:=
make
(
map
[
types
.
NamespacedName
]
sets
.
String
)
for
svcPort
:=
range
endpointsMap
{
for
svcPort
Name
:=
range
endpointsMap
{
for
_
,
ep
:=
range
endpointsMap
[
svcPort
]
{
for
_
,
ep
:=
range
endpointsMap
[
svcPort
Name
]
{
if
ep
.
isLocal
{
if
ep
.
isLocal
{
nsn
:=
svcPort
.
NamespacedName
// If the endpoint has a bad format, utilproxy.IPPart() will log an
if
localIPs
[
nsn
]
==
nil
{
// error and ep.IPPart() will return a null string.
localIPs
[
nsn
]
=
sets
.
NewString
()
if
ip
:=
ep
.
IPPart
();
ip
!=
""
{
nsn
:=
svcPortName
.
NamespacedName
if
localIPs
[
nsn
]
==
nil
{
localIPs
[
nsn
]
=
sets
.
NewString
()
}
localIPs
[
nsn
]
.
Insert
(
ip
)
}
}
localIPs
[
nsn
]
.
Insert
(
ep
.
IPPart
())
// just the IP part
}
}
}
}
}
}
...
...
pkg/proxy/ipvs/proxier_test.go
View file @
42832e76
...
@@ -2017,6 +2017,14 @@ func Test_getLocalIPs(t *testing.T) {
...
@@ -2017,6 +2017,14 @@ func Test_getLocalIPs(t *testing.T) {
{
Namespace
:
"ns2"
,
Name
:
"ep2"
}
:
sets
.
NewString
(
"2.2.2.2"
,
"2.2.2.22"
,
"2.2.2.3"
),
{
Namespace
:
"ns2"
,
Name
:
"ep2"
}
:
sets
.
NewString
(
"2.2.2.2"
,
"2.2.2.22"
,
"2.2.2.3"
),
{
Namespace
:
"ns4"
,
Name
:
"ep4"
}
:
sets
.
NewString
(
"4.4.4.4"
,
"4.4.4.6"
),
{
Namespace
:
"ns4"
,
Name
:
"ep4"
}
:
sets
.
NewString
(
"4.4.4.4"
,
"4.4.4.6"
),
},
},
},
{
// Case[5]: named port local and bad endpoints IP
endpointsMap
:
map
[
proxy
.
ServicePortName
][]
*
endpointsInfo
{
makeServicePortName
(
"ns1"
,
"ep1"
,
"p11"
)
:
{
{
endpoint
:
"bad ip:11"
,
isLocal
:
true
},
},
},
expected
:
map
[
types
.
NamespacedName
]
sets
.
String
{},
}}
}}
for
tci
,
tc
:=
range
testCases
{
for
tci
,
tc
:=
range
testCases
{
...
...
pkg/proxy/util/endpoints.go
View file @
42832e76
...
@@ -32,12 +32,17 @@ func IPPart(s string) string {
...
@@ -32,12 +32,17 @@ func IPPart(s string) string {
return
s
return
s
}
}
// Must be IP:port
// Must be IP:port
ip
,
_
,
err
:=
net
.
SplitHostPort
(
s
)
host
,
_
,
err
:=
net
.
SplitHostPort
(
s
)
if
err
!=
nil
{
if
err
!=
nil
{
glog
.
Errorf
(
"Error parsing '%s': %v"
,
s
,
err
)
glog
.
Errorf
(
"Error parsing '%s': %v"
,
s
,
err
)
return
""
return
""
}
}
return
ip
// Check if host string is a valid IP address
if
ip
:=
net
.
ParseIP
(
host
);
ip
!=
nil
{
glog
.
Errorf
(
"invalid IP part '%s'"
,
host
)
return
host
}
return
""
}
}
// ToCIDR returns a host address of the form <ip-address>/32 for
// ToCIDR returns a host address of the form <ip-address>/32 for
...
...
pkg/proxy/util/endpoints_test.go
View file @
42832e76
...
@@ -35,6 +35,7 @@ func TestIPPart(t *testing.T) {
...
@@ -35,6 +35,7 @@ func TestIPPart(t *testing.T) {
{
"[2001:db8::2:2]:9999"
,
"2001:db8::2:2"
,
noError
},
{
"[2001:db8::2:2]:9999"
,
"2001:db8::2:2"
,
noError
},
{
"1.2.3.4::9999"
,
""
,
"too many colons"
},
{
"1.2.3.4::9999"
,
""
,
"too many colons"
},
{
"1.2.3.4:[0]"
,
""
,
"unexpected '[' in address"
},
{
"1.2.3.4:[0]"
,
""
,
"unexpected '[' in address"
},
{
"1.2.3:8080"
,
""
,
"invalid ip part"
},
}
}
for
_
,
tc
:=
range
testCases
{
for
_
,
tc
:=
range
testCases
{
...
...
Write
Preview
Markdown
is supported
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