-
Notifications
You must be signed in to change notification settings - Fork 38.7k
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
CronJob: Respect ControllerRef #42177
Merged
k8s-github-robot
merged 10 commits into
kubernetes:master
from
enisoc:controller-ref-cronjob
Apr 20, 2017
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
4c954d6
CronJob: Don't launch if DeletionTimestamp is set.
enisoc d72eebd
CronJob: Add ControllerRef on all created Jobs.
enisoc 631d8bc
CronJob: Set DefaultGarbageCollectionPolicy to OrphanDependents.
enisoc e085f1f
CronJob: Apply missing ControllerRefs to Jobs created by a CronJob.
enisoc 4e682fd
CronJob: Always set BlockOwnerDeletion in ControllerRef.
enisoc 5cef455
CronJob: Use synchronous deletion for CronJobs in e2e.
enisoc 4e1b07d
CronJob: Check ControllerRef Name and UID in unit test.
enisoc 1e14323
CronJob: List children before parents.
enisoc 33d7788
CronJob: Add e2e test for adoption.
enisoc be1fe95
CronJob: Use PATCH to adopt Jobs.
enisoc File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -56,6 +56,9 @@ import ( | |
|
||
// Utilities for dealing with Jobs and CronJobs and time. | ||
|
||
// controllerKind contains the schema.GroupVersionKind for this controller type. | ||
var controllerKind = batchv2alpha1.SchemeGroupVersion.WithKind("CronJob") | ||
|
||
type CronJobController struct { | ||
kubeClient clientset.Interface | ||
jobControl jobControlInterface | ||
|
@@ -102,21 +105,25 @@ func (jm *CronJobController) Run(stopCh <-chan struct{}) { | |
|
||
// syncAll lists all the CronJobs and Jobs and reconciles them. | ||
func (jm *CronJobController) syncAll() { | ||
sjl, err := jm.kubeClient.BatchV2alpha1().CronJobs(metav1.NamespaceAll).List(metav1.ListOptions{}) | ||
// List children (Jobs) before parents (CronJob). | ||
// This guarantees that if we see any Job that got orphaned by the GC orphan finalizer, | ||
// we must also see that the parent CronJob has non-nil DeletionTimestamp (see #42639). | ||
// Note that this only works because we are NOT using any caches here. | ||
jl, err := jm.kubeClient.BatchV1().Jobs(metav1.NamespaceAll).List(metav1.ListOptions{}) | ||
if err != nil { | ||
glog.Errorf("Error listing cronjobs: %v", err) | ||
utilruntime.HandleError(fmt.Errorf("can't list Jobs: %v", err)) | ||
return | ||
} | ||
sjs := sjl.Items | ||
glog.V(4).Infof("Found %d cronjobs", len(sjs)) | ||
js := jl.Items | ||
glog.V(4).Infof("Found %d jobs", len(js)) | ||
|
||
jl, err := jm.kubeClient.BatchV1().Jobs(metav1.NamespaceAll).List(metav1.ListOptions{}) | ||
sjl, err := jm.kubeClient.BatchV2alpha1().CronJobs(metav1.NamespaceAll).List(metav1.ListOptions{}) | ||
if err != nil { | ||
glog.Errorf("Error listing jobs") | ||
utilruntime.HandleError(fmt.Errorf("can't list CronJobs: %v", err)) | ||
return | ||
} | ||
js := jl.Items | ||
glog.V(4).Infof("Found %d jobs", len(js)) | ||
sjs := sjl.Items | ||
glog.V(4).Infof("Found %d cronjobs", len(sjs)) | ||
|
||
jobsBySj := groupJobsByParent(js) | ||
glog.V(4).Infof("Found %d groups", len(jobsBySj)) | ||
|
@@ -238,6 +245,18 @@ func syncOne(sj *batchv2alpha1.CronJob, js []batchv1.Job, now time.Time, jc jobC | |
} | ||
*sj = *updatedSJ | ||
|
||
if sj.DeletionTimestamp != nil { | ||
// The CronJob is being deleted. | ||
// Don't do anything other than updating status. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is no status update. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh well it seems it has already happened above |
||
return | ||
} | ||
|
||
if err := adoptJobs(sj, js, jc); err != nil { | ||
// This is fine. We will retry later. | ||
// Adoption is only to advise other controllers. We don't rely on it. | ||
glog.V(4).Infof("Unable to adopt Jobs for CronJob %v: %v", nameForLog, err) | ||
} | ||
|
||
if sj.Spec.Suspend != nil && *sj.Spec.Suspend { | ||
glog.V(4).Infof("Not starting job for %s because it is suspended", nameForLog) | ||
return | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
@soltysh we'll need to take care of this when we change cronjob controller to use informer
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.
Yes, we've talked about it during KubeCon. If I have a reasonable solution in place in openshift I'll make sure to fix cronjob controller.