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
b38c25eb
Commit
b38c25eb
authored
Jan 09, 2015
by
Clayton Coleman
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Shorten scheduler/factory test by making backoff a struct var
parent
e67786b2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
20 additions
and
11 deletions
+20
-11
factory.go
plugin/pkg/scheduler/factory/factory.go
+12
-7
factory_test.go
plugin/pkg/scheduler/factory/factory_test.go
+8
-4
No files found.
plugin/pkg/scheduler/factory/factory.go
View file @
b38c25eb
...
...
@@ -112,6 +112,9 @@ func (f *ConfigFactory) CreateFromKeys(predicateKeys, priorityKeys util.StringSe
podBackoff
:=
podBackoff
{
perPodBackoff
:
map
[
string
]
*
backoffEntry
{},
clock
:
realClock
{},
defaultDuration
:
1
*
time
.
Second
,
maxDuration
:
60
*
time
.
Second
,
}
return
&
scheduler
.
Config
{
...
...
@@ -245,9 +248,11 @@ type backoffEntry struct {
}
type
podBackoff
struct
{
perPodBackoff
map
[
string
]
*
backoffEntry
lock
sync
.
Mutex
clock
clock
perPodBackoff
map
[
string
]
*
backoffEntry
lock
sync
.
Mutex
clock
clock
defaultDuration
time
.
Duration
maxDuration
time
.
Duration
}
func
(
p
*
podBackoff
)
getEntry
(
podID
string
)
*
backoffEntry
{
...
...
@@ -255,7 +260,7 @@ func (p *podBackoff) getEntry(podID string) *backoffEntry {
defer
p
.
lock
.
Unlock
()
entry
,
ok
:=
p
.
perPodBackoff
[
podID
]
if
!
ok
{
entry
=
&
backoffEntry
{
backoff
:
1
*
time
.
Second
}
entry
=
&
backoffEntry
{
backoff
:
p
.
defaultDuration
}
p
.
perPodBackoff
[
podID
]
=
entry
}
entry
.
lastUpdate
=
p
.
clock
.
Now
()
...
...
@@ -266,8 +271,8 @@ func (p *podBackoff) getBackoff(podID string) time.Duration {
entry
:=
p
.
getEntry
(
podID
)
duration
:=
entry
.
backoff
entry
.
backoff
*=
2
if
entry
.
backoff
>
60
*
time
.
Second
{
entry
.
backoff
=
60
*
time
.
Second
if
entry
.
backoff
>
p
.
maxDuration
{
entry
.
backoff
=
p
.
maxDuration
}
glog
.
V
(
4
)
.
Infof
(
"Backing off %s for pod %s"
,
duration
.
String
(),
podID
)
return
duration
...
...
@@ -282,7 +287,7 @@ func (p *podBackoff) gc() {
defer
p
.
lock
.
Unlock
()
now
:=
p
.
clock
.
Now
()
for
podID
,
entry
:=
range
p
.
perPodBackoff
{
if
now
.
Sub
(
entry
.
lastUpdate
)
>
60
*
time
.
Second
{
if
now
.
Sub
(
entry
.
lastUpdate
)
>
p
.
maxDuration
{
delete
(
p
.
perPodBackoff
,
podID
)
}
}
...
...
plugin/pkg/scheduler/factory/factory_test.go
View file @
b38c25eb
...
...
@@ -118,8 +118,10 @@ func TestDefaultErrorFunc(t *testing.T) {
factory
:=
NewConfigFactory
(
client
.
NewOrDie
(
&
client
.
Config
{
Host
:
server
.
URL
,
Version
:
testapi
.
Version
()}))
queue
:=
cache
.
NewFIFO
()
podBackoff
:=
podBackoff
{
perPodBackoff
:
map
[
string
]
*
backoffEntry
{},
clock
:
&
fakeClock
{},
perPodBackoff
:
map
[
string
]
*
backoffEntry
{},
clock
:
&
fakeClock
{},
defaultDuration
:
1
*
time
.
Millisecond
,
maxDuration
:
1
*
time
.
Second
,
}
errFunc
:=
factory
.
makeDefaultErrorFunc
(
&
podBackoff
,
queue
)
...
...
@@ -203,8 +205,10 @@ func TestBind(t *testing.T) {
func
TestBackoff
(
t
*
testing
.
T
)
{
clock
:=
fakeClock
{}
backoff
:=
podBackoff
{
perPodBackoff
:
map
[
string
]
*
backoffEntry
{},
clock
:
&
clock
,
perPodBackoff
:
map
[
string
]
*
backoffEntry
{},
clock
:
&
clock
,
defaultDuration
:
1
*
time
.
Second
,
maxDuration
:
60
*
time
.
Second
,
}
tests
:=
[]
struct
{
...
...
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