kubernetes-sigs / kubebuilder

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

Proposed Changes for 4.3.0 Release #4214

Open camilamacedo86 opened 2 days ago

camilamacedo86 commented 2 days ago

What do you want to happen?

Please take a look at the draft for the upcoming 4.3.0 release and what’s been merged into the master branch so far bellow.

We’ve been working to improve the documentation for this upcoming release. We’ve reviewed and rewritten sections, cleaning up outdated information and making significant revisions to areas such as "Watching Resources," "Getting Started," and "Plugins." You can check the current state of the docs and how they will appear in production after the release by visiting the “nightly” docs at:master.book.kubebuilder.io.

Please let us know if you have any suggestions, objections, or other feedback for the next release. If no objections are raised, we are planning to push the release any time after Monday, the 14th.

------ Draft ----

⚠️ Important Notice:

(Only projects using webhooks are impacted by)

Controller runtime has deprecated the webhook.Validator and webhook.Defaulter interfaces, and they will no longer be provided in future versions. Therefore, projects must adopt the new CustomValidator and CustomDefaulter interfaces to remain compatible with controller-runtime v0.20.0 and upper versions. For more details, refer to controller-runtime/issues/2641.

Additionally, webhooks should no longer be placed under the api directory. They should be moved to internal/webhook. You can temporarily scaffold using --legacy=true, but this flag will be removed in future releases.

Steps to Migrate:

  1. Move Webhook Files to the Internal Directory:

    Depending on your project structure, move the webhook files:

    • Single Group Layout: Move from api/<version> to internal/webhook/<version>.

      Before:

      api/
      ├── <version>/
      │   ├── <kind>_webhook.go
      │   ├── <kind>_webhook_test.go
      │   └── webhook_suite_test.go

      After:

      internal/
      ├── webhook/
      │   └── <version>/
      │       ├── <kind>_webhook.go
      │       ├── <kind>_webhook_test.go
      │       └── webhook_suite_test.go
    • Multigroup Layout: Move from api/<group>/<version> to internal/webhook/<group>/<version>.

      Before:

      api/
      ├── <group>/
      │   └── <version>/
      │       ├── <kind>_webhook.go
      │       ├── <kind>_webhook_test.go
      │       └── webhook_suite_test.go

      After:

      internal/
      ├── webhook/
      │   └── <group>/
      │       └── <version>/
      │           ├── <kind>_webhook.go
      │           ├── <kind>_webhook_test.go
      │           └── webhook_suite_test.go
  2. Update Imports:

    After moving the files, ensure that all references to webhooks are updated in your main.go and other files. For example, update the import:

    • Before:

      import "your_project/api/v1"
    • After:

      import "your_project/internal/webhook/v1"
  3. Replace Deprecated Interfaces with Custom Ones:

    Replace webhook.Validator and webhook.Defaulter with the new CustomValidator and CustomDefaulter interfaces:

    • Before:

      var _ webhook.Validator = &MyResource{}
      
      func (r *MyResource) ValidateCreate() error { ... }
      func (r *MyResource) ValidateUpdate() error { ... }
      func (r *MyResource) ValidateDelete() error { ... }
      
      var _ webhook.Defaulter = &MyResource{}
      
      func (r *MyResource) Default() { ... }
    • After:

      var _ webhook.CustomValidator = &MyResource{}
      
      func (v *MyResource) ValidateCreate(ctx context.Context, obj runtime.Object) (admission.Warnings, error) {
       myResource, ok := obj.(*MyResource)
       if !ok { return nil, fmt.Errorf("expected MyResource, got %T", obj) }
       return nil, validateMyResource(myResource)
      }
      
      func (v *MyResource) ValidateUpdate(ctx context.Context, oldObj, newObj runtime.Object) (admission.Warnings, error) {
       myResource, ok := newObj.(*MyResource)
       if !ok { return nil, fmt.Errorf("expected MyResource, got %T", newObj) }
       return nil, validateMyResource(myResource)
      }
      
      func (v *MyResource) ValidateDelete(ctx context.Context, obj runtime.Object) (admission.Warnings, error) {
       myResource, ok := obj.(*MyResource)
       if !ok { return nil, fmt.Errorf("expected MyResource, got %T", obj) }
       return nil, nil
      }
      
      var _ webhook.CustomDefaulter = &MyResource{}
      
      func (d *MyResource) Default(ctx context.Context, obj runtime.Object) error {
       myResource, ok := obj.(*MyResource)
       if !ok { return fmt.Errorf("expected MyResource, got %T", obj) }
       // Defaulting logic
       return nil
      }

Example: See the tutorial: CronJob Webhook Example.

Note: You might want to use the Upgrade Assistance to re-scaffold your project and then apply your code changes on top, ensuring that all necessary updates are addressed.

⚠️ Breaking Changes

✨ New Features

🐛 Bug Fixes

What's Changed

New Contributors

Full Changelog: https://github.com/kubernetes-sigs/kubebuilder/compare/v4.2.0...v4.3.0

Extra Labels

No response

camilamacedo86 commented 2 days ago

c/c @varshaprasad96 @Kavinjsir @mogsie @TAM360 @Adembc @pgaxatte @rkosegi @lorenzofelletti @mateusoliveira43

varshaprasad96 commented 2 days ago

This release is going to be big and exciting, with a bunch of breaking changes! Thanks all for all the effort in getting it through. Lgtm for the draft from my end 👍

Kavinjsir commented 1 day ago

Looks good to me 👍🏼 @camilamacedo86 Appreciated for the huge contribution!

TAM360 commented 1 day ago

Everything looks good! @camilamacedo86