Skip to content

Migrate to Kubebuilder v4#1105

Merged
Zerpet merged 11 commits intomainfrom
migrate-kubebuilder
Feb 25, 2026
Merged

Migrate to Kubebuilder v4#1105
Zerpet merged 11 commits intomainfrom
migrate-kubebuilder

Conversation

@Zerpet
Copy link
Member

@Zerpet Zerpet commented Feb 9, 2026

Summary

This PR migrates the messaging-topology-operator to the latest Kubebuilder v4 project layout and conventions, resulting in significant structural changes while maintaining all core functionality.

Key Changes

🏗️ Major Project Restructuring

Entry Point Migration:

  • Moved main.gocmd/main.go (following Kubebuilder v4 convention)
  • Updated Dockerfile to reflect new build path
  • All imports and build commands updated accordingly

Controller Organization:

  • Moved controllers/internal/controller/
  • Renamed controller files to follow <resource>_controller.go pattern
  • Updated test suite paths from system_tests/test/system/

Webhook Reorganization:

  • Moved webhooks from controllers/ to internal/webhook/
  • Separated webhook logic into dedicated files by resource type

📦 Resource Naming Changes

This refactor introduces breaking changes to resource names for better namespace isolation:

Services:

  • webhook-servicemessaging-topology-webhook-service
  • Added new: messaging-topology-controller-metrics-service

ValidatingWebhookConfiguration:

  • topology.rabbitmq.commessaging-topology-validating-webhook-configuration

Cert-manager Resources (with-certmanager variant):

  • serving-certmessaging-topology-serving-cert
  • selfsigned-issuermessaging-topology-selfsigned-issuer

New RBAC for Metrics:

  • ClusterRole: messaging-topology-metrics-auth-role
  • ClusterRole: messaging-topology-metrics-reader
  • ClusterRoleBinding: messaging-topology-metrics-auth-rolebinding

🔧 CI/CD Improvements

.github/workflows/pr.yml:

  • Added tool binary caching to speed up builds (actions/cache@v4 for bin/ directory)
  • Expanded Kubernetes test matrix: added k8s 1.33.7
  • Consolidated test commands: make unit-tests and make integration-tests now include all checks
  • Improved artifact handling with ${{ runner.temp }} instead of /tmp
  • Removed setup-ginkgo action (now installed via Makefile)
  • Streamlined ytt/kustomize installation through Makefile targets

.github/workflows/build-test-publish.yml:

  • Removed id-token: 'write' permission (unused)
  • Fixed kustomize image references to use unified namespace
  • Updated image paths in installation configs

.github/workflows/lint.yml (NEW):

  • Added dedicated golangci-lint workflow for consistent code quality checks
  • Runs on all pushes and pull requests

.github/workflows/test-e2e.yml (NEW):

  • Added dedicated E2E test workflow
  • Automates Kind cluster setup and E2E test execution

.github/workflows/olm.yml:

  • Updated test paths (system_tests/test/system/)
  • Fixed OLM bundle directory structure handling

.github/workflows/codeql-analysis.yml:

  • Removed unnecessary matrix strategy (single language project)

🛠️ Makefile Modernization

Comprehensive rewrite with Kubebuilder v4 conventions:

  • Tool Management: All tools now version-pinned and installed to ./bin/ with smart caching
  • ENVTEST Setup: Dynamic version detection from go.mod dependencies
  • New Targets:
    • make help - Categorized help menu with descriptions
    • make install-tools - Installs all required tooling
    • make lint / make lint-fix - golangci-lint integration
    • make test-e2e - E2E test target with Kind cluster management
  • Tool Versions: All tools explicitly versioned (Kustomize 5.7.1, controller-tools 0.20.0, etc.)
  • Platform Detection: Improved handling for different architectures (amd64, arm64, aarch64)

📝 Configuration Updates

