kubebuilder
kubebuilder copied to clipboard
Implement e2e controller tests for the multi-version sample used in the docs
Description
See that we have the tutorial: https://book.kubebuilder.io/multiversion-tutorial/tutorial All code used in this tutorial came from the sample in: https://github.com/kubernetes-sigs/kubebuilder/tree/master/docs/book/src/multiversion-tutorial/testdata/project
This sample is tested via the unit-test when we push a PR with changes. Then, note that currently the EnvTest tests to test the reconciliation is commented:
https://github.com/kubernetes-sigs/kubebuilder/blob/master/docs/book/src/multiversion-tutorial/testdata/project/internal/controller/cronjob_controller_test.go#L87-L102
If we uncomment this line we will check in the CI/or when we run make tests for this project the following error:
"controllerGroup": "batch.tutorial.kubebuilder.io", "controllerKind": "CronJob", "CronJob": {"name":"test-resource","namespace":"default"}, "namespace": "default", "name": "test-resource", "reconcileID": "0504dde2-9a69-4126-829d-cd143fc79f8f", "active jobs": 0, "successful jobs": 0, "failed jobs": 0}
2024-04-26T07:47:09Z ERROR unable to list child Jobs {"error": "field label \".metadata.controller\" not supported for Job"}
tutorial.kubebuilder.io/project/internal/controller.(*CronJobReconciler).Reconcile
/Users/runner/work/kubebuilder/kubebuilder/docs/book/src/multiversion-tutorial/testdata/project/internal/controller/cronjob_controller.go:132
tutorial.kubebuilder.io/project/internal/controller.glob..func1.1.3
/Users/runner/work/kubebuilder/kubebuilder/docs/book/src/multiversion-tutorial/testdata/project/internal/controller/cronjob_controller_test.go:94
github.com/onsi/ginkgo/v2/internal.extractBodyFunction.func3
/Users/runner/go/pkg/mod/github.com/onsi/ginkgo/[email protected]/internal/node.go:463
github.com/onsi/ginkgo/v2/internal.(*Suite).runNode.func3
/Users/runner/go/pkg/mod/github.com/onsi/ginkgo/[email protected]/internal/suite.go:889
2024-04-26T07:47:09Z DEBUG job count {"controller": "cronjob", "controllerGroup": "batch.tutorial.kubebuilder.io", "controllerKind": "CronJob", "CronJob": {"name":"test-resource","namespace":"default"}, "namespace": "default", "name": "test-resource", "reconcileID": "eb8800f5-c534-4025-a99e-0988b0d9321a", "active jobs": 0, "successful jobs": 0, "failed jobs": 0}
[FAILED] in [It] - /Users/runner/work/kubebuilder/kubebuilder/docs/book/src/multiversion-tutorial/testdata/project/internal/controller/cronjob_controller_test.go:97 @ 04/26/24 07:47:09.663
STEP: Cleaning up the specific resource instance of CronJob @ 04/26/24 07:47:09.663
2024-04-26T07:47:09Z DEBUG no upcoming scheduled times, sleeping until next {"controller": "cronjob", "controllerGroup": "batch.tutorial.kubebuilder.io", "controllerKind": "CronJob", "CronJob": {"name":"test-resource","namespace":"default"}, "namespace": "default", "name": "test-resource", "reconcileID": "eb8800f5-c534-4025-a99e-0988b0d9321a", "now": "2024-04-26T07:47:09Z", "next run": "2024-04-26T07:48:00Z"}
<< Timeline
[FAILED] Unexpected error:
<*errors.StatusError | 0x14000263b80>:
field label ".metadata.controller" not supported for Job
{
ErrStatus: {
TypeMeta: {Kind: "", APIVersion: ""},
ListMeta: {
SelfLink: "",
ResourceVersion: "",
Continue: "",
RemainingItemCount: nil,
},
Status: "Failure",
Message: "field label \".metadata.controller\" not supported for Job",
Reason: "BadRequest",
Details: nil,
Code: 400,
},
}
occurred
In [It] at: /Users/runner/work/kubebuilder/kubebuilder/docs/book/src/multiversion-tutorial/testdata/project/internal/controller/cronjob_controller_test.go:97 @\
Example: https://github.com/kubernetes-sigs/kubebuilder/actions/runs/8844368662/job/24286141139#step:5:474
What we need to do:
- Fix the reconcile implementation in: https://github.com/kubernetes-sigs/kubebuilder/blob/master/docs/book/src/multiversion-tutorial/testdata/project/internal/controller/cronjob_controller.go
- Ensure that we have tests to cover this implementation in: https://github.com/kubernetes-sigs/kubebuilder/blob/master/docs/book/src/multiversion-tutorial/testdata/project/internal/controller/cronjob_controller_test.go
Extra Labels
No response