mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-25 12:43:23 +00:00
Fix name for Pods of NonIndexed Jobs
Change-Id: I0ea4685a82f4cdec0caab362d52144476652f95a
This commit is contained in:
parent
c4d802b0b5
commit
4ef9d18abe
@ -627,18 +627,7 @@ func (f *FakePodControl) PatchPod(namespace, name string, data []byte) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (f *FakePodControl) CreatePods(namespace string, spec *v1.PodTemplateSpec, object runtime.Object, controllerRef *metav1.OwnerReference) error {
|
func (f *FakePodControl) CreatePods(namespace string, spec *v1.PodTemplateSpec, object runtime.Object, controllerRef *metav1.OwnerReference) error {
|
||||||
f.Lock()
|
return f.CreatePodsWithGenerateName(namespace, spec, object, controllerRef, "")
|
||||||
defer f.Unlock()
|
|
||||||
f.CreateCallCount++
|
|
||||||
if f.CreateLimit != 0 && f.CreateCallCount > f.CreateLimit {
|
|
||||||
return fmt.Errorf("not creating pod, limit %d already reached (create call %d)", f.CreateLimit, f.CreateCallCount)
|
|
||||||
}
|
|
||||||
f.Templates = append(f.Templates, *spec)
|
|
||||||
f.ControllerRefs = append(f.ControllerRefs, *controllerRef)
|
|
||||||
if f.Err != nil {
|
|
||||||
return f.Err
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *FakePodControl) CreatePodsWithGenerateName(namespace string, spec *v1.PodTemplateSpec, object runtime.Object, controllerRef *metav1.OwnerReference, generateNamePrefix string) error {
|
func (f *FakePodControl) CreatePodsWithGenerateName(namespace string, spec *v1.PodTemplateSpec, object runtime.Object, controllerRef *metav1.OwnerReference, generateNamePrefix string) error {
|
||||||
@ -648,6 +637,7 @@ func (f *FakePodControl) CreatePodsWithGenerateName(namespace string, spec *v1.P
|
|||||||
if f.CreateLimit != 0 && f.CreateCallCount > f.CreateLimit {
|
if f.CreateLimit != 0 && f.CreateCallCount > f.CreateLimit {
|
||||||
return fmt.Errorf("not creating pod, limit %d already reached (create call %d)", f.CreateLimit, f.CreateCallCount)
|
return fmt.Errorf("not creating pod, limit %d already reached (create call %d)", f.CreateLimit, f.CreateCallCount)
|
||||||
}
|
}
|
||||||
|
spec.GenerateName = generateNamePrefix
|
||||||
f.Templates = append(f.Templates, *spec)
|
f.Templates = append(f.Templates, *spec)
|
||||||
f.ControllerRefs = append(f.ControllerRefs, *controllerRef)
|
f.ControllerRefs = append(f.ControllerRefs, *controllerRef)
|
||||||
if f.Err != nil {
|
if f.Err != nil {
|
||||||
|
@ -1348,13 +1348,14 @@ func (jm *Controller) manageJob(job *batch.Job, activePods []*v1.Pod, succeeded
|
|||||||
}
|
}
|
||||||
go func() {
|
go func() {
|
||||||
template := podTemplate
|
template := podTemplate
|
||||||
|
generateName := ""
|
||||||
if completionIndex != unknownCompletionIndex {
|
if completionIndex != unknownCompletionIndex {
|
||||||
template = podTemplate.DeepCopy()
|
template = podTemplate.DeepCopy()
|
||||||
addCompletionIndexAnnotation(template, completionIndex)
|
addCompletionIndexAnnotation(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)
|
||||||
}
|
}
|
||||||
defer wait.Done()
|
defer wait.Done()
|
||||||
generateName := podGenerateNameWithIndex(job.Name, completionIndex)
|
|
||||||
err := jm.podControl.CreatePodsWithGenerateName(job.Namespace, template, job, metav1.NewControllerRef(job, controllerKind), generateName)
|
err := jm.podControl.CreatePodsWithGenerateName(job.Namespace, template, job, metav1.NewControllerRef(job, controllerKind), generateName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if apierrors.HasStatusCause(err, v1.NamespaceTerminatingCause) {
|
if apierrors.HasStatusCause(err, v1.NamespaceTerminatingCause) {
|
||||||
|
@ -782,6 +782,16 @@ func TestControllerSyncJob(t *testing.T) {
|
|||||||
}
|
}
|
||||||
if tc.completionMode == batch.IndexedCompletion {
|
if tc.completionMode == batch.IndexedCompletion {
|
||||||
checkIndexedJobPods(t, &fakePodControl, tc.expectedCreatedIndexes, job.Name)
|
checkIndexedJobPods(t, &fakePodControl, tc.expectedCreatedIndexes, job.Name)
|
||||||
|
} else {
|
||||||
|
for _, p := range fakePodControl.Templates {
|
||||||
|
// Fake pod control doesn't add generate name from the owner reference.
|
||||||
|
if p.GenerateName != "" {
|
||||||
|
t.Errorf("Got pod generate name %s, want %s", p.GenerateName, "")
|
||||||
|
}
|
||||||
|
if p.Spec.Hostname != "" {
|
||||||
|
t.Errorf("Got pod hostname %q, want none", p.Spec.Hostname)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if int32(len(fakePodControl.DeletePodName)) != tc.expectedDeletions {
|
if int32(len(fakePodControl.DeletePodName)) != tc.expectedDeletions {
|
||||||
t.Errorf("Unexpected number of deletes. Expected %d, saw %d\n", tc.expectedDeletions, len(fakePodControl.DeletePodName))
|
t.Errorf("Unexpected number of deletes. Expected %d, saw %d\n", tc.expectedDeletions, len(fakePodControl.DeletePodName))
|
||||||
@ -872,9 +882,13 @@ func checkIndexedJobPods(t *testing.T, control *controller.FakePodControl, wantI
|
|||||||
gotIndexes.Insert(ix)
|
gotIndexes.Insert(ix)
|
||||||
}
|
}
|
||||||
expectedName := fmt.Sprintf("%s-%d", jobName, ix)
|
expectedName := fmt.Sprintf("%s-%d", jobName, ix)
|
||||||
if diff := cmp.Equal(expectedName, p.Spec.Hostname); !diff {
|
if expectedName != p.Spec.Hostname {
|
||||||
t.Errorf("Got pod hostname %s, want %s", p.Spec.Hostname, expectedName)
|
t.Errorf("Got pod hostname %s, want %s", p.Spec.Hostname, expectedName)
|
||||||
}
|
}
|
||||||
|
expectedName += "-"
|
||||||
|
if expectedName != p.GenerateName {
|
||||||
|
t.Errorf("Got pod generate name %s, want %s", p.GenerateName, expectedName)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if diff := cmp.Diff(wantIndexes.List(), gotIndexes.List()); diff != "" {
|
if diff := cmp.Diff(wantIndexes.List(), gotIndexes.List()); diff != "" {
|
||||||
t.Errorf("Unexpected created completion indexes (-want,+got):\n%s", diff)
|
t.Errorf("Unexpected created completion indexes (-want,+got):\n%s", diff)
|
||||||
|
Loading…
Reference in New Issue
Block a user