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
d141a43d
Commit
d141a43d
authored
Jan 07, 2017
by
peay
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Do not list CronJob unmet starting times beyond deadline
parent
de59ede6
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
71 additions
and
10 deletions
+71
-10
cronjob_controller_test.go
pkg/controller/cronjob/cronjob_controller_test.go
+48
-8
utils.go
pkg/controller/cronjob/utils.go
+9
-1
utils_test.go
pkg/controller/cronjob/utils_test.go
+14
-1
No files found.
pkg/controller/cronjob/cronjob_controller_test.go
View file @
d141a43d
...
@@ -56,6 +56,14 @@ func justAfterTheHour() time.Time {
...
@@ -56,6 +56,14 @@ func justAfterTheHour() time.Time {
return
T1
return
T1
}
}
func
weekAfterTheHour
()
time
.
Time
{
T1
,
err
:=
time
.
Parse
(
time
.
RFC3339
,
"2016-05-26T10:00:00Z"
)
if
err
!=
nil
{
panic
(
"test setup error"
)
}
return
T1
}
func
justBeforeThePriorHour
()
time
.
Time
{
func
justBeforeThePriorHour
()
time
.
Time
{
T1
,
err
:=
time
.
Parse
(
time
.
RFC3339
,
"2016-05-19T08:59:00Z"
)
T1
,
err
:=
time
.
Parse
(
time
.
RFC3339
,
"2016-05-19T08:59:00Z"
)
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -129,17 +137,31 @@ func newJob(UID string) batch.Job {
...
@@ -129,17 +137,31 @@ func newJob(UID string) batch.Job {
}
}
var
(
var
(
shortDead
int64
=
10
shortDead
int64
=
10
longDead
int64
=
1000000
mediumDead
int64
=
2
*
60
*
60
noDead
int64
=
-
12345
longDead
int64
=
1000000
A
batch
.
ConcurrencyPolicy
=
batch
.
AllowConcurrent
noDead
int64
=
-
12345
f
batch
.
ConcurrencyPolicy
=
batch
.
ForbidConcurrent
A
batch
.
ConcurrencyPolicy
=
batch
.
AllowConcurrent
R
batch
.
ConcurrencyPolicy
=
batch
.
ReplaceConcurrent
f
batch
.
ConcurrencyPolicy
=
batch
.
ForbidConcurrent
T
bool
=
true
R
batch
.
ConcurrencyPolicy
=
batch
.
ReplaceConcurrent
F
bool
=
false
T
bool
=
true
F
bool
=
false
)
)
func
TestSyncOne_RunOrNot
(
t
*
testing
.
T
)
{
func
TestSyncOne_RunOrNot
(
t
*
testing
.
T
)
{
// Check expectations on deadline parameters
if
shortDead
/
60
/
60
>=
1
{
t
.
Errorf
(
"shortDead should be less than one hour"
)
}
if
mediumDead
/
60
/
60
<
1
||
mediumDead
/
60
/
60
>=
24
{
t
.
Errorf
(
"mediumDead should be between one hour and one day"
)
}
if
longDead
/
60
/
60
/
24
<
10
{
t
.
Errorf
(
"longDead should be at least ten days"
)
}
testCases
:=
map
[
string
]
struct
{
testCases
:=
map
[
string
]
struct
{
// sj spec
// sj spec
concurrencyPolicy
batch
.
ConcurrencyPolicy
concurrencyPolicy
batch
.
ConcurrencyPolicy
...
@@ -188,6 +210,24 @@ func TestSyncOne_RunOrNot(t *testing.T) {
...
@@ -188,6 +210,24 @@ func TestSyncOne_RunOrNot(t *testing.T) {
"still active, is time, suspended"
:
{
A
,
T
,
onTheHour
,
noDead
,
T
,
T
,
justAfterTheHour
(),
F
,
F
,
1
},
"still active, is time, suspended"
:
{
A
,
T
,
onTheHour
,
noDead
,
T
,
T
,
justAfterTheHour
(),
F
,
F
,
1
},
"still active, is time, past deadline"
:
{
A
,
F
,
onTheHour
,
shortDead
,
T
,
T
,
justAfterTheHour
(),
F
,
F
,
1
},
"still active, is time, past deadline"
:
{
A
,
F
,
onTheHour
,
shortDead
,
T
,
T
,
justAfterTheHour
(),
F
,
F
,
1
},
"still active, is time, not past deadline"
:
{
A
,
F
,
onTheHour
,
longDead
,
T
,
T
,
justAfterTheHour
(),
T
,
F
,
2
},
"still active, is time, not past deadline"
:
{
A
,
F
,
onTheHour
,
longDead
,
T
,
T
,
justAfterTheHour
(),
T
,
F
,
2
},
// Controller should fail to schedule these, as there are too many missed starting times
// and either no deadline or a too long deadline.
"prev ran but done, long overdue, not past deadline, A"
:
{
A
,
F
,
onTheHour
,
longDead
,
T
,
F
,
weekAfterTheHour
(),
F
,
F
,
0
},
"prev ran but done, long overdue, not past deadline, R"
:
{
R
,
F
,
onTheHour
,
longDead
,
T
,
F
,
weekAfterTheHour
(),
F
,
F
,
0
},
"prev ran but done, long overdue, not past deadline, F"
:
{
f
,
F
,
onTheHour
,
longDead
,
T
,
F
,
weekAfterTheHour
(),
F
,
F
,
0
},
"prev ran but done, long overdue, no deadline, A"
:
{
A
,
F
,
onTheHour
,
noDead
,
T
,
F
,
weekAfterTheHour
(),
F
,
F
,
0
},
"prev ran but done, long overdue, no deadline, R"
:
{
R
,
F
,
onTheHour
,
noDead
,
T
,
F
,
weekAfterTheHour
(),
F
,
F
,
0
},
"prev ran but done, long overdue, no deadline, F"
:
{
f
,
F
,
onTheHour
,
noDead
,
T
,
F
,
weekAfterTheHour
(),
F
,
F
,
0
},
"prev ran but done, long overdue, past medium deadline, A"
:
{
A
,
F
,
onTheHour
,
mediumDead
,
T
,
F
,
weekAfterTheHour
(),
T
,
F
,
1
},
"prev ran but done, long overdue, past short deadline, A"
:
{
A
,
F
,
onTheHour
,
shortDead
,
T
,
F
,
weekAfterTheHour
(),
T
,
F
,
1
},
"prev ran but done, long overdue, past medium deadline, R"
:
{
R
,
F
,
onTheHour
,
mediumDead
,
T
,
F
,
weekAfterTheHour
(),
T
,
F
,
1
},
"prev ran but done, long overdue, past short deadline, R"
:
{
R
,
F
,
onTheHour
,
shortDead
,
T
,
F
,
weekAfterTheHour
(),
T
,
F
,
1
},
"prev ran but done, long overdue, past medium deadline, F"
:
{
f
,
F
,
onTheHour
,
mediumDead
,
T
,
F
,
weekAfterTheHour
(),
T
,
F
,
1
},
"prev ran but done, long overdue, past short deadline, F"
:
{
f
,
F
,
onTheHour
,
shortDead
,
T
,
F
,
weekAfterTheHour
(),
T
,
F
,
1
},
}
}
for
name
,
tc
:=
range
testCases
{
for
name
,
tc
:=
range
testCases
{
sj
:=
cronJob
()
sj
:=
cronJob
()
...
...
pkg/controller/cronjob/utils.go
View file @
d141a43d
...
@@ -125,6 +125,7 @@ func getRecentUnmetScheduleTimes(sj batch.CronJob, now time.Time) ([]time.Time,
...
@@ -125,6 +125,7 @@ func getRecentUnmetScheduleTimes(sj batch.CronJob, now time.Time) ([]time.Time,
if
err
!=
nil
{
if
err
!=
nil
{
return
starts
,
fmt
.
Errorf
(
"Unparseable schedule: %s : %s"
,
sj
.
Spec
.
Schedule
,
err
)
return
starts
,
fmt
.
Errorf
(
"Unparseable schedule: %s : %s"
,
sj
.
Spec
.
Schedule
,
err
)
}
}
var
earliestTime
time
.
Time
var
earliestTime
time
.
Time
if
sj
.
Status
.
LastScheduleTime
!=
nil
{
if
sj
.
Status
.
LastScheduleTime
!=
nil
{
earliestTime
=
sj
.
Status
.
LastScheduleTime
.
Time
earliestTime
=
sj
.
Status
.
LastScheduleTime
.
Time
...
@@ -137,7 +138,14 @@ func getRecentUnmetScheduleTimes(sj batch.CronJob, now time.Time) ([]time.Time,
...
@@ -137,7 +138,14 @@ func getRecentUnmetScheduleTimes(sj batch.CronJob, now time.Time) ([]time.Time,
// CronJob as last known start time.
// CronJob as last known start time.
earliestTime
=
sj
.
ObjectMeta
.
CreationTimestamp
.
Time
earliestTime
=
sj
.
ObjectMeta
.
CreationTimestamp
.
Time
}
}
if
sj
.
Spec
.
StartingDeadlineSeconds
!=
nil
{
// Controller is not going to schedule anything below this point
schedulingDeadline
:=
now
.
Add
(
-
time
.
Second
*
time
.
Duration
(
*
sj
.
Spec
.
StartingDeadlineSeconds
))
if
schedulingDeadline
.
After
(
earliestTime
)
{
earliestTime
=
schedulingDeadline
}
}
if
earliestTime
.
After
(
now
)
{
if
earliestTime
.
After
(
now
)
{
return
[]
time
.
Time
{},
nil
return
[]
time
.
Time
{},
nil
}
}
...
@@ -163,7 +171,7 @@ func getRecentUnmetScheduleTimes(sj batch.CronJob, now time.Time) ([]time.Time,
...
@@ -163,7 +171,7 @@ func getRecentUnmetScheduleTimes(sj batch.CronJob, now time.Time) ([]time.Time,
// but less than "lots".
// but less than "lots".
if
len
(
starts
)
>
100
{
if
len
(
starts
)
>
100
{
// We can't get the most recent times so just return an empty slice
// We can't get the most recent times so just return an empty slice
return
[]
time
.
Time
{},
fmt
.
Errorf
(
"Too many missed start time
s to list
"
)
return
[]
time
.
Time
{},
fmt
.
Errorf
(
"Too many missed start time
(> 100). Set or decrease .spec.startingDeadlineSeconds or check clock skew.
"
)
}
}
}
}
return
starts
,
nil
return
starts
,
nil
...
...
pkg/controller/cronjob/utils_test.go
View file @
d141a43d
...
@@ -367,7 +367,7 @@ func TestGetRecentUnmetScheduleTimes(t *testing.T) {
...
@@ -367,7 +367,7 @@ func TestGetRecentUnmetScheduleTimes(t *testing.T) {
}
}
}
}
{
{
// Case 6: now is way way ahead of last start time.
// Case 6: now is way way ahead of last start time
, and there is no deadline
.
sj
.
ObjectMeta
.
CreationTimestamp
=
metav1
.
Time
{
Time
:
T1
.
Add
(
-
2
*
time
.
Hour
)}
sj
.
ObjectMeta
.
CreationTimestamp
=
metav1
.
Time
{
Time
:
T1
.
Add
(
-
2
*
time
.
Hour
)}
sj
.
Status
.
LastScheduleTime
=
&
metav1
.
Time
{
Time
:
T1
.
Add
(
-
1
*
time
.
Hour
)}
sj
.
Status
.
LastScheduleTime
=
&
metav1
.
Time
{
Time
:
T1
.
Add
(
-
1
*
time
.
Hour
)}
now
:=
T2
.
Add
(
10
*
24
*
time
.
Hour
)
now
:=
T2
.
Add
(
10
*
24
*
time
.
Hour
)
...
@@ -376,5 +376,18 @@ func TestGetRecentUnmetScheduleTimes(t *testing.T) {
...
@@ -376,5 +376,18 @@ func TestGetRecentUnmetScheduleTimes(t *testing.T) {
t
.
Errorf
(
"unexpected lack of error"
)
t
.
Errorf
(
"unexpected lack of error"
)
}
}
}
}
{
// Case 7: now is way way ahead of last start time, but there is a short deadline.
sj
.
ObjectMeta
.
CreationTimestamp
=
metav1
.
Time
{
Time
:
T1
.
Add
(
-
2
*
time
.
Hour
)}
sj
.
Status
.
LastScheduleTime
=
&
metav1
.
Time
{
Time
:
T1
.
Add
(
-
1
*
time
.
Hour
)}
now
:=
T2
.
Add
(
10
*
24
*
time
.
Hour
)
// Deadline is short
deadline
:=
int64
(
2
*
60
*
60
)
sj
.
Spec
.
StartingDeadlineSeconds
=
&
deadline
_
,
err
:=
getRecentUnmetScheduleTimes
(
sj
,
now
)
if
err
!=
nil
{
t
.
Errorf
(
"unexpected error"
)
}
}
}
}
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