diff --git a/pkg/controller/job/indexed_job_utils.go b/pkg/controller/job/indexed_job_utils.go index 9ec8f8535b2..0778e60ba58 100644 --- a/pkg/controller/job/indexed_job_utils.go +++ b/pkg/controller/job/indexed_job_utils.go @@ -315,7 +315,8 @@ func addCompletionIndexLabel(template *v1.PodTemplateSpec, index int) { if template.Labels == nil { template.Labels = make(map[string]string, 1) } - template.Labels[batch.JobCompletionIndexLabel] = strconv.Itoa(index) + // For consistency, we use the annotation batch.kubernetes.io/job-completion-index for the corresponding label as well. + template.Labels[batch.JobCompletionIndexAnnotation] = strconv.Itoa(index) } func podGenerateNameWithIndex(jobName string, index int) string { diff --git a/pkg/controller/job/job_controller_test.go b/pkg/controller/job/job_controller_test.go index e3b71aa68d9..c9c147c6e41 100644 --- a/pkg/controller/job/job_controller_test.go +++ b/pkg/controller/job/job_controller_test.go @@ -4413,8 +4413,8 @@ func TestFinalizersRemovedExpectations(t *testing.T) { func checkJobCompletionLabel(t *testing.T, p *v1.PodTemplateSpec) { t.Helper() labels := p.GetLabels() - if labels == nil || labels[batch.JobCompletionIndexLabel] == "" { - t.Errorf("missing expected pod label %s", batch.JobCompletionIndexLabel) + if labels == nil || labels[batch.JobCompletionIndexAnnotation] == "" { + t.Errorf("missing expected pod label %s", batch.JobCompletionIndexAnnotation) } } diff --git a/staging/src/k8s.io/api/apps/v1/types.go b/staging/src/k8s.io/api/apps/v1/types.go index 15dc3150a63..c3f5a6e21c3 100644 --- a/staging/src/k8s.io/api/apps/v1/types.go +++ b/staging/src/k8s.io/api/apps/v1/types.go @@ -17,7 +17,7 @@ limitations under the License. package v1 import ( - "k8s.io/api/core/v1" + v1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" runtime "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/util/intstr" @@ -29,6 +29,7 @@ const ( DeprecatedRollbackTo = "deprecated.deployment.rollback.to" DeprecatedTemplateGeneration = "deprecated.daemonset.template.generation" StatefulSetPodNameLabel = "statefulset.kubernetes.io/pod-name" + StatefulSetPodIndexLabel = "statefulset.kubernetes.io/pod-index" ) // +genclient diff --git a/staging/src/k8s.io/api/batch/v1/types.go b/staging/src/k8s.io/api/batch/v1/types.go index 15cc874ff21..22cf9ee9cb6 100644 --- a/staging/src/k8s.io/api/batch/v1/types.go +++ b/staging/src/k8s.io/api/batch/v1/types.go @@ -28,8 +28,6 @@ const ( labelPrefix = "batch.kubernetes.io/" JobCompletionIndexAnnotation = labelPrefix + "job-completion-index" - // JobCompletionIndexLabel is defined following the format .kubernetes.io/pod-index - JobCompletionIndexLabel = "job.kubernetes.io/pod-index" // JobTrackingFinalizer is a finalizer for Job's pods. It prevents them from // being deleted before being accounted in the Job status. //