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
79e54c26
Commit
79e54c26
authored
Jun 29, 2015
by
Dr. Stefan Schimanski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add unit tests for RepackSubsets to take pod UID into consideration
parent
55daf3b8
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
98 additions
and
3 deletions
+98
-3
util.go
pkg/api/endpoints/util.go
+3
-3
util_test.go
pkg/api/endpoints/util_test.go
+95
-0
No files found.
pkg/api/endpoints/util.go
View file @
79e54c26
...
@@ -36,7 +36,7 @@ func RepackSubsets(subsets []api.EndpointSubset) []api.EndpointSubset {
...
@@ -36,7 +36,7 @@ func RepackSubsets(subsets []api.EndpointSubset) []api.EndpointSubset {
// First map each unique port definition to the sets of hosts that
// First map each unique port definition to the sets of hosts that
// offer it. The sets of hosts must be de-duped, using IP+UID as the key.
// offer it. The sets of hosts must be de-duped, using IP+UID as the key.
type
addressKey
struct
{
type
addressKey
struct
{
ip
string
ip
string
uid
types
.
UID
uid
types
.
UID
}
}
allAddrs
:=
map
[
addressKey
]
*
api
.
EndpointAddress
{}
allAddrs
:=
map
[
addressKey
]
*
api
.
EndpointAddress
{}
...
@@ -120,10 +120,10 @@ func LessEndpointAddress(a, b *api.EndpointAddress) bool {
...
@@ -120,10 +120,10 @@ func LessEndpointAddress(a, b *api.EndpointAddress) bool {
if
ipComparison
!=
0
{
if
ipComparison
!=
0
{
return
ipComparison
<
0
return
ipComparison
<
0
}
}
if
(
b
.
TargetRef
==
nil
)
{
if
b
.
TargetRef
==
nil
{
return
false
return
false
}
}
if
(
a
.
TargetRef
==
nil
)
{
if
a
.
TargetRef
==
nil
{
return
true
return
true
}
}
return
a
.
TargetRef
.
UID
<
b
.
TargetRef
.
UID
return
a
.
TargetRef
.
UID
<
b
.
TargetRef
.
UID
...
...
pkg/api/endpoints/util_test.go
View file @
79e54c26
...
@@ -22,8 +22,14 @@ import (
...
@@ -22,8 +22,14 @@ import (
"github.com/davecgh/go-spew/spew"
"github.com/davecgh/go-spew/spew"
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/types"
)
)
func
podRef
(
uid
string
)
*
api
.
ObjectReference
{
ref
:=
api
.
ObjectReference
{
UID
:
types
.
UID
(
uid
)}
return
&
ref
}
func
TestPackSubsets
(
t
*
testing
.
T
)
{
func
TestPackSubsets
(
t
*
testing
.
T
)
{
// The downside of table-driven tests is that some things have to live outside the table.
// The downside of table-driven tests is that some things have to live outside the table.
fooObjRef
:=
api
.
ObjectReference
{
Name
:
"foo"
}
fooObjRef
:=
api
.
ObjectReference
{
Name
:
"foo"
}
...
@@ -57,6 +63,26 @@ func TestPackSubsets(t *testing.T) {
...
@@ -57,6 +63,26 @@ func TestPackSubsets(t *testing.T) {
Ports
:
[]
api
.
EndpointPort
{{
Port
:
111
}},
Ports
:
[]
api
.
EndpointPort
{{
Port
:
111
}},
}},
}},
},
{
},
{
name
:
"one set, one ip, one UID, one port"
,
given
:
[]
api
.
EndpointSubset
{{
Addresses
:
[]
api
.
EndpointAddress
{{
IP
:
"1.2.3.4"
,
TargetRef
:
podRef
(
"uid-1"
)}},
Ports
:
[]
api
.
EndpointPort
{{
Port
:
111
}},
}},
expect
:
[]
api
.
EndpointSubset
{{
Addresses
:
[]
api
.
EndpointAddress
{{
IP
:
"1.2.3.4"
,
TargetRef
:
podRef
(
"uid-1"
)}},
Ports
:
[]
api
.
EndpointPort
{{
Port
:
111
}},
}},
},
{
name
:
"one set, one ip, empty UID, one port"
,
given
:
[]
api
.
EndpointSubset
{{
Addresses
:
[]
api
.
EndpointAddress
{{
IP
:
"1.2.3.4"
,
TargetRef
:
podRef
(
""
)}},
Ports
:
[]
api
.
EndpointPort
{{
Port
:
111
}},
}},
expect
:
[]
api
.
EndpointSubset
{{
Addresses
:
[]
api
.
EndpointAddress
{{
IP
:
"1.2.3.4"
,
TargetRef
:
podRef
(
""
)}},
Ports
:
[]
api
.
EndpointPort
{{
Port
:
111
}},
}},
},
{
name
:
"one set, two ips, one port"
,
name
:
"one set, two ips, one port"
,
given
:
[]
api
.
EndpointSubset
{{
given
:
[]
api
.
EndpointSubset
{{
Addresses
:
[]
api
.
EndpointAddress
{{
IP
:
"1.2.3.4"
},
{
IP
:
"5.6.7.8"
}},
Addresses
:
[]
api
.
EndpointAddress
{{
IP
:
"1.2.3.4"
},
{
IP
:
"5.6.7.8"
}},
...
@@ -136,6 +162,19 @@ func TestPackSubsets(t *testing.T) {
...
@@ -136,6 +162,19 @@ func TestPackSubsets(t *testing.T) {
Ports
:
[]
api
.
EndpointPort
{{
Port
:
111
},
{
Port
:
222
}},
Ports
:
[]
api
.
EndpointPort
{{
Port
:
111
},
{
Port
:
222
}},
}},
}},
},
{
},
{
name
:
"two sets, dup ip, dup uids, two ports"
,
given
:
[]
api
.
EndpointSubset
{{
Addresses
:
[]
api
.
EndpointAddress
{{
IP
:
"1.2.3.4"
,
TargetRef
:
podRef
(
"uid-1"
)}},
Ports
:
[]
api
.
EndpointPort
{{
Port
:
111
}},
},
{
Addresses
:
[]
api
.
EndpointAddress
{{
IP
:
"1.2.3.4"
,
TargetRef
:
podRef
(
"uid-1"
)}},
Ports
:
[]
api
.
EndpointPort
{{
Port
:
222
}},
}},
expect
:
[]
api
.
EndpointSubset
{{
Addresses
:
[]
api
.
EndpointAddress
{{
IP
:
"1.2.3.4"
,
TargetRef
:
podRef
(
"uid-1"
)}},
Ports
:
[]
api
.
EndpointPort
{{
Port
:
111
},
{
Port
:
222
}},
}},
},
{
name
:
"two sets, two ips, dup port"
,
name
:
"two sets, two ips, dup port"
,
given
:
[]
api
.
EndpointSubset
{{
given
:
[]
api
.
EndpointSubset
{{
Addresses
:
[]
api
.
EndpointAddress
{{
IP
:
"1.2.3.4"
}},
Addresses
:
[]
api
.
EndpointAddress
{{
IP
:
"1.2.3.4"
}},
...
@@ -149,6 +188,62 @@ func TestPackSubsets(t *testing.T) {
...
@@ -149,6 +188,62 @@ func TestPackSubsets(t *testing.T) {
Ports
:
[]
api
.
EndpointPort
{{
Port
:
111
}},
Ports
:
[]
api
.
EndpointPort
{{
Port
:
111
}},
}},
}},
},
{
},
{
name
:
"two set, dup ip, two uids, dup ports"
,
given
:
[]
api
.
EndpointSubset
{{
Addresses
:
[]
api
.
EndpointAddress
{{
IP
:
"1.2.3.4"
,
TargetRef
:
podRef
(
"uid-1"
)}},
Ports
:
[]
api
.
EndpointPort
{{
Port
:
111
}},
},
{
Addresses
:
[]
api
.
EndpointAddress
{{
IP
:
"1.2.3.4"
,
TargetRef
:
podRef
(
"uid-2"
)}},
Ports
:
[]
api
.
EndpointPort
{{
Port
:
111
}},
}},
expect
:
[]
api
.
EndpointSubset
{{
Addresses
:
[]
api
.
EndpointAddress
{
{
IP
:
"1.2.3.4"
,
TargetRef
:
podRef
(
"uid-1"
)},
{
IP
:
"1.2.3.4"
,
TargetRef
:
podRef
(
"uid-2"
)},
},
Ports
:
[]
api
.
EndpointPort
{{
Port
:
111
}},
}},
},
{
name
:
"two set, dup ip, with and without uid, dup ports"
,
given
:
[]
api
.
EndpointSubset
{{
Addresses
:
[]
api
.
EndpointAddress
{{
IP
:
"1.2.3.4"
}},
Ports
:
[]
api
.
EndpointPort
{{
Port
:
111
}},
},
{
Addresses
:
[]
api
.
EndpointAddress
{{
IP
:
"1.2.3.4"
,
TargetRef
:
podRef
(
"uid-2"
)}},
Ports
:
[]
api
.
EndpointPort
{{
Port
:
111
}},
}},
expect
:
[]
api
.
EndpointSubset
{{
Addresses
:
[]
api
.
EndpointAddress
{
{
IP
:
"1.2.3.4"
},
{
IP
:
"1.2.3.4"
,
TargetRef
:
podRef
(
"uid-2"
)},
},
Ports
:
[]
api
.
EndpointPort
{{
Port
:
111
}},
}},
},
{
name
:
"two sets, two ips, two dup ip with uid, dup port, wrong order"
,
given
:
[]
api
.
EndpointSubset
{{
Addresses
:
[]
api
.
EndpointAddress
{{
IP
:
"5.6.7.8"
}},
Ports
:
[]
api
.
EndpointPort
{{
Port
:
111
}},
},
{
Addresses
:
[]
api
.
EndpointAddress
{{
IP
:
"5.6.7.8"
,
TargetRef
:
podRef
(
"uid-1"
)}},
Ports
:
[]
api
.
EndpointPort
{{
Port
:
111
}},
},
{
Addresses
:
[]
api
.
EndpointAddress
{{
IP
:
"1.2.3.4"
,
TargetRef
:
podRef
(
"uid-1"
)}},
Ports
:
[]
api
.
EndpointPort
{{
Port
:
111
}},
},
{
Addresses
:
[]
api
.
EndpointAddress
{{
IP
:
"1.2.3.4"
}},
Ports
:
[]
api
.
EndpointPort
{{
Port
:
111
}},
}},
expect
:
[]
api
.
EndpointSubset
{{
Addresses
:
[]
api
.
EndpointAddress
{
{
IP
:
"1.2.3.4"
},
{
IP
:
"1.2.3.4"
,
TargetRef
:
podRef
(
"uid-1"
)},
{
IP
:
"5.6.7.8"
},
{
IP
:
"5.6.7.8"
,
TargetRef
:
podRef
(
"uid-1"
)},
},
Ports
:
[]
api
.
EndpointPort
{{
Port
:
111
}},
}},
},
{
name
:
"two sets, two ips, two ports"
,
name
:
"two sets, two ips, two ports"
,
given
:
[]
api
.
EndpointSubset
{{
given
:
[]
api
.
EndpointSubset
{{
Addresses
:
[]
api
.
EndpointAddress
{{
IP
:
"1.2.3.4"
}},
Addresses
:
[]
api
.
EndpointAddress
{{
IP
:
"1.2.3.4"
}},
...
...
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