From 24a688c05fc5fef1e4609b932c2c5569f5ea6057 Mon Sep 17 00:00:00 2001 From: Yuki Iwai Date: Tue, 6 Jun 2023 22:03:24 +0900 Subject: [PATCH] KEP-3998: Job success/completion policy Signed-off-by: Yuki Iwai --- keps/prod-readiness/sig-apps/3998.yaml | 3 + .../README.md | 1071 +++++++++++++++++ .../kep.yaml | 42 + 3 files changed, 1116 insertions(+) create mode 100644 keps/prod-readiness/sig-apps/3998.yaml create mode 100644 keps/sig-apps/3998-job-success-completion-policy/README.md create mode 100644 keps/sig-apps/3998-job-success-completion-policy/kep.yaml diff --git a/keps/prod-readiness/sig-apps/3998.yaml b/keps/prod-readiness/sig-apps/3998.yaml new file mode 100644 index 000000000000..07d7140592ac --- /dev/null +++ b/keps/prod-readiness/sig-apps/3998.yaml @@ -0,0 +1,3 @@ +kep-number: 3998 +beta: + approver: "@wojtek-t" diff --git a/keps/sig-apps/3998-job-success-completion-policy/README.md b/keps/sig-apps/3998-job-success-completion-policy/README.md new file mode 100644 index 000000000000..6c0f29f28812 --- /dev/null +++ b/keps/sig-apps/3998-job-success-completion-policy/README.md @@ -0,0 +1,1071 @@ + +# KEP-3998: Job success/completion policy + + + + + + +- [Release Signoff Checklist](#release-signoff-checklist) +- [Summary](#summary) +- [Motivation](#motivation) + - [Goals](#goals) + - [Non-Goals](#non-goals) +- [Proposal](#proposal) + - [User Stories (Optional)](#user-stories-optional) + - [Story 1](#story-1) + - [Story 2](#story-2) + - [Story 3](#story-3) + - [Notes/Constraints/Caveats (Optional)](#notesconstraintscaveats-optional) + - [Risks and Mitigations](#risks-and-mitigations) + - [The Job object too big](#the-job-object-too-big) +- [Design Details](#design-details) + - [Test Plan](#test-plan) + - [Prerequisite testing updates](#prerequisite-testing-updates) + - [Unit tests](#unit-tests) + - [Integration tests](#integration-tests) + - [e2e tests](#e2e-tests) + - [Graduation Criteria](#graduation-criteria) + - [Upgrade / Downgrade Strategy](#upgrade--downgrade-strategy) + - [Version Skew Strategy](#version-skew-strategy) +- [Production Readiness Review Questionnaire](#production-readiness-review-questionnaire) + - [Feature Enablement and Rollback](#feature-enablement-and-rollback) + - [Rollout, Upgrade and Rollback Planning](#rollout-upgrade-and-rollback-planning) + - [Monitoring Requirements](#monitoring-requirements) + - [Dependencies](#dependencies) + - [Scalability](#scalability) + - [Troubleshooting](#troubleshooting) +- [Implementation History](#implementation-history) +- [Drawbacks](#drawbacks) +- [Alternatives](#alternatives) +- [Infrastructure Needed (Optional)](#infrastructure-needed-optional) + + +## Release Signoff Checklist + + + +Items marked with (R) are required *prior to targeting to a milestone / release*. + +- [ ] (R) Enhancement issue in release milestone, which links to KEP dir in [kubernetes/enhancements] (not the initial KEP PR) +- [ ] (R) KEP approvers have approved the KEP status as `implementable` +- [ ] (R) Design details are appropriately documented +- [ ] (R) Test plan is in place, giving consideration to SIG Architecture and SIG Testing input (including test refactors) + - [ ] e2e Tests for all Beta API Operations (endpoints) + - [ ] (R) Ensure GA e2e tests meet requirements for [Conformance Tests](https://github.com/kubernetes/community/blob/master/contributors/devel/sig-architecture/conformance-tests.md) + - [ ] (R) Minimum Two Week Window for GA e2e tests to prove flake free +- [ ] (R) Graduation criteria is in place + - [ ] (R) [all GA Endpoints](https://github.com/kubernetes/community/pull/1806) must be hit by [Conformance Tests](https://github.com/kubernetes/community/blob/master/contributors/devel/sig-architecture/conformance-tests.md) +- [ ] (R) Production readiness review completed +- [ ] (R) Production readiness review approved +- [ ] "Implementation History" section is up-to-date for milestone +- [ ] User-facing documentation has been created in [kubernetes/website], for publication to [kubernetes.io] +- [ ] Supporting documentation—e.g., additional design documents, links to mailing list discussions/SIG meetings, relevant PRs/issues, release notes + + + +[kubernetes.io]: https://kubernetes.io/ +[kubernetes/enhancements]: https://git.k8s.io/enhancements +[kubernetes/kubernetes]: https://git.k8s.io/kubernetes +[kubernetes/website]: https://git.k8s.io/website + +## Summary + + + +This KEP extends the Job API to allow setting conditions under which the Job can be declared as succeeded. + +## Motivation + + + +There are cases where a batch workload requires an indexed job that want to care +only about drivers (leaders) indexes in determining the success or failure of a Job, +for example MPI and PyTorch etc. This is currently not possible because the indexed job +is marked as Completed only if all indexes are succeeded. + +Additionally, there are cases where a batch workload requires a number +to be specified as a percentage when determining the success of a job +because an indexed job author might not know how many indexes the job will have in advance +when the above batch workload has an autoscale semantic. + +Some third-party frameworks have implemented success policy. + +- [Kubeflow Training Operator](https://www.kubeflow.org/docs/components/training) +- [Flux Operator](https://flux-framework.org/flux-operator/) + +### Goals + + + +- allow to mark a job as a `Succeeded` even if some of the indexes fail. + +### Non-Goals + + + +- Change the existing behavior of `NonIndexed` mode. +- Change the existing behavior of `Indexed` mode without a SuccessfulPolicy. + +## Proposal + + + +We propose new policies under which a job can be declared as succeeded. +Those policies can be modeled in the following: + +1. An indexed job completes if a set of [x, y, z...] indexes are successful. +2. An indexed job completes if x or x% of indexes are successful. + +### User Stories (Optional) + + + +#### Story 1 + +As a machine-learning researcher, I run a indexed job which drivers (leaders) are launched +as index=0,1,2, and workers are launched as non index=0,1,2. +I want to care about only the drivers when the result of job is evaluated. + +```yaml +apiVersion: v1 +kind: Job +spec: + parallelism: 10 + completions: 10 + completionMode: Indexed + successfulPolicy: + onRequiredIndexes: [0,1,2] + template: + spec: + restartPolicy: Never + containers: + - name: job-container + image: job-image + command: ["./sample"] +``` + +#### Story 2 + +As a machine-learning researcher, I run an indexed job with an autoscale semantic +set as a minimum number is 5 and a maximum number is 20. +I want to mark the job as successful at least 5 indexes succeeded, even if +all indexes don't succeed. + +```yaml +apiVersion: v1 +kind: Job +spec: + parallelism: 10 + completions: 10 + completionMode: Indexed + successfulPolicy: + onIndexesThreshold: 5 + template: + spec: + restartPolicy: Never + containers: + - name: job-container + image: job-image + command: ["./sample"] +``` + +#### Story 3 + +As a machine-learning researcher from the [Story 2](#story-2), I want to mark the job +as successful if 50% of all indexes succeed because I can not know how many indexes +will have in advance. + +```yaml +apiVersion: v1 +kind: Job +spec: + parallelism: 10 + completions: 10 + completionMode: Indexed + successfulPolicy: + onIndexesThreshold: 50% + template: + spec: + restartPolicy: Never + containers: + - name: job-container + image: job-image + command: ["./sample"] +``` + +### Notes/Constraints/Caveats (Optional) + + + +### Risks and Mitigations + + + +#### Incorrect `.status.completedIndexes` + +If the job object's size reaches to limit of the etcd and +the job controller can't store a correct value in `.status.completedIndexes`, +we probably can not evaluate the SuccessfulPolicy correctly. + +#### The Job object too big + +If we allow users to set all indexes (`0~10^5`) to `.spec.successfulPolicy.requiredIndexes` +and don't limit the number of list sizes, there are cases that the size of a job object is too big. + +In the worst case, allowed all indexes (`0~10^5`) are added to requiredIndexes. +In that case, a `requiredIndexes` size is `SUM[9*10^n*(n+1)]+2+6≈5.6656MiB`, where: +- `n` starts from `0` and goes up to `5`. +- `1` of `n+1` means a separator that indicates `,`. +- `2` is the sum of the index `0` and `,`. +- `6` is the size of indexes `10^5`. + +## Design Details + + + +### Job API + +We extend the Job API to set different policies by which a Job can be declared as succeeded. + +```golang +type JobSpec struct { + ... + // Specifies the policy when the job can be declared as succeeded. + // If empty, the default behavior applies - the job is declared as succeeded + // only when the number of succeeded pods equals to the completions. + // This policy can not be specified more than one. + // + // This field is alpha-level. To use this field, you must enable the + // `JobSuccessPolicy` feature gate (disable by default). + // +option + SuccessfulPolicy *SuccessfulPolicy +} + +// SuccessfulPolicy describes how succeeded pods influence the conditions. +type SuccessfulPolicy struct { + // Specifies a set of required indexes. + // The job is declared as succeeded if a set of indexes are succeeded. + // The list of indexes must come within 0 to `.spec.completions` and + // must not contain duplicates. At least one element is required. + // + // +option + OnRequiredIndexes []int + + // Specifies the required number of indexes. + // Value can be an absolute number (ex: 5) or a percentage of total indexes + // when the job can be declared as succeeded (ex: 50%). + // The absolute number is calculated from the percentage by rounding up. + // + // +option + OnIndexesThreshold intstr.IntOrString +} +``` + +Moreover, we validate the following constraints: +- exactly one of the fields `onRequiredIndexes` and `onIndexesThreshold` is specified + for a requirement. +- whether the specified indexes in the `onRequiredIndexes` and + the number of indexes in the `onIndexesThreshold` don't exceed the value of `completions`. +- whether `Indexed` is specified in the `completionMode` field. + +### Evaluation +We evaluate the SuccessfulPolicy after all indexes have been finished. +And then if the job meets the SuccessfulPolicy, we add `Completed` condition +instead of `Failed` condition to `.status.conditions` even if other indexes fail. + +If a set of indexes are specified in the `onRequiredIndexes` field, +we evaluate `.status.completedIndexes` to see if a set of indexes is there. + +If the number of indexes is specified in the `onIndexesThreshold`, +we evaluate `.status.succeeded` to see if the value is `onIndexesThreshold` or more. + +### Test Plan + + + +[x] I/we understand the owners of the involved components may require updates to +existing tests to make this code solid enough prior to committing the changes necessary +to implement this enhancement. + +##### Prerequisite testing updates + + + +##### Unit tests + + + + + +- Test cases: + - tests for Defaulting and Validating + - tests for rounding up absolute numbers in `.spec.successfulPolicy.onRequiredIndexesThreshold`. + - verify whether a job has condition=completed if the job meets to successfulPolicy + and some indexes fail. + +- `k8s.io/kubernetes/pkg/controller/job`: `6 June 2023` - `90.5%` +- `k8s.io/kubernetes/pkg/apis/batch/validation`: `6 June 2023` - `98.5%` + +##### Integration tests + + + + + +- Test scenarios: + - enabling, disabling and re-enabling of the `JobSuccessfulPolicy` feature gate + - handling of successfulPolicy when all indexes succeeded + - handling of the `.spec.successfulPolicy.onRequiredIndexes` when some indexes fail + - handling of the `.spec.successfulPolicy.onRequiredIndexesThreshold` when some indexes fail + +##### e2e tests + + + +- Test scenarios: + - handling of successfulPolicy when all indexes succeeded + - handling of the `.spec.successfulPolicy.onRequiredIndexes` when some indexes fail + - handling of the `.spec.successfulPolicy.onRequiredIndexesThreshold` when some indexes fail + +### Graduation Criteria + + + + +#### Alpha + +- Feature implemented behind the `JobSuccessfulPolicy` feature gate. +- Unit and integration tests passed as designed in [TestPlan](#test-plan). + +#### Beta + +- E2E tests passed as designed in [TestPlan](#test-plan). +- Added a new reasons to the existing `job_finished_total` metric in [Monitoring Requirements](#monitoring-requirements). +- Feature is enabled by default. +- Gather feedback from developers. + +#### GA + +- No negative feedback. + +### Upgrade / Downgrade Strategy + + + +- Upgrade + - If the feature gate is enabled, `JobSuccessfulPolicy` are allowed to use only. + - If the feature gate is enabled without `JobSuccessfulPolicy`, + the default values will be applied to a job object. + - Even if the feature gate is enabled, the Job controller doesn't update + `.status.conditions` in already finished jobs. +- Downgrade + - Previously configured values will be ignored, and the job will be marked + as completed only when all indexes succeed. + - the Job controller doesn't update `.status.conditions` in already finished jobs. + +### Version Skew Strategy + + + +The apiserver's version should be consistent with the kube-controller-manager version, +or this feature will not work. + +## Production Readiness Review Questionnaire + + + +### Feature Enablement and Rollback + + + +###### How can this feature be enabled / disabled in a live cluster? + + + +- [x] Feature gate (also fill in values in `kep.yaml`) + - Feature gate name: + - Components depending on the feature gate: + - kube-apiserver + - kube-controller-manager + +###### Does enabling the feature change any default behavior? + + + +No. + +###### Can the feature be disabled once it has been enabled (i.e. can we roll back the enablement)? + + + +Yes, we can disable the `JobSuccessfulPolicy` feature gate. + +###### What happens if we reenable the feature if it was previously rolled back? + +The Job controller considers the `.spec.successfulPolicy` when it updates `.status.conditions` +only for running Jobs and don't update `.status.conditions` for already finished jobs. + +###### Are there any tests for feature enablement/disablement? + + + +No, we'll add them during alpha. + +### Rollout, Upgrade and Rollback Planning + + + +###### How can a rollout or rollback fail? Can it impact already running workloads? + + + +No. The Job controller considers `.spec.successfulPolicy` after all indexes (pods) are finished. + +###### What specific metrics should inform a rollback? + + + +An increase in the `job_sync_duration_seconds` metrics can mean that finished jobs +are taking longer to evaluate. + +The users should check whether the completed jobs have the appropriate condition, +specifically the reason. + +###### Were upgrade and rollback tested? Was the upgrade->downgrade->upgrade path tested? + + + +No. + +###### Is the rollout accompanied by any deprecations and/or removals of features, APIs, fields of API types, flags, etc.? + + + +No. + +### Monitoring Requirements + + + +###### How can an operator determine if the feature is in use by workloads? + + + +`job_finished_total`: the new `JobSuccessfulPolicy` and `Completions` values for the `reason` label. + - `JobSuccessfulPolicy` indicates a job is declared as succeeded because the job meets `.spec.successfulPolicy`. + - `Completions` indicates a job is declared as succeeded because the job mees `spec.completions`. + +###### How can someone using this feature know that it is working for their instance? + + + +- [x] Job API .status + - The Job controller will add a condition with `JobSuccessfulPolicy` reason to `conditions`. + +###### What are the reasonable SLOs (Service Level Objectives) for the enhancement? + + + +###### What are the SLIs (Service Level Indicators) an operator can use to determine the health of the service? + + + +- [x] Metrics + - Metric name: `job_sync_duration_seconds` (existing): can be used to see how much the + feature enablement increases the time spent in the sync job + - Components exposing the metric: + +###### Are there any missing metrics that would be useful to have to improve observability of this feature? + + + +No. + +### Dependencies + + + +###### Does this feature depend on any specific services running in the cluster? + + + +No. + +### Scalability + + + +No. + +###### Will enabling / using this feature result in any new API calls? + + + +No. + +###### Will enabling / using this feature result in introducing new API types? + + + +No. + +###### Will enabling / using this feature result in any new calls to the cloud provider? + + + +No. + +###### Will enabling / using this feature result in increasing size or count of the existing API objects? + + + +Yes, it will increase the size of existing API objects only when the `.spec.successfulPolicy` is set. + +- API type(s): Job +- Estimated increase in size: `.spec.successPolicy.requiredIndexes` field are impacted. +In the worst case, the size of `requiredIndexes` can be estimated about 5.6MiB (see [The Job object too big](#the-job-object-too-big)). + +###### Will enabling / using this feature result in increasing time taken by any operations covered by existing SLIs/SLOs? + + + +No. + +###### Will enabling / using this feature result in non-negligible increase of resource usage (CPU, RAM, disk, IO, ...) in any components? + + + +No. + +###### Can enabling / using this feature result in resource exhaustion of some node resources (PIDs, sockets, inodes, etc.)? + + + +No. + +### Troubleshooting + + + +###### How does this feature react if the API server and/or etcd is unavailable? + +###### What are other known failure modes? + + + +None. + +###### What steps should be taken if SLOs are not being met to determine the problem? + +## Implementation History + + +- 2023.06.06: This KEP is ready for review. + +## Drawbacks + + + +## Alternatives + + + +### Relax a validation for `.spec.completions` +Currently, a job is restricted `.spec.completion!=nil`. +By relaxing the validation, the job can be declared as succeeded when some indexes succeeded, +similar to NonIndexed jobs. + +## Infrastructure Needed (Optional) + + diff --git a/keps/sig-apps/3998-job-success-completion-policy/kep.yaml b/keps/sig-apps/3998-job-success-completion-policy/kep.yaml new file mode 100644 index 000000000000..86c628e4b044 --- /dev/null +++ b/keps/sig-apps/3998-job-success-completion-policy/kep.yaml @@ -0,0 +1,42 @@ +title: Job success/completion policy +kep-number: 3998 +authors: + - "@tenzen-y" +owning-sig: sig-apps +participating-sigs: + - sig-apps +status: implementable +creation-date: 2023-06-05 +reviewers: + - "@mimowo" + - "@alculquicondor" +approvers: + - "@wojtek-t" + - "@soltysh" + +# The target maturity stage in the current dev cycle for this KEP. +stage: alpha + +# The most recent milestone for which work toward delivery of this KEP has been +# done. This can be the current (upcoming) milestone, if it is being actively +# worked on. +latest-milestone: "v1.28" + +# The milestone at which this feature was, or is targeted to be, at each stage. +milestone: + alpha: "v1.28" + beta: "v1.29" + stable: "v1.30" + +# The following PRR answers are required at alpha release +# List the feature gate name and the components for which it must be enabled +feature-gates: + - name: JobSuccessfulPolicy + components: + - kube-apiserver + - kube-controller-manager +disable-supported: true + +# The following PRR answers are required at beta release +metrics: + - jobs_finished_total