Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Job conformance test for job status updates #123751

Merged
merged 1 commit into from Mar 7, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
40 changes: 34 additions & 6 deletions test/e2e/apps/job.go
Expand Up @@ -848,12 +848,19 @@ done`}
err = e2ejob.WaitForJobPodsRunning(ctx, f.ClientSet, f.Namespace.Name, job.Name, parallelism)
framework.ExpectNoError(err, "failed to ensure number of pods associated with job %s is equal to parallelism count in namespace: %s", job.Name, f.Namespace.Name)

customConditionType := batchv1.JobConditionType("CustomConditionType")
// /status subresource operations
ginkgo.By("patching /status")
// we need to use RFC3339 version since conversion over the wire cuts nanoseconds
now1 := metav1.Now().Rfc3339Copy()
jStatus := batchv1.JobStatus{
StartTime: &now1,
Conditions: []batchv1.JobCondition{
{
Type: customConditionType,
Status: v1.ConditionTrue,
LastTransitionTime: now1,
},
},
}

jStatusJSON, err := json.Marshal(jStatus)
Expand All @@ -862,8 +869,12 @@ done`}
[]byte(`{"metadata":{"annotations":{"patchedstatus":"true"}},"status":`+string(jStatusJSON)+`}`),
metav1.PatchOptions{}, "status")
framework.ExpectNoError(err)
if !patchedStatus.Status.StartTime.Equal(&now1) {
framework.Failf("patched object should have the applied StartTime %#v, got %#v instead", jStatus.StartTime, patchedStatus.Status.StartTime)
if condition := findConditionByType(patchedStatus.Status.Conditions, customConditionType); condition != nil {
if !condition.LastTransitionTime.Equal(&now1) {
framework.Failf("patched object should have the applied condition with LastTransitionTime %#v, got %#v instead", now1, condition.LastTransitionTime)
}
} else {
framework.Failf("patched object does not have the required condition %v", customConditionType)
}
gomega.Expect(patchedStatus.Annotations).To(gomega.HaveKeyWithValue("patchedstatus", "true"), "patched object should have the applied annotation")

Expand All @@ -876,13 +887,21 @@ done`}
if err != nil {
return err
}
statusToUpdate.Status.StartTime = &now2
if condition := findConditionByType(patchedStatus.Status.Conditions, customConditionType); condition != nil {
condition.LastTransitionTime = now2
} else {
framework.Failf("patched object does not have the required condition %v", customConditionType)
}
updatedStatus, err = jClient.UpdateStatus(ctx, statusToUpdate, metav1.UpdateOptions{})
return err
})
framework.ExpectNoError(err)
if !updatedStatus.Status.StartTime.Equal(&now2) {
framework.Failf("updated object status expected to have updated StartTime %#v, got %#v", statusToUpdate.Status.StartTime, updatedStatus.Status.StartTime)
if condition := findConditionByType(updatedStatus.Status.Conditions, customConditionType); condition != nil {
if !condition.LastTransitionTime.Equal(&now2) {
framework.Failf("patched object should have the applied condition with LastTransitionTime %#v, got %#v instead", now2, condition.LastTransitionTime)
}
} else {
framework.Failf("patched object does not have the required condition %v", customConditionType)
}

ginkgo.By("get /status")
Expand Down Expand Up @@ -1119,3 +1138,12 @@ func waitForJobFailure(ctx context.Context, c clientset.Interface, ns, jobName s
return false, nil
})
}

func findConditionByType(list []batchv1.JobCondition, cType batchv1.JobConditionType) *batchv1.JobCondition {
for i := range list {
if list[i].Type == cType {
return &list[i]
}
}
return nil
}