Project Metadata (PROJECT file):

  • Updated to Kubebuilder v4 format
  • Changed layout from go.kubebuilder.io/v3 to go.kubebuilder.io/v4
  • Updated resource paths to reflect new structure

Kustomize Manifests:

  • All config files reorganized under new directory structure
  • Updated image names: controllermanager
  • New cert-manager integration for metrics server
  • Added secure metrics support patches

Docker Improvements:

  • Added .dockerignore for more efficient builds (excludes test files)
  • Updated COPY directives to match new structure

🧪 Testing Infrastructure

  • Test paths updated throughout codebase
  • Enhanced E2E test support with automated Kind cluster setup
  • Improved test binary caching and management
  • All Ginkgo/Gomega tests maintained with updated imports

📚 Documentation

New Files:

  • AGENTS.md - Comprehensive AI agent guide for Kubebuilder projects
  • .golangci.yml - Linter configuration with extensive rule set
  • .devcontainer/ - Dev container support for consistent development environments

Updated:

  • All references to controller/webhook paths throughout documentation
  • README examples updated for new resource names

🗑️ Removed

  • .github/ISSUE_TEMPLATE/ - Removed custom issue templates (using defaults)
  • Old project structure artifacts
  • Deprecated configuration files

Migration Impact

For Users Upgrading:
A cleanup script has been added (cleanup-old-resources.sh) to delete old resources before applying the new manifests:

  • Old webhook service and configuration
  • Old cert-manager resources (if applicable)

For Developers:

  • Update local tooling: make install-tools
  • All build/test commands remain the same
  • IDE configurations may need path updates

Testing

  • ✅ All unit tests passing
  • ✅ All integration tests passing
  • ✅ CI pipeline green
  • ✅ Manifests regenerated and validated

This migration positions the operator for better maintainability and alignment with current Kubernetes operator best practices while preserving all existing functionality.

@Zerpet Zerpet added this to the v1.19.0 milestone Feb 10, 2026
@github-advanced-security
Copy link

This pull request sets up GitHub code scanning for this repository. Once the scans have completed and the checks have passed, the analysis results for this pull request branch will appear on this overview. Once you merge this pull request, the 'Security' tab will show more code scanning analysis results (for example, for the default branch). Depending on your configuration and choice of analysis tool, future pull requests will be annotated with code scanning analysis results. For more information about GitHub code scanning, check out the documentation.

@Zerpet Zerpet force-pushed the migrate-kubebuilder branch 2 times, most recently from aa59ef5 to c6055bc Compare February 11, 2026 10:49
@Zerpet
Copy link
Member Author

Zerpet commented Feb 11, 2026

Holding off merging until we pass Feb release of rabbitmq

@Zerpet
Copy link
Member Author

Zerpet commented Feb 23, 2026

@copilot rebase on top of main and solve merge conflicts

Copilot AI mentioned this pull request Feb 23, 2026
Copy link
Contributor

Copilot AI commented Feb 23, 2026

@Zerpet I've opened a new pull request, #1111, to work on those changes. Once the pull request is ready, I'll request review from you.

Zerpet and others added 9 commits February 23, 2026 14:41
...with modernized build system and e2e test improvements

This commit completes the migration to Kubebuilder v4, introducing significant improvements to the build system, tooling, and e2e test infrastructure.

Build System & Tooling:
- Modernize Makefile with local tool installation using versioned binaries in bin/
- Add go-install-tool function for automatic tool version management with symlinks
- Implement proper tool caching and version tracking (kustomize, controller-gen, ytt, etc.)
- Remove legacy internal/tools/ directory in favor of declarative tool management
- Add LOCALBIN variable and organized tool sections with ##@ categories
- Improve shell configuration with bash -o pipefail for safer command execution
- Fix ENVTEST_K8S_VERSION resolution bug (x.y.z path vs x.y variable)
- Auto-detect tool versions from go.mod dependencies

