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
aeb35206
Commit
aeb35206
authored
Dec 06, 2018
by
Maciej Szulik
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Set delete propagation policy to background when removing jobs and its dependents
parent
0475d45a
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
20 additions
and
5 deletions
+20
-5
injection.go
pkg/controller/cronjob/injection.go
+2
-1
cronjob.go
test/e2e/apps/cronjob.go
+18
-4
No files found.
pkg/controller/cronjob/injection.go
View file @
aeb35206
...
@@ -118,7 +118,8 @@ func (r realJobControl) CreateJob(namespace string, job *batchv1.Job) (*batchv1.
...
@@ -118,7 +118,8 @@ func (r realJobControl) CreateJob(namespace string, job *batchv1.Job) (*batchv1.
}
}
func
(
r
realJobControl
)
DeleteJob
(
namespace
string
,
name
string
)
error
{
func
(
r
realJobControl
)
DeleteJob
(
namespace
string
,
name
string
)
error
{
return
r
.
KubeClient
.
BatchV1
()
.
Jobs
(
namespace
)
.
Delete
(
name
,
nil
)
background
:=
metav1
.
DeletePropagationBackground
return
r
.
KubeClient
.
BatchV1
()
.
Jobs
(
namespace
)
.
Delete
(
name
,
&
metav1
.
DeleteOptions
{
PropagationPolicy
:
&
background
})
}
}
type
fakeJobControl
struct
{
type
fakeJobControl
struct
{
...
...
test/e2e/apps/cronjob.go
View file @
aeb35206
...
@@ -250,8 +250,10 @@ var _ = SIGDescribe("CronJob", func() {
...
@@ -250,8 +250,10 @@ var _ = SIGDescribe("CronJob", func() {
Expect
(
len
(
finishedJobs
)
==
1
)
.
To
(
BeTrue
())
Expect
(
len
(
finishedJobs
)
==
1
)
.
To
(
BeTrue
())
// Job should get deleted when the next job finishes the next minute
// Job should get deleted when the next job finishes the next minute
By
(
"Ensuring this job does not exist anymore"
)
By
(
"Ensuring this job and its pods does not exist anymore"
)
err
=
waitForJobNotExist
(
f
.
ClientSet
,
f
.
Namespace
.
Name
,
finishedJobs
[
0
])
err
=
waitForJobToDisappear
(
f
.
ClientSet
,
f
.
Namespace
.
Name
,
finishedJobs
[
0
])
Expect
(
err
)
.
NotTo
(
HaveOccurred
())
err
=
waitForJobsPodToDisappear
(
f
.
ClientSet
,
f
.
Namespace
.
Name
,
finishedJobs
[
0
])
Expect
(
err
)
.
NotTo
(
HaveOccurred
())
Expect
(
err
)
.
NotTo
(
HaveOccurred
())
By
(
"Ensuring there is 1 finished job by listing jobs explicitly"
)
By
(
"Ensuring there is 1 finished job by listing jobs explicitly"
)
...
@@ -380,8 +382,8 @@ func waitForJobNotActive(c clientset.Interface, ns, cronJobName, jobName string)
...
@@ -380,8 +382,8 @@ func waitForJobNotActive(c clientset.Interface, ns, cronJobName, jobName string)
})
})
}
}
// Wait for a job to
not exist by listing jobs
explicitly.
// Wait for a job to
disappear by listing them
explicitly.
func
waitForJob
NotExist
(
c
clientset
.
Interface
,
ns
string
,
targetJob
*
batchv1
.
Job
)
error
{
func
waitForJob
ToDisappear
(
c
clientset
.
Interface
,
ns
string
,
targetJob
*
batchv1
.
Job
)
error
{
return
wait
.
Poll
(
framework
.
Poll
,
cronJobTimeout
,
func
()
(
bool
,
error
)
{
return
wait
.
Poll
(
framework
.
Poll
,
cronJobTimeout
,
func
()
(
bool
,
error
)
{
jobs
,
err
:=
c
.
BatchV1
()
.
Jobs
(
ns
)
.
List
(
metav1
.
ListOptions
{})
jobs
,
err
:=
c
.
BatchV1
()
.
Jobs
(
ns
)
.
List
(
metav1
.
ListOptions
{})
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -397,6 +399,18 @@ func waitForJobNotExist(c clientset.Interface, ns string, targetJob *batchv1.Job
...
@@ -397,6 +399,18 @@ func waitForJobNotExist(c clientset.Interface, ns string, targetJob *batchv1.Job
})
})
}
}
// Wait for a pod to disappear by listing them explicitly.
func
waitForJobsPodToDisappear
(
c
clientset
.
Interface
,
ns
string
,
targetJob
*
batchv1
.
Job
)
error
{
return
wait
.
Poll
(
framework
.
Poll
,
cronJobTimeout
,
func
()
(
bool
,
error
)
{
options
:=
metav1
.
ListOptions
{
LabelSelector
:
fmt
.
Sprintf
(
"controller-uid=%s"
,
targetJob
.
UID
)}
pods
,
err
:=
c
.
CoreV1
()
.
Pods
(
ns
)
.
List
(
options
)
if
err
!=
nil
{
return
false
,
err
}
return
len
(
pods
.
Items
)
==
0
,
nil
})
}
// Wait for a job to be replaced with a new one.
// Wait for a job to be replaced with a new one.
func
waitForJobReplaced
(
c
clientset
.
Interface
,
ns
,
previousJobName
string
)
error
{
func
waitForJobReplaced
(
c
clientset
.
Interface
,
ns
,
previousJobName
string
)
error
{
return
wait
.
Poll
(
framework
.
Poll
,
cronJobTimeout
,
func
()
(
bool
,
error
)
{
return
wait
.
Poll
(
framework
.
Poll
,
cronJobTimeout
,
func
()
(
bool
,
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