-
Notifications
You must be signed in to change notification settings - Fork 40.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add e2e test for cronjob chained removal #48068
Add e2e test for cronjob chained removal #48068
Conversation
018caa2
to
19dbefd
Compare
test/e2e/workload/cronjob.go
Outdated
@@ -75,6 +75,13 @@ var _ = framework.KubeDescribe("CronJob", func() { | |||
By("Removing cronjob") | |||
err = deleteCronJob(f.ClientSet, f.Namespace.Name, cronJob.Name) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
deleteCronJob is not setting any DeleteOptions and the default REST strategy for CJs is orphaning so I am wondering how does this test work?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, you need to set the policy to DeletePropagationBackground.
Unless you are doing a foreground deletion, this test is not going to be stable. Also can you verify that the CronJob is deleted? |
test/e2e/workload/cronjob.go
Outdated
@@ -75,6 +75,13 @@ var _ = framework.KubeDescribe("CronJob", func() { | |||
By("Removing cronjob") | |||
err = deleteCronJob(f.ClientSet, f.Namespace.Name, cronJob.Name) | |||
Expect(err).NotTo(HaveOccurred()) | |||
By("Ensuring cronjob does not leave jobs nor pods behind") | |||
jobs, err = f.ClientSet.Batch().Jobs(f.Namespace.Name).List(metav1.ListOptions{}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be a poll and list. The GC takes time.
test/e2e/workload/cronjob.go
Outdated
jobs, err = f.ClientSet.Batch().Jobs(f.Namespace.Name).List(metav1.ListOptions{}) | ||
Expect(err).NotTo(HaveOccurred()) | ||
Expect(jobs.Items).To(HaveLen(0)) | ||
pods, err := f.ClientSet.Core().Pods(f.Namespace.Name).List(metav1.ListOptions{}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same comment here.
@Kargakis @soltysh we need to reach consensus on whether to use foreground or background GC. I think in this test, the stable way is using the foreground gc, then polls for the final deletion of the cronjob, and then verify the pods are deleted. I think @soltysh's intention was to test the GC properly cascades the background GC. For that, i think it is worth a separate test. |
@caesarxuchao should we need to poll in case of foreground deletion? IIUC, the DELETE call should block until everything is deleted, isn't that the case? |
@Kargakis based on this I'm assuming the blocking depends what we set in ownerRef. cronjob has that set so I'll go with foreground deletion as proposed by @caesarxuchao |
@Kargakis actually, the foreground removal works without the fix, so we need background removal to verify its role. |
19dbefd
to
f9d135a
Compare
@caesarxuchao @Kargakis I've created a separate tests just for cronjobs GC, ptal |
@caesarxuchao any objections to merge this in? |
test/e2e/garbage_collector.go
Outdated
} | ||
|
||
By("Delete the cronjob") | ||
if err := f.ClientSet.BatchV2alpha1().CronJobs(f.Namespace.Name).Delete(cronJob.Name, getNonOrphanOptions()); err != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could be fixed in another PR. OrphanDependents field is deprecated, set propagationPolicy to Background instead.
test/e2e/garbage_collector.go
Outdated
_, err := f.ClientSet.BatchV2alpha1().CronJobs(f.Namespace.Name).Get(cronJob.Name, metav1.GetOptions{}) | ||
return err != nil && !errors.IsNotFound(err), nil | ||
}) | ||
By("Verify if cronjob does not leave jobs nor pods behind") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These should be wrapped in a poll. The Cronjob is deleted with getNonOrphanOptions, which is equivalent of the "background" GC policy, which causes the cronjob to be deleted immediately, then GC deletes the dependents in the background.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you use the "foreground" GC, then GC will delete the cronjob after all dependents are deleted, then these checks make sense.
@soltysh too late for 1.7, changed to 1.8 |
f9d135a
to
e0e8f29
Compare
@caesarxuchao I've updated per your suggestion and I've also split the fix to rs and deployment test swallowing errors to a separate commit. |
/lgtm @soltysh could you rebase? Thanks. |
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: caesarxuchao, soltysh No associated issue. Update pull-request body to add a reference to an issue, or get approval with The full list of commands accepted by this bot can be found here.
Needs approval from an approver in each of these OWNERS Files:
You can indicate your approval by writing |
e0e8f29
to
591db87
Compare
@caesarxuchao sorry, I was out for almost a month. I've rebased and addressed that single comment of yours. ptal |
591db87
to
17f8c97
Compare
Bazel fixed, should be good now. |
Based on previous approval I'm re-adding the labels. |
/test all [submit-queue is verifying that this PR is safe to merge] |
Automatic merge from submit-queue |
This is test proving #44058 works with cronjobs. This will fail until the aforementioned PR merges.
@caesarxuchao ptal