use job completion index annotation as label

This commit is contained in:
Daniel Vega-Myhre 2023-07-13 21:03:18 +00:00
parent 98c6e25c37
commit 1ae60c0ed1
4 changed files with 6 additions and 6 deletions

View File

@ -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 {

View File

@ -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)
}
}

View File

@ -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

View File

@ -28,8 +28,6 @@ const (
labelPrefix = "batch.kubernetes.io/"
JobCompletionIndexAnnotation = labelPrefix + "job-completion-index"
// JobCompletionIndexLabel is defined following the format <controller>.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.
//