mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-16 15:20:17 +00:00
add completion index as pod label
This commit is contained in:
parent
96d853f4b8
commit
2176053415
@ -311,6 +311,14 @@ func addCompletionIndexAnnotation(template *v1.PodTemplateSpec, index int) {
|
|||||||
template.Annotations[batch.JobCompletionIndexAnnotation] = strconv.Itoa(index)
|
template.Annotations[batch.JobCompletionIndexAnnotation] = strconv.Itoa(index)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func addCompletionIndexLabel(template *v1.PodTemplateSpec, index int) {
|
||||||
|
if template.Labels == nil {
|
||||||
|
template.Labels = make(map[string]string, 1)
|
||||||
|
}
|
||||||
|
// Use completion index annotation as label as well for consistency.
|
||||||
|
template.Labels[batch.JobCompletionIndexAnnotation] = strconv.Itoa(index)
|
||||||
|
}
|
||||||
|
|
||||||
func podGenerateNameWithIndex(jobName string, index int) string {
|
func podGenerateNameWithIndex(jobName string, index int) string {
|
||||||
appendIndex := "-" + strconv.Itoa(index) + "-"
|
appendIndex := "-" + strconv.Itoa(index) + "-"
|
||||||
generateNamePrefix := jobName + appendIndex
|
generateNamePrefix := jobName + appendIndex
|
||||||
|
@ -1482,6 +1482,7 @@ func (jm *Controller) manageJob(ctx context.Context, job *batch.Job, activePods
|
|||||||
if completionIndex != unknownCompletionIndex {
|
if completionIndex != unknownCompletionIndex {
|
||||||
template = podTemplate.DeepCopy()
|
template = podTemplate.DeepCopy()
|
||||||
addCompletionIndexAnnotation(template, completionIndex)
|
addCompletionIndexAnnotation(template, completionIndex)
|
||||||
|
addCompletionIndexLabel(template, completionIndex)
|
||||||
template.Spec.Hostname = fmt.Sprintf("%s-%d", job.Name, completionIndex)
|
template.Spec.Hostname = fmt.Sprintf("%s-%d", job.Name, completionIndex)
|
||||||
generateName = podGenerateNameWithIndex(job.Name, completionIndex)
|
generateName = podGenerateNameWithIndex(job.Name, completionIndex)
|
||||||
}
|
}
|
||||||
|
@ -962,6 +962,7 @@ func checkIndexedJobPods(t *testing.T, control *controller.FakePodControl, wantI
|
|||||||
gotIndexes := sets.New[int]()
|
gotIndexes := sets.New[int]()
|
||||||
for _, p := range control.Templates {
|
for _, p := range control.Templates {
|
||||||
checkJobCompletionEnvVariable(t, &p.Spec)
|
checkJobCompletionEnvVariable(t, &p.Spec)
|
||||||
|
checkJobCompletionLabel(t, &p)
|
||||||
ix := getCompletionIndex(p.Annotations)
|
ix := getCompletionIndex(p.Annotations)
|
||||||
if ix == -1 {
|
if ix == -1 {
|
||||||
t.Errorf("Created pod %s didn't have completion index", p.Name)
|
t.Errorf("Created pod %s didn't have completion index", p.Name)
|
||||||
@ -4394,6 +4395,13 @@ func TestFinalizersRemovedExpectations(t *testing.T) {
|
|||||||
t.Errorf("Timeout waiting for expectations (-want, +got):\n%s", diff)
|
t.Errorf("Timeout waiting for expectations (-want, +got):\n%s", diff)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
func checkJobCompletionLabel(t *testing.T, p *v1.PodTemplateSpec) {
|
||||||
|
t.Helper()
|
||||||
|
labels := p.GetLabels()
|
||||||
|
if labels == nil || labels[batch.JobCompletionIndexAnnotation] == "" {
|
||||||
|
t.Errorf("missing expected pod label %s", batch.JobCompletionIndexAnnotation)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func checkJobCompletionEnvVariable(t *testing.T, spec *v1.PodSpec) {
|
func checkJobCompletionEnvVariable(t *testing.T, spec *v1.PodSpec) {
|
||||||
t.Helper()
|
t.Helper()
|
||||||
|
Loading…
Reference in New Issue
Block a user