Repository: kubernetes-sigs/kubebuilder (language: go)

Issue:
Improve hack/docs to avoid failures when upgrading controller-runtime version
Currently, all projects generated for documentation/tutorials are created automatically via commands and scripts under `hack/docs`. This automation helps keep our documentation up to date without needing manual intervention.

When we run `make generate`, it triggers `make generate-docs`, which re-generates these example projects and syncs them with the documentation.

### The Problem

We have a hardcoded version of `controller-runtime` in the following line:

https://github.com/kubernetes-sigs/kubebuilder/blob/3ae96043f3673504f18a1e776cc32ee142deaf91/hack/docs/internal/cronjob-tutorial/generate_cronjob.go#L291

This causes `make generate-docs` to fail when we bump the controller-runtime version in the scaffold logic. For example, updating this constant:

https://github.com/kubernetes-sigs/kubebuilder/blob/3ae96043f3673504f18a1e776cc32ee142deaf91/pkg/plugins/golang/v4/scaffolds/init.go#L43

From:
ControllerRuntimeVersion = "v0.20.4"

To a newer version may result in errors like:

`ERRO error fixing cronjob_controller.go: string // - https://pkg.go.dev/sigs.k8s.io/controller-runtime@v0.20.3/pkg/reconcile not found in /* Copyright 2025 The Kubernetes authors.
`
### What Needs to Be Done

We should improve the logic in `hack/docs` so that it's not tied to a hardcoded controller-runtime version.

We could either:
- Remove the need for the manual replacement in the first place
- OR dynamically use the version from the `ControllerRuntimeVersion` constant in the scaffolding code

This would prevent future breakages when we upgrade dependencies and keep `make generate-docs` stable and version-aware.




Discussion / hints:
/assign
Taking this up. @camilamacedo86 

Fix patch:
diff --git a/hack/docs/internal/cronjob-tutorial/generate_cronjob.go b/hack/docs/internal/cronjob-tutorial/generate_cronjob.go
index c7fd20a025e..fef9b97e1df 100644
--- a/hack/docs/internal/cronjob-tutorial/generate_cronjob.go
+++ b/hack/docs/internal/cronjob-tutorial/generate_cronjob.go
@@ -17,6 +17,7 @@ limitations under the License.
 package cronjob
 
 import (
+	"fmt"
 	"os/exec"
 	"path/filepath"
 
@@ -24,6 +25,7 @@ import (
 	"github.com/spf13/afero"
 	hackutils "sigs.k8s.io/kubebuilder/v4/hack/docs/utils"
 	pluginutil "sigs.k8s.io/kubebuilder/v4/pkg/plugin/util"
+	"sigs.k8s.io/kubebuilder/v4/pkg/plugins/golang/v4/scaffolds"
 	"sigs.k8s.io/kubebuilder/v4/test/e2e/utils"
 )
 
@@ -288,7 +290,8 @@ func (sp *Sample) updateController() {
 
 	err = pluginutil.InsertCode(
 		filepath.Join(sp.ctx.Dir, "internal/controller/cronjob_controller.go"),
-		`// - https://pkg.go.dev/sigs.k8s.io/controller-runtime@v0.20.4/pkg/reconcile`, skipGoCycloLint)
+		fmt.Sprintf(`// - https://pkg.go.dev/sigs.k8s.io/controller-runtime@%s/pkg/reconcile`,
+			scaffolds.ControllerRuntimeVersion), skipGoCycloLint)
 	hackutils.CheckError("fixing cronjob_controller.go", err)
 
 	err = pluginutil.ReplaceInFile(


Test patch: