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
base: master
Are you sure you want to change the base?
WIP: Job: calculate the job completion before calculating the activeDeadlineSeconds #121863
Conversation
This issue is currently awaiting triage. If a SIG or subproject determines this is a relevant issue, they will accept it by applying the The 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. |
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: tenzen-y 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 |
I'm implementing unit tests. |
I have pushed all commits. If I'm missing anything, please let me know. |
/wg batch |
/cc |
@@ -2020,6 +2020,23 @@ func TestSyncJobPastDeadline(t *testing.T) { | |||
expectedCondition: batch.JobSuspended, | |||
expectedConditionReason: "JobSuspended", | |||
}, | |||
"nonIndexed job succeeded and exceeded activeDeadlineSeconds": { |
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.
For these test cases, do they reproduce the bug if this code is removed?
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 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
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.
Sounds good.
fd6f39b
to
e141b37
Compare
Rebased. |
/retest |
/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 { |
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.
Do we need this if
? Maybe, if needed, it could be inside the wantActivePods
function?
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.
I think we should put this if
here since wantActivePods
is also called in L1478.
@mimowo WDYT?
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.
@mimowo Friendly ping :)
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.
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.
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.
Ah, you're right. We should call inside wantActive()
if we need this if
. Thanks!
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.
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 { |
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.
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.
Thanks for your suggestion! I'll try to evaluate the suggested way, carefully. |
The Kubernetes project currently lacks enough contributors to adequately respond to all PRs. This bot triages PRs according to the following rules:
You can:
Please send feedback to sig-contributor-experience at kubernetes/community. /lifecycle stale |
I will come back here after JobSuccessPolicy initial implementation. /remove-lifecycle stale |
e141b37
to
15bd979
Compare
Rebased. |
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 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:
- Check if there is a FailureTarget condition.
- Check if we have all the succeeded pods.
- 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>
15bd979
to
9fcf8b5
Compare
@tenzen-y: The following tests failed, say
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. |
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?
Additional documentation e.g., KEPs (Kubernetes Enhancement Proposals), usage docs, etc.: