Skip to content

Commit 2923e6b

Browse files
authored
Merge pull request #28841 from alculquicondor/job-tracking
Add feature gate JobTrackingWithFinalizers
2 parents a1fd3a2 + a6b6a97 commit 2923e6b

File tree

3 files changed

+55
-0
lines changed

3 files changed

+55
-0
lines changed

content/en/docs/concepts/workloads/controllers/job.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -561,6 +561,46 @@ The new Job itself will have a different uid from `a8f3d00d-c6d2-11e5-9f87-42010
561561
`manualSelector: true` tells the system to that you know what you are doing and to allow this
562562
mismatch.
563563

564+
### Job tracking with finalizers
565+
566+
{{< feature-state for_k8s_version="v1.22" state="alpha" >}}
567+
568+
{{< note >}}
569+
In order to use this behavior, you must enable the `JobTrackingWithFinalizers`
570+
[feature gate](/docs/reference/command-line-tools-reference/feature-gates/)
571+
on the [API server](/docs/reference/command-line-tools-reference/kube-apiserver/)
572+
and the [controller manager](/docs/reference/command-line-tools-reference/kube-controller-manager/).
573+
It is disabled by default.
574+
575+
When enabled, the control plane tracks new Jobs using the behavior described
576+
below. Existing Jobs are unaffected. As a user, the only difference you would
577+
see is that the control plane tracking of Job completion is more accurate.
578+
{{< /note >}}
579+
580+
When this feature isn't enabled, the Job {{< glossary_tooltip term_id="controller" >}}
581+
relies on counting the Pods that exist in the cluster to track the Job status,
582+
that is, to keep the counters for `succeeded` and `failed` Pods.
583+
However, Pods can be removed for a number of reasons, including:
584+
- The garbage collector that removes orphan Pods when a Node goes down.
585+
- The garbage collector that removes finished Pods (in `Succeeded` or `Failed`
586+
phase) after a threshold.
587+
- Human intervention to delete Pods belonging to a Job.
588+
- An external controller (not provided as part of Kubernetes) that removes or
589+
replaces Pods.
590+
591+
If you enable the `JobTrackingWithFinalizers` feature for your cluster, the
592+
control plane keeps track of the Pods that belong to any Job and notices if any
593+
such Pod is removed from the API server. To do that, the Job controller creates Pods with
594+
the finalizer `batch.kubernetes.io/job-tracking`. The controller removes the
595+
finalizer only after the Pod has been accounted for in the Job status, allowing
596+
the Pod to be removed by other controllers or users.
597+
598+
The Job controller uses the new algorithm for new Jobs only. Jobs created
599+
before the feature is enabled are unaffected. You can determine if the Job
600+
controller is tracking a Job using Pod finalizers by checking if the Job has the
601+
annotation `batch.kubernetes.io/job-tracking`. You should **not** manually add
602+
or remove this annotation from Jobs.
603+
564604
## Alternatives
565605

566606
### Bare Pods

content/en/docs/reference/command-line-tools-reference/feature-gates.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ different Kubernetes components.
129129
| `HugePageStorageMediumSize` | `true` | Beta | 1.19 | |
130130
| `IndexedJob` | `false` | Alpha | 1.21 | 1.21 |
131131
| `IndexedJob` | `true` | Beta | 1.22 | |
132+
| `JobTrackingWithFinalizers` | `false` | Alpha | 1.22 | |
132133
| `IngressClassNamespacedParams` | `false` | Alpha | 1.21 | 1.21 |
133134
| `IngressClassNamespacedParams` | `true` | Beta | 1.22 | |
134135
| `IPv6DualStack` | `false` | Alpha | 1.15 | 1.20 |
@@ -729,6 +730,10 @@ Each feature gate is designed for enabling/disabling a specific feature:
729730
immutable for better safety and performance.
730731
- `IndexedJob`: Allows the [Job](/docs/concepts/workloads/controllers/job/)
731732
controller to manage Pod completions per completion index.
733+
- `JobTrackingWithFinalizers`: Enables tracking [Job](/docs/concepts/workloads/controllers/job)
734+
completions without relying on Pods remaining in the cluster indefinitely.
735+
The Job controller uses Pod finalizers and a field in the Job status to keep
736+
track of the finished Pods to count towards completion.
732737
- `IngressClassNamespacedParams`: Allow namespace-scoped parameters reference in
733738
`IngressClass` resource. This feature adds two fields - `Scope` and `Namespace`
734739
to `IngressClass.spec.parameters`.

content/en/docs/reference/labels-annotations-taints.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,16 @@ Used on: Endpoints
268268

269269
In Kubernetes clusters v1.21 (or later), the Endpoints controller adds this annotation to an Endpoints resource if it has more than 1000 endpoints. The annotation indicates that the Endpoints resource is over capacity.
270270

271+
## batch.kubernetes.io/job-tracking
272+
273+
Example: `batch.kubernetes.io/job-tracking: ""`
274+
275+
Used on: Jobs
276+
277+
The presence of this annotation on a Job indicates that the control plane is
278+
[tracking the Job status using finalizers](/docs/concepts/workloads/controllers/job/#job-tracking-with-finalizers).
279+
You should **not** manually add or remove this annotation.
280+
271281
## scheduler.alpha.kubernetes.io/preferAvoidPods (deprecated) {#scheduleralphakubernetesio-preferavoidpods}
272282

273283
Used on: Nodes

0 commit comments

Comments
 (0)