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
90ebc1ad
Commit
90ebc1ad
authored
Jun 26, 2015
by
Prashanth Balasubramanian
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Sort overlapping rcs
parent
29a55cc8
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
61 additions
and
0 deletions
+61
-0
controller_utils.go
pkg/controller/controller_utils.go
+13
-0
replication_controller.go
pkg/controller/replication_controller.go
+1
-0
replication_controller_test.go
pkg/controller/replication_controller_test.go
+42
-0
time.go
pkg/util/time.go
+5
-0
No files found.
pkg/controller/controller_utils.go
View file @
90ebc1ad
...
@@ -289,6 +289,19 @@ func (s activePods) Less(i, j int) bool {
...
@@ -289,6 +289,19 @@ func (s activePods) Less(i, j int) bool {
return
false
return
false
}
}
// overlappingControllers sorts a list of controllers by creation timestamp, using their names as a tie breaker.
type
overlappingControllers
[]
api
.
ReplicationController
func
(
o
overlappingControllers
)
Len
()
int
{
return
len
(
o
)
}
func
(
o
overlappingControllers
)
Swap
(
i
,
j
int
)
{
o
[
i
],
o
[
j
]
=
o
[
j
],
o
[
i
]
}
func
(
o
overlappingControllers
)
Less
(
i
,
j
int
)
bool
{
if
o
[
i
]
.
CreationTimestamp
.
Equal
(
o
[
j
]
.
CreationTimestamp
)
{
return
o
[
i
]
.
Name
<
o
[
j
]
.
Name
}
return
o
[
i
]
.
CreationTimestamp
.
Before
(
o
[
j
]
.
CreationTimestamp
)
}
// filterActivePods returns pods that have not terminated.
// filterActivePods returns pods that have not terminated.
func
filterActivePods
(
pods
[]
api
.
Pod
)
[]
*
api
.
Pod
{
func
filterActivePods
(
pods
[]
api
.
Pod
)
[]
*
api
.
Pod
{
var
result
[]
*
api
.
Pod
var
result
[]
*
api
.
Pod
...
...
pkg/controller/replication_controller.go
View file @
90ebc1ad
...
@@ -209,6 +209,7 @@ func (rm *ReplicationManager) getPodControllers(pod *api.Pod) *api.ReplicationCo
...
@@ -209,6 +209,7 @@ func (rm *ReplicationManager) getPodControllers(pod *api.Pod) *api.ReplicationCo
glog
.
V
(
4
)
.
Infof
(
"No controllers found for pod %v, replication manager will avoid syncing"
,
pod
.
Name
)
glog
.
V
(
4
)
.
Infof
(
"No controllers found for pod %v, replication manager will avoid syncing"
,
pod
.
Name
)
return
nil
return
nil
}
}
sort
.
Sort
(
overlappingControllers
(
controllers
))
return
&
controllers
[
0
]
return
&
controllers
[
0
]
}
}
...
...
pkg/controller/replication_controller_test.go
View file @
90ebc1ad
...
@@ -1108,3 +1108,45 @@ func TestRCManagerNotReady(t *testing.T) {
...
@@ -1108,3 +1108,45 @@ func TestRCManagerNotReady(t *testing.T) {
manager
.
syncReplicationController
(
rcKey
)
manager
.
syncReplicationController
(
rcKey
)
validateSyncReplication
(
t
,
&
fakePodControl
,
1
,
0
)
validateSyncReplication
(
t
,
&
fakePodControl
,
1
,
0
)
}
}
// shuffle returns a new shuffled list of container controllers.
func
shuffle
(
controllers
[]
*
api
.
ReplicationController
)
[]
*
api
.
ReplicationController
{
numControllers
:=
len
(
controllers
)
randIndexes
:=
rand
.
Perm
(
numControllers
)
shuffled
:=
make
([]
*
api
.
ReplicationController
,
numControllers
)
for
i
:=
0
;
i
<
numControllers
;
i
++
{
shuffled
[
i
]
=
controllers
[
randIndexes
[
i
]]
}
return
shuffled
}
func
TestOverlappingRCs
(
t
*
testing
.
T
)
{
client
:=
client
.
NewOrDie
(
&
client
.
Config
{
Host
:
""
,
Version
:
testapi
.
Version
()})
for
i
:=
0
;
i
<
5
;
i
++
{
manager
:=
NewReplicationManager
(
client
,
10
)
manager
.
podStoreSynced
=
alwaysReady
// Create 10 rcs, shuffled them randomly and insert them into the rc manager's store
var
controllers
[]
*
api
.
ReplicationController
for
j
:=
1
;
j
<
10
;
j
++
{
controllerSpec
:=
newReplicationController
(
1
)
controllerSpec
.
CreationTimestamp
=
util
.
Date
(
2014
,
time
.
December
,
j
,
0
,
0
,
0
,
0
,
time
.
Local
)
controllerSpec
.
Name
=
string
(
util
.
NewUUID
())
controllers
=
append
(
controllers
,
controllerSpec
)
}
shuffledControllers
:=
shuffle
(
controllers
)
for
j
,
_
:=
range
shuffledControllers
{
manager
.
controllerStore
.
Store
.
Add
(
shuffledControllers
[
j
])
}
// Add a pod and make sure only the oldest rc is synced
pods
:=
newPodList
(
nil
,
1
,
api
.
PodPending
,
controllers
[
0
])
rcKey
:=
getKey
(
controllers
[
0
],
t
)
manager
.
addPod
(
&
pods
.
Items
[
0
])
queueRC
,
_
:=
manager
.
queue
.
Get
()
if
queueRC
!=
rcKey
{
t
.
Fatalf
(
"Expected to find key %v in queue, found %v"
,
rcKey
,
queueRC
)
}
}
}
pkg/util/time.go
View file @
90ebc1ad
...
@@ -59,6 +59,11 @@ func (t Time) Before(u Time) bool {
...
@@ -59,6 +59,11 @@ func (t Time) Before(u Time) bool {
return
t
.
Time
.
Before
(
u
.
Time
)
return
t
.
Time
.
Before
(
u
.
Time
)
}
}
// Equal reports whether the time instant t is equal to u.
func
(
t
Time
)
Equal
(
u
Time
)
bool
{
return
t
.
Time
.
Equal
(
u
.
Time
)
}
// Unix returns the local time corresponding to the given Unix time
// Unix returns the local time corresponding to the given Unix time
// by wrapping time.Unix.
// by wrapping time.Unix.
func
Unix
(
sec
int64
,
nsec
int64
)
Time
{
func
Unix
(
sec
int64
,
nsec
int64
)
Time
{
...
...
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