Added back test changes

This commit is contained in:
Sharpz7 2023-08-25 10:35:07 +00:00
parent 5fb049ff47
commit 6ded53ce4d

View File

@ -5197,37 +5197,41 @@ func TestBackupFinalizerRemoval(t *testing.T) {
t.Fatalf("Creating job: %v", err) t.Fatalf("Creating job: %v", err)
} }
// 3. Create the pods. pod := newPod("test-pod", job)
podBuilder := buildPod().name("test_pod").deletionTimestamp().trackingFinalizer().job(job) // pod.Finalizers = append(pod.Finalizers, batch.JobTrackingFinalizer)
pod, err := clientset.CoreV1().Pods(podBuilder.Pod.GetNamespace()).Create(ctx, podBuilder.Pod, metav1.CreateOptions{})
_, err = clientset.CoreV1().Pods(pod.GetNamespace()).Create(ctx, pod, metav1.CreateOptions{})
if err != nil { if err != nil {
t.Fatalf("Creating pod: %v", err) t.Fatalf("Creating pod: %v", err)
} }
// 4. Finish the job.
job.Status.Conditions = append(job.Status.Conditions, batch.JobCondition{ job.Status.Conditions = append(job.Status.Conditions, batch.JobCondition{
Type: batch.JobComplete, Type: batch.JobComplete,
Status: v1.ConditionTrue, Status: v1.ConditionTrue,
}) })
// 5. Start the workers. clientset.BatchV1().Jobs(job.GetNamespace()).UpdateStatus(ctx, job, metav1.UpdateOptions{})
go manager.Run(context.TODO(), 0) go manager.Run(context.TODO(), 0)
err = manager.syncJob(context.TODO(), testutil.GetKey(job, t)) ctx, cancel := context.WithTimeout(context.Background(), wait.ForeverTestTimeout)
if err != nil { defer cancel()
t.Errorf("Unexpected error when syncing jobs %v", err)
}
// Check if the finalizer has been removed from the pod. if err := wait.PollUntilContextTimeout(ctx, 100*time.Millisecond, wait.ForeverTestTimeout, true, func(ctx context.Context) (bool, error) {
if err := wait.Poll(100*time.Millisecond, wait.ForeverTestTimeout, func() (bool, error) { p, err := clientset.CoreV1().Pods(pod.Namespace).Get(ctx, pod.Name, metav1.GetOptions{})
p, err := clientset.CoreV1().Pods(pod.Namespace).Get(context.Background(), pod.Name, metav1.GetOptions{})
if err != nil { if err != nil {
return false, err return false, err
} }
return !hasJobTrackingFinalizer(p), nil return !hasJobTrackingFinalizer(p), nil
}); err != nil { }); err != nil {
t.Errorf("Waiting for Pod to get the finalizer removed: %v", err) // Check for context deadline exceeded, which would mean the operation timed out
if errors.Is(err, context.DeadlineExceeded) {
t.Errorf("Timed out waiting for Pod to get the finalizer removed")
} else {
t.Errorf("Waiting for Pod to get the finalizer removed: %v", err)
}
} }
} }
func checkJobCompletionLabel(t *testing.T, p *v1.PodTemplateSpec) { func checkJobCompletionLabel(t *testing.T, p *v1.PodTemplateSpec) {