Skip to content

Commit

Permalink
Update test examples not to set Status on create
Browse files Browse the repository at this point in the history
  • Loading branch information
hsadoyan committed Jul 19, 2024
1 parent b3eeace commit 90ce1b6
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -163,9 +163,6 @@ var _ = Describe("CronJob controller", func() {
},
},
},
Status: batchv1.JobStatus{
Active: 2,
},
}

// Note that your CronJob’s GroupVersionKind is required to set up this owner reference.
Expand All @@ -175,6 +172,13 @@ var _ = Describe("CronJob controller", func() {
controllerRef := metav1.NewControllerRef(createdCronjob, gvk)
testJob.SetOwnerReferences([]metav1.OwnerReference{*controllerRef})
Expect(k8sClient.Create(ctx, testJob)).Should(Succeed())
// Note that you can not manage the status values while creating the resource.
// The status field is managed separately to reflect the current state of the resource.
// Therefore, it should be updated using a PATCH or PUT operation after the resource has been created.
// Additionally, it is recommended to use StatusConditions to manage the status. For further information see:
// https://github.com/kubernetes/community/blob/master/contributors/devel/sig-architecture/api-conventions.md#spec-and-status
testJob.Status.Active = 2
Expect(k8sClient.Status().Update(ctx, testJob)).Should(Succeed())
/*
Adding this Job to our test CronJob should trigger our controller’s reconciler logic.
After that, we can write a test that evaluates whether our controller eventually updates our CronJob’s Status field as expected!
Expand Down
10 changes: 7 additions & 3 deletions hack/docs/internal/cronjob-tutorial/writing_tests_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,9 +182,6 @@ var _ = Describe("CronJob controller", func() {
},
},
},
Status: batchv1.JobStatus{
Active: 2,
},
}
// Note that your CronJob’s GroupVersionKind is required to set up this owner reference.
Expand All @@ -194,6 +191,13 @@ var _ = Describe("CronJob controller", func() {
controllerRef := metav1.NewControllerRef(createdCronjob, gvk)
testJob.SetOwnerReferences([]metav1.OwnerReference{*controllerRef})
Expect(k8sClient.Create(ctx, testJob)).Should(Succeed())
// Note that you can not manage the status values while creating the resource.
// The status field is managed separately to reflect the current state of the resource.
// Therefore, it should be updated using a PATCH or PUT operation after the resource has been created.
// Additionally, it is recommended to use StatusConditions to manage the status. For further information see:
// https://github.com/kubernetes/community/blob/master/contributors/devel/sig-architecture/api-conventions.md#spec-and-status
testJob.Status.Active = 2
Expect(k8sClient.Status().Update(ctx, testJob)).Should(Succeed())
/*
Adding this Job to our test CronJob should trigger our controller’s reconciler logic.
After that, we can write a test that evaluates whether our controller eventually updates our CronJob’s Status field as expected!
Expand Down

0 comments on commit 90ce1b6

Please sign in to comment.