$ show kubernetes-sigs/kubebuilder
Kubebuilder is a CLI tool and library for scaffolding Kubernetes operator projects. It generates the complete project structure including Go controllers, webhooks, CRDs, RBAC, kustomize configurations, Helm charts, and CI/CD workflows. The tool implements a plugin architecture where built-in and external plugins handle specific scaffolding phases: project initialization, API/resource creation, webhook scaffolding, and configuration editing. The core scaffolding engine (pkg/machinery) uses templates with marker-based code injection and a filesystem abstraction to produce idempotent output. In production, a user runs `kubebuilder init` to bootstrap a project, then `kubebuilder create api` to add a custom resource and controller, and optionally `kubebuilder create webhook` for admission webhooks. The system relies on controller-runtime, controller-tools, kustomize, and the Go toolchain. The primary data flow is user input → CLI command → plugin chain → template rendering → file generation on disk. The PROJECT file (YAML) acts as the persistent configuration, tracked and versioned across scaffolding steps. The codebase demonstrates strong software engineering practices: clean separation of concerns with plugin interfaces, a generic scaffolding engine, comprehensive unit and end-to-end tests, and well-structured internal APIs. It is actively maintained with recent commits and a clear versioning strategy, though some alpha features (helm/v2alpha, alpha update) carry experimental risk.
The LLM identified 3 files worth highlighting for reuse:
A collection of idempotent file manipulation functions: InsertCode inserts a code block at a marker, ReplaceInFile replaces regex-matched content, UncommentCode/CommentCode toggle comments, and HasFileContentWith checks for content. These functions have no dependencies on kubebuilder internals (only standard library and strings) and are well-tested. They can be extracted as a standalone utility library for any code generator or CLI tool needing reliable file patching.
Defines the GVK (Group/Version/Kind) struct with parsing, validation, and canonical form generation. It handles edge cases like empty group, unversioned type, and kind parsing. This is a self-contained domain model that only depends on Go standard library and strings. It can be reused in any Kubernetes-related Go project for consistent GVK manipulation and validation.
A YAML-based config store with versioning support. It handles loading/saving PROJECT files with backward-compatible schema evolution, symlink detection, atomic writes via temp files, and path validation. The implementation is cleanly separated from kubebuilder's business logic and could serve as a generic versioned configuration store for any CLI tool that persists structured config in YAML.