E2E Test Infrastructure:
- Refactor e2e tests to use KinD with local image loading instead of non-existent registry
- Change operator image from example.com/messaging-topology-operator to localhost/messaging-topology-operator
- Update e2e suite to use IfNotPresent pull policy with locally loaded images
- Add KinD installation and management targets with version checking
- Simplify e2e test code by removing complex sed commands
- Add YTT overlays: skip_namespace.yml, always_pull.yml, add_pull_secrets.yml

CI/CD Improvements:
- Update GitHub workflows (pr.yml, test-e2e.yml, lint.yml, codeql-analysis.yml)
- Add caching for Go modules and tool binaries in CI
- Refactor workflows to use new Makefile targets
- Use local tools (./bin/kustomize, ./bin/ytt) instead of system-installed tools
- Remove obsolete test.yml workflow

Kubebuilder v4 Migration:
- Update PROJECT file with Kubebuilder v4 metadata
- Modernize cmd/main.go with improved manager setup
- Restructure config/ directory (remove nested overlays, update kustomization files)
- Add operatorpolicy webhook and sample resources
- Update all webhook files to use new controller-runtime patterns
- Reorganize RBAC and CRD configuration structure

Configuration Changes:
- Simplify config/default/kustomization.yaml (remove nested base/overlays structure)
- Update config/manager with new image references and structure
- Add config/rbac/operatorpolicy_admin_role.yaml
- Update service account and role binding configurations

The migration improves developer experience with faster tool installation, better caching,
more reliable e2e tests, and alignment with Kubebuilder v4 best practices.

Co-authored-by: Cursor <[email protected]>
Naming is hard. Renaming is harder. Specially when two names are almost
identical except for one word.
The new layout provided e2e tests under `test/` folder. For consistency,
it makes sense to have system tests under the same folder, because our
system tests are a form of e2e tests.

The ability to configure the service type allows to run system tests in
different local k8s flavours, for example, in k3d + traeffik a.k.a
Rancher Desktop. In some local environments, accesing the NodePort
service is not possible, because Docker runs inside a VM and the host
may not redirect all ports to the VM.
It was removed by the re-scaffold
This script will be required as a one off task when users upgrade to
Topology Operator v1.19+

This version of the Operator went through a major refactor to catch up
with Kubebuilder latest version and modern project layout.
@Zerpet Zerpet force-pushed the migrate-kubebuilder branch from 3b91e06 to 8455bde Compare February 23, 2026 13:43
@Zerpet
Copy link
Member Author

Zerpet commented Feb 23, 2026

@Zerpet I've opened a new pull request, #1111, to work on those changes. Once the pull request is ready, I'll request review from you.

The outcome did not resolve the merge conflicts at all 🫠 I had to manually rebase to resolve the conflicts.

Because label selectors in the Deployment spec is inmutable. If we
change the selectors, it will be impossible to in-place upgrade, and
users will have to delete-redeploy.

This commit also includes `go fmt` and a minor fix to one of the
examples.
@Zerpet Zerpet force-pushed the migrate-kubebuilder branch 2 times, most recently from e9630a4 to f5261e6 Compare February 25, 2026 12:23
The most serious issue was that installation manifests were generated
incorrectly. The "dockerhub" manifest was generated with an image name
that pointed to `localhost/...`. This commit now sets the "dockerhub"
manifest to use GHCR. This is intended and it's part of an initiative to
abandon DockerHub image publishing.

The other fix was that our tests were not using Ginkgo CLI, even tho
there's a maketarget to install it locally.
@Zerpet Zerpet force-pushed the migrate-kubebuilder branch from f5261e6 to b0e77bd Compare February 25, 2026 12:48
@Zerpet Zerpet merged commit 3be64f7 into main Feb 25, 2026
9 of 11 checks passed
@Zerpet Zerpet deleted the migrate-kubebuilder branch February 25, 2026 14:33
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.

4 participants