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

Update dependency kubernetes-sigs/kubebuilder to v4 #63

Merged
merged 1 commit into from
Nov 18, 2024

Conversation

renovate[bot]
Copy link
Contributor

@renovate renovate bot commented May 24, 2024

This PR contains the following updates:

Package Update Change
kubernetes-sigs/kubebuilder major v3.8.0 -> v4.3.1

Release Notes

kubernetes-sigs/kubebuilder (kubernetes-sigs/kubebuilder)

v4.3.1

Compare Source

✨ New Features

Note: Only minor version updates were applied in this release.

  • (go/v4): Upgraded controller-runtime from v0.19.0 to v0.19.1. (#​4234)
  • (go/v4): Updated kustomize from v5.4.3 to v5.5.0 (#​4235)
  • (go/v4): Upgraded golangci-lint from v1.59 to v1.61 with minor adjustments for lint rules. (#​4236)

🐛 Bug Fixes

  • (kustomize/v2, go/v4): Corrected the generation of manifests under config/crd/patches to ensure the /convert service patch is only created for webhooks configured with --conversion. (#​4280)
  • (go/v4): Fixed path configuration for webhook markers generated for core types with non-"core" group values, ensuring accurate path handling in core-type webhooks. (#​4301)
  • (go/v4): Resolved misleading comments regarding metrics configuration for certs in cmd/main.go, providing clarity on secure metrics setup. (#​4245)
  • (go/v4): Enabled the --make=false option for webhook creation, ensuring consistency with other command options and improved flexibility. (#​4275)
  • (kustomize/v2, go/v4): Moved the cert-manager uncomment block to the top of kustomization.yaml to enhance visibility (#​4283)
  • (Impact only for library users): ⚠️ Restructured internal layout to move main.go boilerplate into the cmd/ directory. This change is relevant for users consuming the framework as a library and Kubebuilder maintainers only, providing a cleaner separation of code. (#​4246)

What's Changed

New Contributors

Full Changelog: kubernetes-sigs/kubebuilder@v4.3.0...v4.3.1

v4.3.0

Compare Source

⚠️ 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

  • (Only projects using webhooks are impacted by) (go/v4): Replaced the deprecated webhook.Validator and webhook.Defaulter interfaces with CustomValidator and CustomDefaulter. Projects using the old interfaces must migrate to ensure compatibility with future versions. (#​4060)
  • (Only projects using webhooks are impacted by) (go/v4): Webhooks are now decoupled from the API directory. Webhook files should be moved from api/<version> or api/<group>/<version> to internal/webhook/<version> or internal/webhook/<group>/<version>. This restructuring improves project organization. (#​4150)
  • (Impact only for library users): Removed the APIPackagePathLegacy method, which has been obsolete since release 4.0.0. This change cleans up unused code. (#​4182)
  • (Impact only for library users): cleanup/refactor: Alpha Generate command. Move code source implementation to internal since this alpha feature is not designed to be imported by other tools (#​4180)
  • (Impact only for library users): Removed the redundant HasFragment method, favoring HasFileContentWith to reduce duplication and simplify the codebase. (#​4191)

✨ New Features

  • (go/v4): Added DevContainer support, making development in environments like GitHub Workspaces easier by removing the need for local setup. (#​4078)
  • (go/v4): The e2e test scaffolding has been improved with a comprehensive set of tests under e2e/tests, covering the manager and webhooks. These tests are designed to fail when not run against clusters using Kind, and they avoid re-installing Prometheus and Cert-Manager if already present. See the final scaffolded tests in the samples under testdata here. Key improvements include:
    • Added checks to detect existing Prometheus and Cert-Manager installations to prevent re-installation. (#​4117)
    • Enhanced e2e tests to ensure proper execution with Kind and clarified usage. (#​4106)
    • Ensured make manifests and make generate are run as part of the e2e tests. (#​4122)
    • Aligned make test-e2e with make test for consistent behavior. (#​4125)
    • Improved tests to validate metrics endpoints and ensure proper metric exposure, including guidance for using metrics in reconciliation validation. (#​4131)
    • Added support for scaffolded e2e webhook tests with the +kubebuilder:scaffold:e2e-webhooks-checks marker. (#​4121)
    • Simplified Gomega assertions for better readability and improved error handling and logging in e2e/test.go. (#​4141, #​4158, #​4166, #​4175)
  • (go/v4): Improved the webhook tests by adding examples. Also, enhanced the CronJob tutorial to clarify usage and validate changes. (#​4130)
  • (deploy-image/v1alpha): Improved the tests scaffolded for controllers to ensure better coverage. (#​4197)
  • (go/v4): Added support for scaffolding controllers and webhooks for External Types, making it easier to work with external resources in projects. (#​4171, #​4203, #​4217)
  • (go/v4): Add Support for Scaffolding Webhooks for Core Types (#​4210)
  • (go/v4): Upgraded the cert-manager version used in tests from v1.14.4 to v1.16.0 for better compatibility and features. (#​4209)
  • (deploy-image/v1-alpha1): Added comments to clarify how resource watching and reconciliation logic works in the scaffolded code. (#​4102)
  • (go/v4): Upgrade controller-tools version from v0.16.1 to v0.16.4 (#​4215)
  • (go/v4): Upgrade Prometheus Operator version used on the tests from v0.72.0 to 0.77.1 (#​4212)

🐛 Bug Fixes

  • (deploy-image/v1-alpha1): Corrected a typo, replacing typeNamespaceName with typeNamespacedName to ensure accurate variable naming. (#​4100)
  • (deploy-image/v1-alpha1): Fixed sample code to apply correct labels to resources, improving consistency in the scaffolded examples. (#​4101)
  • (go/v4): Resolved linter issues in the scaffold, adding nolint where necessary to prevent failures for specific cases that should not fail during checks. (#​4111)
  • (deploy-image/v1-alpha1): Addressed additional linter issues to enhance code quality. (#​4112)
  • (go/v4): Fixed linter issues to pass stricter checks like godot, gofumpt, and nlreturn, ensuring better code formatting and style. (#​4133)
  • (go/v4): Removed duplicate webhook names in multi-version APIs, resolving conflicts when using the same webhook names across different API versions. (#​4145)
  • (go/v4): Improved webhook test templates by adding examples, providing clearer guidance for testing webhooks. (#​4151)
  • (go/v4): Ensured unique controller names to fix naming conflicts in multigroup layouts, improving support for projects with multiple groups. (#​4162)
  • (go/v4): Fixed the HasResource package method to stop once a match is found, improving performance and accuracy in resource handling. (#​4190)
  • (go/v4, kustomize/v2): Simplified scaffold by removing webhookcainjection_patch and clarified the use of cert-manager as a replacement. (#​4123)
  • (go/v4, kustomize/v2): fixed Duplicate Webhook Patch Entries when Creating Multiple Versions (#​4220)

What's Changed

New Contributors

Full Changelog: kubernetes-sigs/kubebuilder@v4.2.0...v4.3.0

v4.2.0

Compare Source

changes since v4.1.1

⚠️ Important Notice:

The artefacts for ENVTEST from k8s 1.31 are exclusively available at: Controller Tools Releases. Kubebuilder no longer builds and promote the ENVTEST artefacts at the old location https://storage.googleapis.com/kubebuilder-tools which is deprecated and can no longer be ensured by Kubebuilder maintainers. You should ensure that your projects are using the new location. For further information, see: https://github.com/kubernetes-sigs/kubebuilder/discussions/4082

This update is fully transparent for Kubebuilder users assuming that they properly update their scaffolds to use setup-envtest from controller-runtime branch release-0.19.

# To know the available versions check: 
# - https://github.com/kubernetes-sigs/controller-tools/blob/main/envtest-releases.yaml
ENVTEST_K8S_VERSION = 1.31.0
# Controller-Runtime branch `release-0.19` has the implementation of the setup-envtest's code responsible
# for downloading the tarball from the correct location.
ENVTEST_VERSION ?= release-0.19

...
.PHONY: envtest
envtest: $(ENVTEST) ## Download setup-envtest locally if necessary.
$(ENVTEST): $(LOCALBIN)
	$(call go-install-tool,$(ENVTEST),sigs.k8s.io/controller-runtime/tools/setup-envtest,$(ENVTEST_VERSION))
✨ New Features
  • (go/v4, kustomize/v2): Add support to protect project with network policies (#​3853)
  • (go/v4): Add support to k8s 1.31 (#​4080)
  • (go/v4): Upgrading controller-runtime from v0.18.4 to v0.19.0 (#​4080)
  • (go/v4): Upgrading controller-tools from v0.15.0 to v0.16.1 (#​4080)
  • (go/v4, kustomize/v2): Upgrade kustomize from v5.4.2 to v5.4.3 (#​4084)
🐛 Bug Fixes
  • (go/v4): Add missing cancel context to controller's suite-test (#​4067)
  • ⚠️ (Only relevant for users of Kubebuilder as a library): ImplementWebhooks should only be used by the e2e tests and should be under its package. Therefore, this method is no longer served under pkg/plugin/util (#​4065)

What's Changed (Full Changelog)


Configuration

📅 Schedule: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

🚦 Automerge: Disabled by config. Please merge this manually once you are satisfied.

Rebasing: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 Ignore: Close this PR and you won't be reminded about this update again.


  • If you want to rebase/retry this PR, check this box

This PR was generated by Mend Renovate. View the repository job log.

@renovate renovate bot force-pushed the renovate/kubernetes-sigs-kubebuilder-4.x branch from 9a2b602 to 81ffdbd Compare July 5, 2024 11:30
@renovate renovate bot force-pushed the renovate/kubernetes-sigs-kubebuilder-4.x branch from 81ffdbd to 868d541 Compare July 23, 2024 09:38
@renovate renovate bot force-pushed the renovate/kubernetes-sigs-kubebuilder-4.x branch from 868d541 to b335375 Compare August 17, 2024 12:26
@renovate renovate bot force-pushed the renovate/kubernetes-sigs-kubebuilder-4.x branch from b335375 to 89227a6 Compare October 22, 2024 08:45
@renovate renovate bot force-pushed the renovate/kubernetes-sigs-kubebuilder-4.x branch from 89227a6 to 7b351f4 Compare November 9, 2024 13:00
@guni1192 guni1192 merged commit 451e1a2 into main Nov 18, 2024
@renovate renovate bot deleted the renovate/kubernetes-sigs-kubebuilder-4.x branch November 18, 2024 13:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant