kubernetes-sigs / kubebuilder

Kubebuilder - SDK for building Kubernetes APIs using CRDs
http://book.kubebuilder.io
Apache License 2.0
7.8k stars 1.44k forks source link

Implement e2e controller tests for the multi-version sample used in the docs #3878

Closed camilamacedo86 closed 3 weeks ago

camilamacedo86 commented 5 months ago

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/v2@v2.14.0/internal/node.go:463
  github.com/onsi/ginkgo/v2/internal.(*Suite).runNode.func3
    /Users/runner/go/pkg/mod/github.com/onsi/ginkgo/v2@v2.14.0/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:

Extra Labels

No response

omerap12 commented 4 months ago

Maybe I can help with that /assign

ansh-devs commented 4 weeks ago

Hi @omerap12, are you working on this ?

omerap12 commented 4 weeks ago

Hey @ansh-devs, I started working on it but got stuck and haven't had the time to continue. Feel free to take it over! 😊 /unassign

ansh-devs commented 4 weeks ago

/assign

camilamacedo86 commented 3 weeks ago

I have been looking on this one. The fix is just apply the same code implementation that we have for cronjob to the mulriversion since the multiversion tutorial is the cronjob one with changes to explain how to convert one version to another.

So it is fixed in : https://github.com/kubernetes-sigs/kubebuilder/issues/3878

However, I will raise a new issue for we review the test implementation to see if we could change and enhance it to be more aligned with out scaffolds.

camilamacedo86 commented 3 weeks ago

See that I open https://github.com/kubernetes-sigs/kubebuilder/issues/4140 for we review the test implementation and ensure that is a good example and is following our default scaffold.