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
929adb69
Unverified
Commit
929adb69
authored
May 15, 2019
by
Kubernetes Prow Robot
Committed by
GitHub
May 15, 2019
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #76165 from JacobTanenbaum/minor-cleanups
Minor cleanups in pkg/proxy/endpoints.go
parents
8a822b0f
9d4693a7
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
19 additions
and
19 deletions
+19
-19
endpoints.go
pkg/proxy/endpoints.go
+9
-9
endpoints_test.go
pkg/proxy/endpoints_test.go
+4
-4
proxier.go
pkg/proxy/iptables/proxier.go
+1
-1
proxier_test.go
pkg/proxy/iptables/proxier_test.go
+2
-2
proxier.go
pkg/proxy/ipvs/proxier.go
+1
-1
proxier_test.go
pkg/proxy/ipvs/proxier_test.go
+2
-2
No files found.
pkg/proxy/endpoints.go
View file @
929adb69
...
...
@@ -201,18 +201,18 @@ type UpdateEndpointMapResult struct {
}
// UpdateEndpointsMap updates endpointsMap base on the given changes.
func
UpdateEndpointsMap
(
endpointsMap
EndpointsMap
,
changes
*
EndpointChangeTracker
)
(
result
UpdateEndpointMapResult
)
{
func
(
em
EndpointsMap
)
Update
(
changes
*
EndpointChangeTracker
)
(
result
UpdateEndpointMapResult
)
{
result
.
StaleEndpoints
=
make
([]
ServiceEndpoint
,
0
)
result
.
StaleServiceNames
=
make
([]
ServicePortName
,
0
)
result
.
LastChangeTriggerTimes
=
make
([]
time
.
Time
,
0
)
e
ndpointsMap
.
apply
(
e
m
.
apply
(
changes
,
&
result
.
StaleEndpoints
,
&
result
.
StaleServiceNames
,
&
result
.
LastChangeTriggerTimes
)
// TODO: If this will appear to be computationally expensive, consider
// computing this incrementally similarly to endpointsMap.
result
.
HCEndpointsLocalIPSize
=
make
(
map
[
types
.
NamespacedName
]
int
)
localIPs
:=
GetLocalEndpointIPs
(
endpointsMap
)
localIPs
:=
em
.
getLocalEndpointIPs
(
)
for
nsn
,
ips
:=
range
localIPs
{
result
.
HCEndpointsLocalIPSize
[
nsn
]
=
len
(
ips
)
}
...
...
@@ -294,8 +294,8 @@ func (em EndpointsMap) apply(changes *EndpointChangeTracker, staleEndpoints *[]S
changes
.
lock
.
Lock
()
defer
changes
.
lock
.
Unlock
()
for
_
,
change
:=
range
changes
.
items
{
em
.
U
nmerge
(
change
.
previous
)
em
.
M
erge
(
change
.
current
)
em
.
u
nmerge
(
change
.
previous
)
em
.
m
erge
(
change
.
current
)
detectStaleConnections
(
change
.
previous
,
change
.
current
,
staleEndpoints
,
staleServiceNames
)
}
changes
.
items
=
make
(
map
[
types
.
NamespacedName
]
*
endpointsChange
)
...
...
@@ -307,23 +307,23 @@ func (em EndpointsMap) apply(changes *EndpointChangeTracker, staleEndpoints *[]S
}
// Merge ensures that the current EndpointsMap contains all <service, endpoints> pairs from the EndpointsMap passed in.
func
(
em
EndpointsMap
)
M
erge
(
other
EndpointsMap
)
{
func
(
em
EndpointsMap
)
m
erge
(
other
EndpointsMap
)
{
for
svcPortName
:=
range
other
{
em
[
svcPortName
]
=
other
[
svcPortName
]
}
}
// Unmerge removes the <service, endpoints> pairs from the current EndpointsMap which are contained in the EndpointsMap passed in.
func
(
em
EndpointsMap
)
U
nmerge
(
other
EndpointsMap
)
{
func
(
em
EndpointsMap
)
u
nmerge
(
other
EndpointsMap
)
{
for
svcPortName
:=
range
other
{
delete
(
em
,
svcPortName
)
}
}
// GetLocalEndpointIPs returns endpoints IPs if given endpoint is local - local means the endpoint is running in same host as kube-proxy.
func
GetLocalEndpointIPs
(
endpointsMap
EndpointsMap
)
map
[
types
.
NamespacedName
]
sets
.
String
{
func
(
em
EndpointsMap
)
getLocalEndpointIPs
(
)
map
[
types
.
NamespacedName
]
sets
.
String
{
localIPs
:=
make
(
map
[
types
.
NamespacedName
]
sets
.
String
)
for
svcPortName
,
epList
:=
range
e
ndpointsMap
{
for
svcPortName
,
epList
:=
range
e
m
{
for
_
,
ep
:=
range
epList
{
if
ep
.
GetIsLocal
()
{
nsn
:=
svcPortName
.
NamespacedName
...
...
pkg/proxy/endpoints_test.go
View file @
929adb69
...
...
@@ -112,7 +112,7 @@ func TestGetLocalEndpointIPs(t *testing.T) {
for
tci
,
tc
:=
range
testCases
{
// outputs
localIPs
:=
GetLocalEndpointIPs
(
tc
.
endpointsMap
)
localIPs
:=
tc
.
endpointsMap
.
getLocalEndpointIPs
(
)
if
!
reflect
.
DeepEqual
(
localIPs
,
tc
.
expected
)
{
t
.
Errorf
(
"[%d] expected %#v, got %#v"
,
tci
,
tc
.
expected
,
localIPs
)
...
...
@@ -1213,7 +1213,7 @@ func TestUpdateEndpointsMap(t *testing.T) {
fp
.
addEndpoints
(
tc
.
previousEndpoints
[
i
])
}
}
UpdateEndpointsMap
(
fp
.
endpointsMap
,
fp
.
endpointsChanges
)
fp
.
endpointsMap
.
Update
(
fp
.
endpointsChanges
)
compareEndpointsMaps
(
t
,
tci
,
fp
.
endpointsMap
,
tc
.
oldEndpoints
)
// Now let's call appropriate handlers to get to state we want to be.
...
...
@@ -1233,7 +1233,7 @@ func TestUpdateEndpointsMap(t *testing.T) {
fp
.
updateEndpoints
(
prev
,
curr
)
}
}
result
:=
UpdateEndpointsMap
(
fp
.
endpointsMap
,
fp
.
endpointsChanges
)
result
:=
fp
.
endpointsMap
.
Update
(
fp
.
endpointsChanges
)
newMap
:=
fp
.
endpointsMap
compareEndpointsMaps
(
t
,
tci
,
newMap
,
tc
.
expectedResult
)
if
len
(
result
.
StaleEndpoints
)
!=
len
(
tc
.
expectedStaleEndpoints
)
{
...
...
@@ -1373,7 +1373,7 @@ func TestLastChangeTriggerTime(t *testing.T) {
tc
.
scenario
(
fp
)
result
:=
UpdateEndpointsMap
(
fp
.
endpointsMap
,
fp
.
endpointsChanges
)
result
:=
fp
.
endpointsMap
.
Update
(
fp
.
endpointsChanges
)
got
:=
result
.
LastChangeTriggerTimes
sortTimeSlice
(
got
)
sortTimeSlice
(
tc
.
expected
)
...
...
pkg/proxy/iptables/proxier.go
View file @
929adb69
...
...
@@ -684,7 +684,7 @@ func (proxier *Proxier) syncProxyRules() {
// even if nothing changed in the meantime. In other words, callers are
// responsible for detecting no-op changes and not calling this function.
serviceUpdateResult
:=
proxy
.
UpdateServiceMap
(
proxier
.
serviceMap
,
proxier
.
serviceChanges
)
endpointUpdateResult
:=
prox
y
.
UpdateEndpointsMap
(
proxier
.
endpointsMap
,
proxier
.
endpointsChanges
)
endpointUpdateResult
:=
prox
ier
.
endpointsMap
.
Update
(
proxier
.
endpointsChanges
)
staleServices
:=
serviceUpdateResult
.
UDPStaleClusterIP
// merge stale services gathered from updateEndpointsMap
...
...
pkg/proxy/iptables/proxier_test.go
View file @
929adb69
...
...
@@ -2185,7 +2185,7 @@ func Test_updateEndpointsMap(t *testing.T) {
fp
.
OnEndpointsAdd
(
tc
.
previousEndpoints
[
i
])
}
}
proxy
.
UpdateEndpointsMap
(
fp
.
endpointsMap
,
fp
.
endpointsChanges
)
fp
.
endpointsMap
.
Update
(
fp
.
endpointsChanges
)
compareEndpointsMaps
(
t
,
tci
,
fp
.
endpointsMap
,
tc
.
oldEndpoints
)
// Now let's call appropriate handlers to get to state we want to be.
...
...
@@ -2205,7 +2205,7 @@ func Test_updateEndpointsMap(t *testing.T) {
fp
.
OnEndpointsUpdate
(
prev
,
curr
)
}
}
result
:=
proxy
.
UpdateEndpointsMap
(
fp
.
endpointsMap
,
fp
.
endpointsChanges
)
result
:=
fp
.
endpointsMap
.
Update
(
fp
.
endpointsChanges
)
newMap
:=
fp
.
endpointsMap
compareEndpointsMaps
(
t
,
tci
,
newMap
,
tc
.
expectedResult
)
if
len
(
result
.
StaleEndpoints
)
!=
len
(
tc
.
expectedStaleEndpoints
)
{
...
...
pkg/proxy/ipvs/proxier.go
View file @
929adb69
...
...
@@ -753,7 +753,7 @@ func (proxier *Proxier) syncProxyRules() {
// even if nothing changed in the meantime. In other words, callers are
// responsible for detecting no-op changes and not calling this function.
serviceUpdateResult
:=
proxy
.
UpdateServiceMap
(
proxier
.
serviceMap
,
proxier
.
serviceChanges
)
endpointUpdateResult
:=
prox
y
.
UpdateEndpointsMap
(
proxier
.
endpointsMap
,
proxier
.
endpointsChanges
)
endpointUpdateResult
:=
prox
ier
.
endpointsMap
.
Update
(
proxier
.
endpointsChanges
)
staleServices
:=
serviceUpdateResult
.
UDPStaleClusterIP
// merge stale services gathered from updateEndpointsMap
...
...
pkg/proxy/ipvs/proxier_test.go
View file @
929adb69
...
...
@@ -2486,7 +2486,7 @@ func Test_updateEndpointsMap(t *testing.T) {
fp
.
OnEndpointsAdd
(
tc
.
previousEndpoints
[
i
])
}
}
proxy
.
UpdateEndpointsMap
(
fp
.
endpointsMap
,
fp
.
endpointsChanges
)
fp
.
endpointsMap
.
Update
(
fp
.
endpointsChanges
)
compareEndpointsMaps
(
t
,
tci
,
fp
.
endpointsMap
,
tc
.
oldEndpoints
)
// Now let's call appropriate handlers to get to state we want to be.
...
...
@@ -2506,7 +2506,7 @@ func Test_updateEndpointsMap(t *testing.T) {
fp
.
OnEndpointsUpdate
(
prev
,
curr
)
}
}
result
:=
proxy
.
UpdateEndpointsMap
(
fp
.
endpointsMap
,
fp
.
endpointsChanges
)
result
:=
fp
.
endpointsMap
.
Update
(
fp
.
endpointsChanges
)
newMap
:=
fp
.
endpointsMap
compareEndpointsMaps
(
t
,
tci
,
newMap
,
tc
.
expectedResult
)
if
len
(
result
.
StaleEndpoints
)
!=
len
(
tc
.
expectedStaleEndpoints
)
{
...
...
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