Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proposed Changes for 4.3.0 Release #4214

Closed
camilamacedo86 opened this issue Oct 10, 2024 · 6 comments
Closed

Proposed Changes for 4.3.0 Release #4214

camilamacedo86 opened this issue Oct 10, 2024 · 6 comments
Labels
kind/feature Categorizes issue or PR as related to a new feature.

Comments

@camilamacedo86
Copy link
Member

camilamacedo86 commented Oct 10, 2024

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.

Furthermore, webhooks should no longer reside under the api directory. Instead, they should be relocated to internal/webhook. For now, you can scaffold webhooks in the legacy path (under api) by using the command kubebuilder create webhook [OPTIONS] --legacy=true, which scaffolds using the CustomValidator and CustomDefaulter interfaces. However, please note that this flag is deprecated and will be removed in upcoming 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. Also,

⚠️ Breaking Changes

✨ New Features

🐛 Bug Fixes

What's Changed

New Contributors

Full Changelog: v4.2.0...v4.3.0

@camilamacedo86 camilamacedo86 added the kind/feature Categorizes issue or PR as related to a new feature. label Oct 10, 2024
@camilamacedo86
Copy link
Member Author

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

@varshaprasad96
Copy link
Member

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
Copy link
Contributor

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

@TAM360
Copy link
Contributor

TAM360 commented Oct 11, 2024

Everything looks good! @camilamacedo86

@migueleliasweb
Copy link

migueleliasweb commented Oct 15, 2024

Thanks for the update. The changes look great, specially:

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.

This is going to help heaps!

@camilamacedo86
Copy link
Member Author

Done; https://github.com/kubernetes-sigs/kubebuilder/releases/tag/v4.3.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/feature Categorizes issue or PR as related to a new feature.
Projects
None yet
Development

No branches or pull requests

5 participants