Skip to content
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

Fix cronjob status reconciliation when job template labels change #107997

Merged

Conversation

d-honeybadger
Copy link
Contributor

@d-honeybadger d-honeybadger commented Feb 8, 2022

What type of PR is this?

/kind bug
/kind regression

What this PR does / why we need it:

In CronJobController V2, the controller only considers jobs with labels that match current cronjob's job template labels. This leads to the controller losing track of jobs owned by a given cronjob when those template labels change. For example, if job template labels were updated while the cronjob was in the active status, that cronjob will be stuck as active, since the controller will never find the completed job whose labels now don't match those of the job template.

Which issue(s) this PR fixes:

Fixes #106496

Special notes for your reviewer:

I see that in #93370 filtering by label was added for performance. If anyone has ideas on how to keep that performance improvement while maintaining correct behavior, I'd be happy to close this and work on another solution.

Does this PR introduce a user-facing change?

Fixes regression in 1.21 default configurations where a bug in CronJob Controller V2 where it would lose track of jobs upon job template labels change.

Additional documentation e.g., KEPs (Kubernetes Enhancement Proposals), usage docs, etc.:


@k8s-ci-robot k8s-ci-robot added kind/bug Categorizes issue or PR as related to a bug. size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. kind/regression Categorizes issue or PR as related to a regression from a prior release. do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. do-not-merge/needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. labels Feb 8, 2022
@k8s-ci-robot
Copy link
Contributor

Welcome @d-honeybadger!

It looks like this is your first PR to kubernetes/kubernetes 🎉. Please refer to our pull request process documentation to help your PR have a smooth ride to approval.

You will be prompted by a bot to use commands during the review process. Do not be afraid to follow the prompts! It is okay to experiment. Here is the bot commands documentation.

You can also check if kubernetes/kubernetes has its own contribution guidelines.

You may want to refer to our testing guide if you run into trouble with your tests not passing.

If you are having difficulty getting your pull request seen, please follow the recommended escalation practices. Also, for tips and tricks in the contribution process you may want to read the Kubernetes contributor cheat sheet. We want to make sure your contribution gets all the attention it needs!

Thank you, and welcome to Kubernetes. 😃

@k8s-ci-robot k8s-ci-robot added needs-priority Indicates a PR lacks a `priority/foo` label and requires one. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Feb 8, 2022
@k8s-ci-robot
Copy link
Contributor

Hi @d-honeybadger. Thanks for your PR.

I'm waiting for a kubernetes member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@k8s-ci-robot k8s-ci-robot added sig/apps Categorizes an issue or PR as relevant to SIG Apps. and removed do-not-merge/needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. labels Feb 8, 2022
@d-honeybadger
Copy link
Contributor Author

/assign @soltysh

@d-honeybadger
Copy link
Contributor Author

/sig apps

@alculquicondor
Copy link
Member

/ok-to-test

This definitely requires a release note.

@k8s-ci-robot k8s-ci-robot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Feb 10, 2022
@alculquicondor
Copy link
Member

For comparison, in the job controller we list all the pods for a similar reason:

// List all pods to include those that don't match the selector anymore
// but have a ControllerRef pointing to this controller.
pods, err := jm.podStore.Pods(j.Namespace).List(labels.Everything())

So I don't see why we shouldn't do the same for the cronjob controller.

I'll have to defer to @soltysh as I don't have the historical background.

@k8s-ci-robot k8s-ci-robot added release-note Denotes a PR that will be considered when it comes time to generate release notes. and removed do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. labels Feb 11, 2022
@d-honeybadger
Copy link
Contributor Author

This definitely requires a release note.

Ah yes, added.
Thank you for taking a look!

@alculquicondor
Copy link
Member

You should probably add a test too :)
But maybe wait for Maciej to confirm if the change is reasonable.

@alculquicondor
Copy link
Member

@janetkuo @kow3ns do you have any thoughts on #107997 (comment) ?

@janetkuo
Copy link
Member

For comparison, in the job controller we list all the pods for a similar reason:

