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

WIP: Job: calculate the job completion before calculating the activeDeadlineSeconds #121863

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

tenzen-y
Copy link
Member

@tenzen-y tenzen-y commented Nov 13, 2023

What type of PR is this?

/kind bug

What this PR does / why we need it:

The job controller should calculate the completion before calculating the activeDeadlineSeconds.

Which issue(s) this PR fixes:

Fixes #117303

Special notes for your reviewer:

Does this PR introduce a user-facing change?

Fix a bug in which the complete condition isn't recorded in jobs when the job reaches activeDeadlineSeconds.

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/M Denotes a PR that changes 30-99 lines, ignoring generated files. 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 Nov 13, 2023
@k8s-ci-robot
Copy link
Contributor

This issue is currently awaiting triage.

If a SIG or subproject determines this is a relevant issue, they will accept it by applying the triage/accepted label and provide further guidance.

The triage/accepted label can be added by org members by writing /triage accepted in a comment.

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 the needs-priority Indicates a PR lacks a `priority/foo` label and requires one. label Nov 13, 2023
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: tenzen-y
Once this PR has been reviewed and has the lgtm label, please assign janetkuo for approval. For more information see the Kubernetes Code Review Process.

The full list of commands accepted by this bot can be found 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 sig/apps Categorizes an issue or PR as relevant to SIG Apps. label Nov 13, 2023
@k8s-ci-robot k8s-ci-robot removed the do-not-merge/needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. label Nov 13, 2023
@tenzen-y tenzen-y changed the title Job: calculate the job completion before calculating the activeDeadlineSeconds [WIP] Job: calculate the job completion before calculating the activeDeadlineSeconds Nov 13, 2023
@k8s-ci-robot k8s-ci-robot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Nov 13, 2023
@tenzen-y
Copy link
Member Author

I'm implementing unit tests.

@alculquicondor
Copy link
Member

@mimowo or @kannon92 would you like to take a first pass?

@tenzen-y tenzen-y changed the title [WIP] Job: calculate the job completion before calculating the activeDeadlineSeconds Job: calculate the job completion before calculating the activeDeadlineSeconds Nov 13, 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 Nov 13, 2023
@tenzen-y
Copy link
Member Author

I have pushed all commits. If I'm missing anything, please let me know.

@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 Nov 13, 2023
@tenzen-y
Copy link
Member Author

/wg batch

@k8s-ci-robot k8s-ci-robot added the wg/batch Categorizes an issue or PR as relevant to WG Batch. label Nov 13, 2023
@kannon92
Copy link
Contributor

/cc

@@ -2020,6 +2020,23 @@ func TestSyncJobPastDeadline(t *testing.T) {
expectedCondition: batch.JobSuspended,
expectedConditionReason: "JobSuspended",
},
"nonIndexed job succeeded and exceeded activeDeadlineSeconds": {
Copy link
Contributor

Choose a reason for hiding this comment

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

For these test cases, do they reproduce the bug if this code is removed?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, we can reproduce issues like the following:

$ go test -run "TestSyncJobPastDeadline" ./pkg/controller/job/...
?       k8s.io/kubernetes/pkg/controller/job/config     [no test files]
?       k8s.io/kubernetes/pkg/controller/job/config/v1alpha1    [no test files]
?       k8s.io/kubernetes/pkg/controller/job/metrics    [no test files]
--- FAIL: TestSyncJobPastDeadline (0.00s)
    --- FAIL: TestSyncJobPastDeadline/nonIndexed_job_succeeded_and_exceeded_activeDeadlineSeconds (0.00s)
        job_controller_test.go:2094: Expected fail condition.  Got []v1.JobCondition{v1.JobCondition{Type:"Failed", Status:"True", LastProbeTime:time.Date(2023, time.November, 14, 13, 40, 12, 766800000, time.Local), LastTransitionTime:time.Date(2023, time.November, 14, 13, 40, 12, 766800000, time.Local), Reason:"DeadlineExceeded", Message:"Job was active longer than specified deadline"}}
    --- FAIL: TestSyncJobPastDeadline/indexed_job_succeeded_and_exceeded_activeDeadlineSeconds (0.00s)
        job_controller_test.go:2094: Expected fail condition.  Got []v1.JobCondition{v1.JobCondition{Type:"Failed", Status:"True", LastProbeTime:time.Date(2023, time.November, 14, 13, 40, 12, 767083000, time.Local), LastTransitionTime:time.Date(2023, time.November, 14, 13, 40, 12, 767083000, time.Local), Reason:"DeadlineExceeded", Message:"Job was active longer than specified deadline"}}
FAIL
FAIL    k8s.io/kubernetes/pkg/controller/job    0.817s
FAIL

Copy link
Contributor

Choose a reason for hiding this comment

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

Sounds good.

@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Nov 16, 2023
@tenzen-y tenzen-y force-pushed the swap-job-succeeded-calculation-and-deadline branch from fd6f39b to e141b37 Compare November 16, 2023 21:15
@tenzen-y
Copy link
Member Author

Rebased.

@tenzen-y
Copy link
Member Author

/retest

@tenzen-y
Copy link
Member Author

/test pull-kubernetes-unit

// If job is scaled down and the number of succeeded pods already reached completions,
// job should be marked as complete here.
wantActive := active
if feature.DefaultFeatureGate.Enabled(features.ElasticIndexedJob) && satisfiedExpectations && job.DeletionTimestamp == nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need this if? Maybe, if needed, it could be inside the wantActivePods function?

Copy link
Member Author

Choose a reason for hiding this comment

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

I think we should put this if here since wantActivePods is also called in L1478.
@mimowo WDYT?

Copy link
Member Author

Choose a reason for hiding this comment

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

@mimowo Friendly ping :)

Copy link
Contributor

