File tree Expand file tree Collapse file tree 2 files changed +14
-6
lines changed
docs/book/src/cronjob-tutorial/testdata/project/internal/controller
hack/docs/internal/cronjob-tutorial Expand file tree Collapse file tree 2 files changed +14
-6
lines changed Original file line number Diff line number Diff line change @@ -163,9 +163,6 @@ var _ = Describe("CronJob controller", func() {
163
163
},
164
164
},
165
165
},
166
- Status : batchv1.JobStatus {
167
- Active : 2 ,
168
- },
169
166
}
170
167
171
168
// Note that your CronJob’s GroupVersionKind is required to set up this owner reference.
@@ -175,6 +172,13 @@ var _ = Describe("CronJob controller", func() {
175
172
controllerRef := metav1 .NewControllerRef (createdCronjob , gvk )
176
173
testJob .SetOwnerReferences ([]metav1.OwnerReference {* controllerRef })
177
174
Expect (k8sClient .Create (ctx , testJob )).Should (Succeed ())
175
+ // Note that you can not manage the status values while creating the resource.
176
+ // The status field is managed separately to reflect the current state of the resource.
177
+ // Therefore, it should be updated using a PATCH or PUT operation after the resource has been created.
178
+ // Additionally, it is recommended to use StatusConditions to manage the status. For further information see:
179
+ // https://github.com/kubernetes/community/blob/master/contributors/devel/sig-architecture/api-conventions.md#spec-and-status
180
+ testJob .Status .Active = 2
181
+ Expect (k8sClient .Status ().Update (ctx , testJob )).Should (Succeed ())
178
182
/*
179
183
Adding this Job to our test CronJob should trigger our controller’s reconciler logic.
180
184
After that, we can write a test that evaluates whether our controller eventually updates our CronJob’s Status field as expected!
Original file line number Diff line number Diff line change @@ -182,9 +182,6 @@ var _ = Describe("CronJob controller", func() {
182
182
},
183
183
},
184
184
},
185
- Status: batchv1.JobStatus{
186
- Active: 2,
187
- },
188
185
}
189
186
190
187
// Note that your CronJob’s GroupVersionKind is required to set up this owner reference.
@@ -194,6 +191,13 @@ var _ = Describe("CronJob controller", func() {
194
191
controllerRef := metav1.NewControllerRef(createdCronjob, gvk)
195
192
testJob.SetOwnerReferences([]metav1.OwnerReference{*controllerRef})
196
193
Expect(k8sClient.Create(ctx, testJob)).Should(Succeed())
194
+ // Note that you can not manage the status values while creating the resource.
195
+ // The status field is managed separately to reflect the current state of the resource.
196
+ // Therefore, it should be updated using a PATCH or PUT operation after the resource has been created.
197
+ // Additionally, it is recommended to use StatusConditions to manage the status. For further information see:
198
+ // https://github.com/kubernetes/community/blob/master/contributors/devel/sig-architecture/api-conventions.md#spec-and-status
199
+ testJob.Status.Active = 2
200
+ Expect(k8sClient.Status().Update(ctx, testJob)).Should(Succeed())
197
201
/*
198
202
Adding this Job to our test CronJob should trigger our controller’s reconciler logic.
199
203
After that, we can write a test that evaluates whether our controller eventually updates our CronJob’s Status field as expected!
You can’t perform that action at this time.
0 commit comments