From 551931c6a85f1b319608559267cf118d266c643d Mon Sep 17 00:00:00 2001 From: Yuki Iwai Date: Sat, 13 Jul 2024 03:00:18 +0900 Subject: [PATCH] Graduate the JobSuccessPolicy to beta Signed-off-by: Yuki Iwai --- api/openapi-spec/swagger.json | 2 +- .../v3/apis__batch__v1_openapi.json | 2 +- pkg/apis/batch/types.go | 4 +- pkg/controller/job/job_controller_test.go | 42 ++++++++++++------- pkg/features/kube_features.go | 3 +- pkg/generated/openapi/zz_generated.openapi.go | 2 +- .../src/k8s.io/api/batch/v1/generated.proto | 4 +- staging/src/k8s.io/api/batch/v1/types.go | 6 +-- .../batch/v1/types_swagger_doc_generated.go | 2 +- test/integration/job/job_test.go | 14 +++---- 10 files changed, 48 insertions(+), 33 deletions(-) diff --git a/api/openapi-spec/swagger.json b/api/openapi-spec/swagger.json index b0c21560dd6..0bc7a1e91b3 100644 --- a/api/openapi-spec/swagger.json +++ b/api/openapi-spec/swagger.json @@ -4845,7 +4845,7 @@ }, "successPolicy": { "$ref": "#/definitions/io.k8s.api.batch.v1.SuccessPolicy", - "description": "successPolicy 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. When the field is specified, it must be immutable and works only for the Indexed Jobs. Once the Job meets the SuccessPolicy, the lingering pods are terminated.\n\nThis field is alpha-level. To use this field, you must enable the `JobSuccessPolicy` feature gate (disabled by default)." + "description": "successPolicy 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. When the field is specified, it must be immutable and works only for the Indexed Jobs. Once the Job meets the SuccessPolicy, the lingering pods are terminated.\n\nThis field is beta-level. To use this field, you must enable the `JobSuccessPolicy` feature gate (enabled by default)." }, "suspend": { "description": "suspend specifies whether the Job controller should create Pods or not. If a Job is created with suspend set to true, no Pods are created by the Job controller. If a Job is suspended after creation (i.e. the flag goes from false to true), the Job controller will delete all active Pods associated with this Job. Users must design their workload to gracefully handle this. Suspending a Job will reset the StartTime field of the Job, effectively resetting the ActiveDeadlineSeconds timer too. Defaults to false.", diff --git a/api/openapi-spec/v3/apis__batch__v1_openapi.json b/api/openapi-spec/v3/apis__batch__v1_openapi.json index c985a3945a6..2bd9d655ac1 100644 --- a/api/openapi-spec/v3/apis__batch__v1_openapi.json +++ b/api/openapi-spec/v3/apis__batch__v1_openapi.json @@ -388,7 +388,7 @@ "$ref": "#/components/schemas/io.k8s.api.batch.v1.SuccessPolicy" } ], - "description": "successPolicy 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. When the field is specified, it must be immutable and works only for the Indexed Jobs. Once the Job meets the SuccessPolicy, the lingering pods are terminated.\n\nThis field is alpha-level. To use this field, you must enable the `JobSuccessPolicy` feature gate (disabled by default)." + "description": "successPolicy 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. When the field is specified, it must be immutable and works only for the Indexed Jobs. Once the Job meets the SuccessPolicy, the lingering pods are terminated.\n\nThis field is beta-level. To use this field, you must enable the `JobSuccessPolicy` feature gate (enabled by default)." }, "suspend": { "description": "suspend specifies whether the Job controller should create Pods or not. If a Job is created with suspend set to true, no Pods are created by the Job controller. If a Job is suspended after creation (i.e. the flag goes from false to true), the Job controller will delete all active Pods associated with this Job. Users must design their workload to gracefully handle this. Suspending a Job will reset the StartTime field of the Job, effectively resetting the ActiveDeadlineSeconds timer too. Defaults to false.", diff --git a/pkg/apis/batch/types.go b/pkg/apis/batch/types.go index a76fa859dd9..19ca116208b 100644 --- a/pkg/apis/batch/types.go +++ b/pkg/apis/batch/types.go @@ -339,8 +339,8 @@ type JobSpec struct { // When the field is specified, it must be immutable and works only for the Indexed Jobs. // Once the Job meets the SuccessPolicy, the lingering pods are terminated. // - // This field is alpha-level. To use this field, you must enable the - // `JobSuccessPolicy` feature gate (disabled by default). + // This field is beta-level. To use this field, you must enable the + // `JobSuccessPolicy` feature gate (enabled by default). // +optional SuccessPolicy *SuccessPolicy diff --git a/pkg/controller/job/job_controller_test.go b/pkg/controller/job/job_controller_test.go index b79226a9c39..49e814c1d8f 100644 --- a/pkg/controller/job/job_controller_test.go +++ b/pkg/controller/job/job_controller_test.go @@ -5171,12 +5171,16 @@ func TestSyncJobWithJobBackoffLimitPerIndex(t *testing.T) { UncountedTerminatedPods: &batch.UncountedTerminatedPods{}, Conditions: []batch.JobCondition{ { - Type: batch.JobSuccessCriteriaMet, - Status: v1.ConditionTrue, + Type: batch.JobSuccessCriteriaMet, + Status: v1.ConditionTrue, + Reason: batch.JobReasonCompletionsReached, + Message: "Reached expected number of succeeded pods", }, { - Type: batch.JobComplete, - Status: v1.ConditionTrue, + Type: batch.JobComplete, + Status: v1.ConditionTrue, + Reason: batch.JobReasonCompletionsReached, + Message: "Reached expected number of succeeded pods", }, }, }, @@ -7105,8 +7109,10 @@ func TestJobBackoffForOnFailure(t *testing.T) { expectedFailed: 0, expectedConditions: []batch.JobCondition{ { - Type: batch.JobComplete, - Status: v1.ConditionTrue, + Type: batch.JobComplete, + Status: v1.ConditionTrue, + Reason: batch.JobReasonCompletionsReached, + Message: "Reached expected number of succeeded pods", }, }, }, @@ -7124,12 +7130,16 @@ func TestJobBackoffForOnFailure(t *testing.T) { expectedFailed: 0, expectedConditions: []batch.JobCondition{ { - Type: batch.JobSuccessCriteriaMet, - Status: v1.ConditionTrue, + Type: batch.JobSuccessCriteriaMet, + Status: v1.ConditionTrue, + Reason: batch.JobReasonCompletionsReached, + Message: "Reached expected number of succeeded pods", }, { - Type: batch.JobComplete, - Status: v1.ConditionTrue, + Type: batch.JobComplete, + Status: v1.ConditionTrue, + Reason: batch.JobReasonCompletionsReached, + Message: "Reached expected number of succeeded pods", }, }, }, @@ -7147,12 +7157,16 @@ func TestJobBackoffForOnFailure(t *testing.T) { expectedFailed: 0, expectedConditions: []batch.JobCondition{ { - Type: batch.JobSuccessCriteriaMet, - Status: v1.ConditionTrue, + Type: batch.JobSuccessCriteriaMet, + Status: v1.ConditionTrue, + Reason: batch.JobReasonCompletionsReached, + Message: "Reached expected number of succeeded pods", }, { - Type: batch.JobComplete, - Status: v1.ConditionTrue, + Type: batch.JobComplete, + Status: v1.ConditionTrue, + Reason: batch.JobReasonCompletionsReached, + Message: "Reached expected number of succeeded pods", }, }, }, diff --git a/pkg/features/kube_features.go b/pkg/features/kube_features.go index 93c98a97cd5..9c6f07a826b 100644 --- a/pkg/features/kube_features.go +++ b/pkg/features/kube_features.go @@ -369,6 +369,7 @@ const ( // owner: @tenzen-y // kep: https://kep.k8s.io/3998 // alpha: v1.30 + // beta: v1.31 // // Allow users to specify when a Job can be declared as succeeded // based on the set of succeeded pods. @@ -1094,7 +1095,7 @@ var defaultKubernetesFeatureGates = map[featuregate.Feature]featuregate.FeatureS JobPodReplacementPolicy: {Default: true, PreRelease: featuregate.Beta}, - JobSuccessPolicy: {Default: false, PreRelease: featuregate.Alpha}, + JobSuccessPolicy: {Default: true, PreRelease: featuregate.Beta}, KubeletCgroupDriverFromCRI: {Default: true, PreRelease: featuregate.Beta}, diff --git a/pkg/generated/openapi/zz_generated.openapi.go b/pkg/generated/openapi/zz_generated.openapi.go index 4a5e35e48fe..ba21737ce91 100644 --- a/pkg/generated/openapi/zz_generated.openapi.go +++ b/pkg/generated/openapi/zz_generated.openapi.go @@ -17224,7 +17224,7 @@ func schema_k8sio_api_batch_v1_JobSpec(ref common.ReferenceCallback) common.Open }, "successPolicy": { SchemaProps: spec.SchemaProps{ - Description: "successPolicy 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. When the field is specified, it must be immutable and works only for the Indexed Jobs. Once the Job meets the SuccessPolicy, the lingering pods are terminated.\n\nThis field is alpha-level. To use this field, you must enable the `JobSuccessPolicy` feature gate (disabled by default).", + Description: "successPolicy 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. When the field is specified, it must be immutable and works only for the Indexed Jobs. Once the Job meets the SuccessPolicy, the lingering pods are terminated.\n\nThis field is beta-level. To use this field, you must enable the `JobSuccessPolicy` feature gate (enabled by default).", Ref: ref("k8s.io/api/batch/v1.SuccessPolicy"), }, }, diff --git a/staging/src/k8s.io/api/batch/v1/generated.proto b/staging/src/k8s.io/api/batch/v1/generated.proto index 68c57364acd..f5a9385f5e0 100644 --- a/staging/src/k8s.io/api/batch/v1/generated.proto +++ b/staging/src/k8s.io/api/batch/v1/generated.proto @@ -222,8 +222,8 @@ message JobSpec { // When the field is specified, it must be immutable and works only for the Indexed Jobs. // Once the Job meets the SuccessPolicy, the lingering pods are terminated. // - // This field is alpha-level. To use this field, you must enable the - // `JobSuccessPolicy` feature gate (disabled by default). + // This field is beta-level. To use this field, you must enable the + // `JobSuccessPolicy` feature gate (enabled by default). // +optional optional SuccessPolicy successPolicy = 16; diff --git a/staging/src/k8s.io/api/batch/v1/types.go b/staging/src/k8s.io/api/batch/v1/types.go index d91435b84d2..b42ec231e45 100644 --- a/staging/src/k8s.io/api/batch/v1/types.go +++ b/staging/src/k8s.io/api/batch/v1/types.go @@ -347,8 +347,8 @@ type JobSpec struct { // When the field is specified, it must be immutable and works only for the Indexed Jobs. // Once the Job meets the SuccessPolicy, the lingering pods are terminated. // - // This field is alpha-level. To use this field, you must enable the - // `JobSuccessPolicy` feature gate (disabled by default). + // This field is beta-level. To use this field, you must enable the + // `JobSuccessPolicy` feature gate (enabled by default). // +optional SuccessPolicy *SuccessPolicy `json:"successPolicy,omitempty" protobuf:"bytes,16,opt,name=successPolicy"` @@ -649,7 +649,7 @@ const ( // JobReasonSuccessPolicy reason indicates a SuccessCriteriaMet condition is added due to // a Job met successPolicy. // https://kep.k8s.io/3998 - // This is currently an alpha field. + // This is currently a beta field. JobReasonSuccessPolicy string = "SuccessPolicy" // JobReasonCompletionsReached reason indicates a SuccessCriteriaMet condition is added due to // a number of succeeded Job pods met completions. diff --git a/staging/src/k8s.io/api/batch/v1/types_swagger_doc_generated.go b/staging/src/k8s.io/api/batch/v1/types_swagger_doc_generated.go index 0ffdcadd86d..d504887884a 100644 --- a/staging/src/k8s.io/api/batch/v1/types_swagger_doc_generated.go +++ b/staging/src/k8s.io/api/batch/v1/types_swagger_doc_generated.go @@ -116,7 +116,7 @@ var map_JobSpec = map[string]string{ "completions": "Specifies the desired number of successfully finished pods the job should be run with. Setting to null means that the success of any pod signals the success of all pods, and allows parallelism to have any positive value. Setting to 1 means that parallelism is limited to 1 and the success of that pod signals the success of the job. More info: https://kubernetes.io/docs/concepts/workloads/controllers/jobs-run-to-completion/", "activeDeadlineSeconds": "Specifies the duration in seconds relative to the startTime that the job may be continuously active before the system tries to terminate it; value must be positive integer. If a Job is suspended (at creation or through an update), this timer will effectively be stopped and reset when the Job is resumed again.", "podFailurePolicy": "Specifies the policy of handling failed pods. In particular, it allows to specify the set of actions and conditions which need to be satisfied to take the associated action. If empty, the default behaviour applies - the counter of failed pods, represented by the jobs's .status.failed field, is incremented and it is checked against the backoffLimit. This field cannot be used in combination with restartPolicy=OnFailure.", - "successPolicy": "successPolicy 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. When the field is specified, it must be immutable and works only for the Indexed Jobs. Once the Job meets the SuccessPolicy, the lingering pods are terminated.\n\nThis field is alpha-level. To use this field, you must enable the `JobSuccessPolicy` feature gate (disabled by default).", + "successPolicy": "successPolicy 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. When the field is specified, it must be immutable and works only for the Indexed Jobs. Once the Job meets the SuccessPolicy, the lingering pods are terminated.\n\nThis field is beta-level. To use this field, you must enable the `JobSuccessPolicy` feature gate (enabled by default).", "backoffLimit": "Specifies the number of retries before marking this job failed. Defaults to 6", "backoffLimitPerIndex": "Specifies the limit for the number of retries within an index before marking this index as failed. When enabled the number of failures per index is kept in the pod's batch.kubernetes.io/job-index-failure-count annotation. It can only be set when Job's completionMode=Indexed, and the Pod's restart policy is Never. The field is immutable. This field is beta-level. It can be used when the `JobBackoffLimitPerIndex` feature gate is enabled (enabled by default).", "maxFailedIndexes": "Specifies the maximal number of failed indexes before marking the Job as failed, when backoffLimitPerIndex is set. Once the number of failed indexes exceeds this number the entire Job is marked as Failed and its execution is terminated. When left as null the job continues execution of all of its indexes and is marked with the `Complete` Job condition. It can only be specified when backoffLimitPerIndex is set. It can be null or up to completions. It is required and must be less than or equal to 10^4 when is completions greater than 10^5. This field is beta-level. It can be used when the `JobBackoffLimitPerIndex` feature gate is enabled (enabled by default).", diff --git a/test/integration/job/job_test.go b/test/integration/job/job_test.go index 9908f6ca882..39955ca8471 100644 --- a/test/integration/job/job_test.go +++ b/test/integration/job/job_test.go @@ -389,7 +389,7 @@ func TestJobPodFailurePolicy(t *testing.T) { Value: 1, }, wantJobFinishedMetric: metricLabelsWithValue{ - Labels: []string{"NonIndexed", "succeeded", ""}, + Labels: []string{"NonIndexed", "succeeded", "CompletionsReached"}, Value: 1, }, }, @@ -400,7 +400,7 @@ func TestJobPodFailurePolicy(t *testing.T) { wantFailed: 1, wantJobConditionType: batchv1.JobComplete, wantJobFinishedMetric: metricLabelsWithValue{ - Labels: []string{"NonIndexed", "succeeded", ""}, + Labels: []string{"NonIndexed", "succeeded", "CompletionsReached"}, Value: 1, }, wantPodFailuresHandledByPolicyRuleMetric: &metricLabelsWithValue{ @@ -415,7 +415,7 @@ func TestJobPodFailurePolicy(t *testing.T) { wantFailed: 1, wantJobConditionType: batchv1.JobComplete, wantJobFinishedMetric: metricLabelsWithValue{ - Labels: []string{"NonIndexed", "succeeded", ""}, + Labels: []string{"NonIndexed", "succeeded", "CompletionsReached"}, Value: 1, }, wantPodFailuresHandledByPolicyRuleMetric: &metricLabelsWithValue{ @@ -2474,7 +2474,7 @@ func TestNonParallelJob(t *testing.T) { }) validateFinishedPodsNoFinalizer(ctx, t, clientSet, jobObj) validateCounterMetric(ctx, t, metrics.JobFinishedNum, metricLabelsWithValue{ - Labels: []string{"NonIndexed", "succeeded", ""}, + Labels: []string{"NonIndexed", "succeeded", "CompletionsReached"}, Value: 1, }) validateCounterMetric(ctx, t, metrics.JobPodsFinished, metricLabelsWithValue{ @@ -2562,7 +2562,7 @@ func TestParallelJob(t *testing.T) { validateFinishedPodsNoFinalizer(ctx, t, clientSet, jobObj) validateTerminatedPodsTrackingFinalizerMetric(ctx, t, 7) validateCounterMetric(ctx, t, metrics.JobFinishedNum, metricLabelsWithValue{ - Labels: []string{"NonIndexed", "succeeded", ""}, + Labels: []string{"NonIndexed", "succeeded", "CompletionsReached"}, Value: 1, }) validateCounterMetric(ctx, t, metrics.JobPodsFinished, metricLabelsWithValue{ @@ -2704,7 +2704,7 @@ func TestParallelJobWithCompletions(t *testing.T) { validateJobPodsStatus(ctx, t, clientSet, jobObj, want) validateFinishedPodsNoFinalizer(ctx, t, clientSet, jobObj) validateCounterMetric(ctx, t, metrics.JobFinishedNum, metricLabelsWithValue{ - Labels: []string{"NonIndexed", "succeeded", ""}, + Labels: []string{"NonIndexed", "succeeded", "CompletionsReached"}, Value: 1, }) validateCounterMetric(ctx, t, metrics.JobPodsFinished, metricLabelsWithValue{ @@ -2800,7 +2800,7 @@ func TestIndexedJob(t *testing.T) { Value: 4, }) validateCounterMetric(ctx, t, metrics.JobFinishedNum, metricLabelsWithValue{ - Labels: []string{"Indexed", "succeeded", ""}, + Labels: []string{"Indexed", "succeeded", "CompletionsReached"}, Value: 1, }) validateCounterMetric(ctx, t, metrics.JobPodsFinished, metricLabelsWithValue{