// List all pods to include those that don't match the selector anymore
// but have a ControllerRef pointing to this controller.
pods, err := jm.podStore.Pods(j.Namespace).List(labels.Everything())

So I don't see why we shouldn't do the same for the cronjob controller.

I'll have to defer to @soltysh as I don't have the historical background.

The reason that we didn't do this for the original CronJob controller is that it doesn't use watches, see the ControllerRef design doc for more details. Given that CronJob v2 now uses watches, it makes sense to make the changes accordingly.

@alculquicondor
Copy link
Member

Makes sense.

@d-honeybadger could you add a unit test for the change?

Copy link
Contributor

@soltysh soltysh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, I'll dig through perf data and see how good/bad this is, alternatively we could add a separate indexer for jobs, if we needed, but that can be done separately from this PR.
But I definitely would like to see unit test added like @alculquicondor mentioned
/approve
/triage accepted
/priority important-longterm
/assign @alculquicondor
he has the final lgtm on it

@k8s-ci-robot k8s-ci-robot added triage/accepted Indicates an issue or PR is ready to be actively worked on. priority/important-longterm Important over the long term, but may not be staffed and/or may need multiple releases to complete. and removed needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. needs-priority Indicates a PR lacks a `priority/foo` label and requires one. labels Feb 18, 2022
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: d-honeybadger, soltysh

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Feb 18, 2022
@k8s-ci-robot k8s-ci-robot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. labels Feb 19, 2022
@d-honeybadger
Copy link
Contributor Author

@alculquicondor 👍 Added a test and a comment for good measure.

Name: "foo-nonmatching-label",
Labels: map[string]string{"key": "different-value"},
OwnerReferences: []metav1.OwnerReference{{Name: "fooer", Controller: &trueRef}}},
},
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add one that has a different owner reference.

Copy link
Member

@alculquicondor alculquicondor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/lgtm

Thanks!

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Feb 23, 2022
@k8s-ci-robot k8s-ci-robot merged commit 343125c into kubernetes:master Feb 23, 2022
@k8s-ci-robot k8s-ci-robot added this to the v1.24 milestone Feb 23, 2022
@simonjpartridge
Copy link

simonjpartridge commented Feb 23, 2022

Thanks for fixing this!

I'm curious if this bug will get backported to any older versions of k8s? Or just released in the 1.24 release?

@alculquicondor
Copy link
Member

This qualifies for backporting as it's a regression.
Feel free to create a cherry-pick https://github.com/kubernetes/community/blob/master/contributors/devel/sig-release/cherry-picks.md

@simonjpartridge
Copy link

@alculquicondor not done this before so let me know if I got something wrong. But I've created 3 cherrypick PRs, one each for 1.21, 1.22, 1.23. I hope that's helpful :)

k8s-ci-robot added a commit that referenced this pull request Mar 3, 2022
…-of-#107997-upstream-release-1.22

Automated cherry pick of #107997: cronjob_controllerv2: do not filter jobs to be reconciled by
k8s-ci-robot added a commit that referenced this pull request Mar 3, 2022
…-of-#107997-upstream-release-1.23

Automated cherry pick of #107997: cronjob_controllerv2: do not filter jobs to be reconciled by
k8s-ci-robot added a commit that referenced this pull request Mar 3, 2022
…-of-#107997-upstream-release-1.21

Automated cherry pick of #107997: cronjob_controllerv2: do not filter jobs to be reconciled by
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/bug Categorizes issue or PR as related to a bug. kind/regression Categorizes issue or PR as related to a regression from a prior release. lgtm "Looks good to me", indicates that a PR is ready to be merged. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. priority/important-longterm Important over the long term, but may not be staffed and/or may need multiple releases to complete. release-note Denotes a PR that will be considered when it comes time to generate release notes. sig/apps Categorizes an issue or PR as relevant to SIG Apps. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. triage/accepted Indicates an issue or PR is ready to be actively worked on.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

CronJob loses track of Jobs after label update
6 participants