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.lastSuccessfulTime not populated by a manually triggered job #118530

Merged
merged 1 commit into from Jun 13, 2023

Conversation

carlory
Copy link
Member

@carlory carlory commented Jun 7, 2023

What type of PR is this?

/kind bug

What this PR does / why we need it:

// cronjob status when job fail 

(⎈|kind-kind:default)➜  ~ kubectl get cronjob -o jsonpath='{.items[*].status}' | jq
{
  "lastScheduleTime": "2023-06-07T15:27:00Z",
  "lastSuccessfulTime": "2023-06-07T15:25:07Z"
}

// cronjob status when a manually triggered job complete before next scheduled time is reach

(⎈|kind-kind:default)➜  ~ kubectl get cronjob -o jsonpath='{.items[*].status}' | jq
{
  "lastScheduleTime": "2023-06-07T15:27:00Z",
  "lastSuccessfulTime": "2023-06-07T15:27:39Z"
}

Which issue(s) this PR fixes:

Fixes #118276

Special notes for your reviewer:

https://github.com/kubernetes/kubernetes/blob/8d78d5e19cc80c860faa7cb32e31e9cb0a31e9e5/pkg/controller/cronjob/cronjob_controllerv2.go#L252-L270

Does this PR introduce a user-facing change?

Fix Cronjob status.lastSuccessfulTime not populated by a manually triggered job

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


@k8s-ci-robot k8s-ci-robot added release-note Denotes a PR that will be considered when it comes time to generate release notes. do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. size/S Denotes a PR that changes 10-29 lines, ignoring generated files. kind/bug Categorizes issue or PR as related to a bug. 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. needs-priority Indicates a PR lacks a `priority/foo` label and requires one. labels Jun 7, 2023
@k8s-ci-robot k8s-ci-robot added area/kubectl sig/cli Categorizes an issue or PR as relevant to SIG CLI. and removed do-not-merge/needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. labels Jun 7, 2023
@k8s-ci-robot k8s-ci-robot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Jun 7, 2023
@k8s-ci-robot k8s-ci-robot added size/S Denotes a PR that changes 10-29 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Jun 7, 2023
@carlory carlory changed the title [WIP] fix Cronjob status.lastSuccessfulTime not populated by a manually triggered job fix Cronjob status.lastSuccessfulTime not populated by a manually triggered job Jun 7, 2023
@k8s-ci-robot k8s-ci-robot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Jun 7, 2023
@carlory
Copy link
Member Author

carlory commented Jun 7, 2023

/assign @apelisse

@apelisse
Copy link
Member

apelisse commented Jun 8, 2023

I'm not super familiar with this code. Why does this work?

@carlory
Copy link
Member Author

carlory commented Jun 9, 2023

@apelisse

The cronjob controller watch cronjob and job events. When a job is created, the registered eventhander for job will check if the job has a ControlRef and then add the corresponding cronjob into the workqueue. However, when kubectl create a job from a cronjob, it sets a ownReference with the controller field unset so the job's event won't be handled by the cronjob controller. This pr set the controller field to true. when reconcile a conjob, the controller will list jobs and filters them by the controller ref.

FYI:

  1. https://github.com/kubernetes/kubernetes/blob/master/pkg/controller/cronjob/cronjob_controllerv2.go#L432
  2. https://github.com/kubernetes/kubernetes/blob/master/pkg/controller/cronjob/utils.go#L188

@apelisse
Copy link
Member

/assign @soltysh

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.

/lgtm
/approve

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jun 13, 2023
@k8s-ci-robot
Copy link
Contributor

LGTM label has been added.

Git tree hash: e4259ed084d7e6c9ab3aac2fb240f6affe1214e4

@soltysh
Copy link
Contributor

soltysh commented Jun 13, 2023

/triage accepted
/priority backlog

@k8s-ci-robot k8s-ci-robot added triage/accepted Indicates an issue or PR is ready to be actively worked on. priority/backlog Higher priority than priority/awaiting-more-evidence. 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 Jun 13, 2023
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: carlory, soltysh, Tusenka

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 Jun 13, 2023
@k8s-ci-robot k8s-ci-robot merged commit bca1336 into kubernetes:master Jun 13, 2023
12 checks passed
@k8s-ci-robot k8s-ci-robot added this to the v1.28 milestone Jun 13, 2023
@carlory carlory deleted the fix-issue-118276 branch June 13, 2023 15:37
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. area/kubectl cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/bug Categorizes issue or PR as related to a bug. lgtm "Looks good to me", indicates that a PR is ready to be merged. priority/backlog Higher priority than priority/awaiting-more-evidence. release-note Denotes a PR that will be considered when it comes time to generate release notes. sig/cli Categorizes an issue or PR as relevant to SIG CLI. size/S Denotes a PR that changes 10-29 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 status.lastSuccessfulTime not populated by a manually triggered job
5 participants