Choose a reason for hiding this comment

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

My question is motivated by the fact that this two code paths could result setting different values for wantActive. So for example if satisfiedExpectations == false, feature.DefaultFeatureGate.Enabled(features.ElasticIndexedJob)==true, and job.Deletion==nil you will have wantActive=active here, but wantActive = wantActivePods(&job, jobCtx) inside manageJob.

I'm wondering if we can / should avoid it. No specific failure scenario at the moment.

Copy link
Member Author

@tenzen-y tenzen-y Nov 30, 2023

Choose a reason for hiding this comment

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

Ah, you're right. We should call inside wantActive() if we need this if. Thanks!

Copy link
Contributor

@mimowo mimowo left a comment

Choose a reason for hiding this comment

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

I'm also wondering if we could take a step back and make some minimal fix. The starting point would be to introduce finishedConditionForActiveDeadlineExceeded, and set it line 826, instead of setting jobCtx.finishedCondition. Then, proceeed with evaluation of complete, and finally set jobCtx.finishedCondition = finishedConditionForActiveDeadlineExceeded if complete=false. I'm not sure this is 100% simpler, but I think worth exploring to compare the options.

// If job is scaled down and the number of succeeded pods already reached completions,
// job should be marked as complete here.
wantActive := active
if feature.DefaultFeatureGate.Enabled(features.ElasticIndexedJob) && satisfiedExpectations && job.DeletionTimestamp == nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

My question is motivated by the fact that this two code paths could result setting different values for wantActive. So for example if satisfiedExpectations == false, feature.DefaultFeatureGate.Enabled(features.ElasticIndexedJob)==true, and job.Deletion==nil you will have wantActive=active here, but wantActive = wantActivePods(&job, jobCtx) inside manageJob.

I'm wondering if we can / should avoid it. No specific failure scenario at the moment.

@tenzen-y
Copy link
Member Author

tenzen-y commented Nov 30, 2023

I'm also wondering if we could take a step back and make some minimal fix. The starting point would be to introduce finishedConditionForActiveDeadlineExceeded, and set it line 826, instead of setting jobCtx.finishedCondition. Then, proceeed with evaluation of complete, and finally set jobCtx.finishedCondition = finishedConditionForActiveDeadlineExceeded if complete=false. I'm not sure this is 100% simpler, but I think worth exploring to compare the options.

Thanks for your suggestion! I'll try to evaluate the suggested way, carefully.

@k8s-triage-robot
Copy link

The Kubernetes project currently lacks enough contributors to adequately respond to all PRs.

This bot triages PRs according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the PR is closed

You can:

  • Mark this PR as fresh with /remove-lifecycle stale
  • Close this PR with /close
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/lifecycle stale

@k8s-ci-robot k8s-ci-robot added the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Feb 28, 2024
@tenzen-y
Copy link
Member Author

I will come back here after JobSuccessPolicy initial implementation.

/remove-lifecycle stale

@k8s-ci-robot k8s-ci-robot removed the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Feb 28, 2024
@tenzen-y tenzen-y force-pushed the swap-job-succeeded-calculation-and-deadline branch from e141b37 to 15bd979 Compare March 2, 2024 20:50
@tenzen-y
Copy link
Member Author

tenzen-y commented Mar 2, 2024

Rebased.

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.

This fix is not enough. I should have been more clear: the issue is not just about activeDeadlineSeconds, but any failure.

So the order should be:

  1. Check if there is a FailureTarget condition.
  2. Check if we have all the succeeded pods.
  3. Check any failures: pod failure policy, backoffLimit, activeDeadline (order here is irrelevant).

@tenzen-y
Copy link
Member Author

tenzen-y commented Mar 7, 2024

This fix is not enough. I should have been more clear: the issue is not just about activeDeadlineSeconds, but any failure.

So the order should be:

  1. Check if there is a FailureTarget condition.
  2. Check if we have all the succeeded pods.
  3. Check any failures: pod failure policy, backoffLimit, activeDeadline (order here is irrelevant).

I came back from JobSuccessPolicy. Let me try to finalize this until Test Freeze.

…neSeconds

Signed-off-by: Yuki Iwai <yuki.iwai.tz@gmail.com>
… activeDeadlineSeconds

Signed-off-by: Yuki Iwai <yuki.iwai.tz@gmail.com>
Signed-off-by: Yuki Iwai <yuki.iwai.tz@gmail.com>
@tenzen-y tenzen-y force-pushed the swap-job-succeeded-calculation-and-deadline branch from 15bd979 to 9fcf8b5 Compare March 8, 2024 16:14
@tenzen-y tenzen-y changed the title Job: calculate the job completion before calculating the activeDeadlineSeconds WIP: Job: calculate the job completion before calculating the activeDeadlineSeconds Mar 8, 2024
@k8s-ci-robot k8s-ci-robot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Mar 8, 2024
@k8s-ci-robot
Copy link
Contributor

@tenzen-y: The following tests failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
pull-kubernetes-conformance-kind-ga-only-parallel 9fcf8b5 link true /test pull-kubernetes-conformance-kind-ga-only-parallel
pull-kubernetes-integration 9fcf8b5 link true /test pull-kubernetes-integration

Full PR test history. Your PR dashboard. Please help us cut down on flakes by linking to an open issue when you hit one in your PR.

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. I understand the commands that are listed here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. kind/bug Categorizes issue or PR as related to a bug. needs-priority Indicates a PR lacks a `priority/foo` label and requires one. needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. 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/L Denotes a PR that changes 100-499 lines, ignoring generated files. wg/batch Categorizes an issue or PR as relevant to WG Batch.
Projects
Status: Needs Triage
Development

Successfully merging this pull request may close these issues.

Inconsistent Job state on DeadlineExceeded
6 participants