mirror of
https://github.com/kubernetes/kubernetes.git
synced 2026-06-10 17:35:44 -04:00
Merge pull request #136920 from ysam12345/master
Fix empty namespace when fetching existing job in cronjob controller
This commit is contained in:
commit
ffa41ed792
3 changed files with 25 additions and 9 deletions
|
|
@ -638,7 +638,7 @@ func (jm *ControllerV2) syncCronJob(
|
|||
// but failed to update the active list in the status, in which case we should reattempt to add the job
|
||||
// into the active list and update the status.
|
||||
jobAlreadyExists = true
|
||||
job, err := jm.jobControl.GetJob(jobReq.GetNamespace(), jobReq.GetName())
|
||||
job, err := jm.jobControl.GetJob(cronJob.Namespace, jobReq.GetName())
|
||||
if err != nil {
|
||||
return nil, updateStatus, err
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1836,6 +1836,13 @@ func TestControllerV2JobAlreadyExistsButNotInActiveStatus(t *testing.T) {
|
|||
if !reflect.DeepEqual(cronJobControl.Updates[0].Status.Active[0], *expectedActiveRef) {
|
||||
t.Errorf("Unexpected job reference in cronjob active list, got: %v, expected: %v", cronJobControl.Updates[0].Status.Active[0], expectedActiveRef)
|
||||
}
|
||||
|
||||
if len(jobControl.GetJobNamespace) != 1 {
|
||||
t.Fatalf("Unexpected get job count, got: %d, expected 1", len(jobControl.GetJobNamespace))
|
||||
}
|
||||
if jobControl.GetJobNamespace[0] != cj.Namespace {
|
||||
t.Fatalf("Unexpected job's namespace, got: %s, expected %s", jobControl.GetJobNamespace[0], cj.Namespace)
|
||||
}
|
||||
}
|
||||
|
||||
// TestControllerV2JobAlreadyExistsButDifferentOwnner validates that an already created job
|
||||
|
|
@ -1882,4 +1889,11 @@ func TestControllerV2JobAlreadyExistsButDifferentOwner(t *testing.T) {
|
|||
if len(cronJobControl.Updates) != 0 {
|
||||
t.Fatalf("Unexpected updates to cronjob, got: %d, expected 0", len(cronJobControl.Updates))
|
||||
}
|
||||
|
||||
if len(jobControl.GetJobNamespace) != 1 {
|
||||
t.Fatalf("Unexpected get job count, got: %d, expected 1", len(jobControl.GetJobNamespace))
|
||||
}
|
||||
if jobControl.GetJobNamespace[0] != cj.Namespace {
|
||||
t.Fatalf("Unexpected job's namespace, got: %s, expected %s", jobControl.GetJobNamespace[0], cj.Namespace)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -111,14 +111,15 @@ func (r realJobControl) DeleteJob(namespace string, name string) error {
|
|||
|
||||
type fakeJobControl struct {
|
||||
sync.Mutex
|
||||
Job *batchv1.Job
|
||||
Jobs []batchv1.Job
|
||||
DeleteJobName []string
|
||||
Err error
|
||||
CreateErr error
|
||||
UpdateJobName []string
|
||||
PatchJobName []string
|
||||
Patches [][]byte
|
||||
Job *batchv1.Job
|
||||
Jobs []batchv1.Job
|
||||
DeleteJobName []string
|
||||
Err error
|
||||
CreateErr error
|
||||
UpdateJobName []string
|
||||
PatchJobName []string
|
||||
Patches [][]byte
|
||||
GetJobNamespace []string
|
||||
}
|
||||
|
||||
var _ jobControlInterface = &fakeJobControl{}
|
||||
|
|
@ -140,6 +141,7 @@ func (f *fakeJobControl) GetJob(namespace, name string) (*batchv1.Job, error) {
|
|||
if f.Err != nil {
|
||||
return nil, f.Err
|
||||
}
|
||||
f.GetJobNamespace = append(f.GetJobNamespace, namespace)
|
||||
return f.Job, nil
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue