diff --git a/docs/book/src/cronjob-tutorial/testdata/project/internal/controller/cronjob_controller_test.go b/docs/book/src/cronjob-tutorial/testdata/project/internal/controller/cronjob_controller_test.go index 6afdf8081b0..c3060c72f65 100644 --- a/docs/book/src/cronjob-tutorial/testdata/project/internal/controller/cronjob_controller_test.go +++ b/docs/book/src/cronjob-tutorial/testdata/project/internal/controller/cronjob_controller_test.go @@ -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. @@ -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! diff --git a/hack/docs/internal/cronjob-tutorial/writing_tests_controller.go b/hack/docs/internal/cronjob-tutorial/writing_tests_controller.go index 28f0a11dd13..ab85accff3b 100644 --- a/hack/docs/internal/cronjob-tutorial/writing_tests_controller.go +++ b/hack/docs/internal/cronjob-tutorial/writing_tests_controller.go @@ -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. @@ -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!