Repository: kubernetes-sigs/kubebuilder
Pull request #4627: 🐛 (go/v4) Update main.go scaffold to follow Go best practices by reducing the scope of err using short variable declarations (:=)
Author: login: koba1t
Labels: name: cncf-cla: yes
description: Indicates the PR's author has signed the CNCF CLA.
name: size/L
description: Denotes a PR that changes 100-499 lines, ignoring generated files.
name: lgtm
description: "Looks good to me", indicates that a PR is ready to be merged.
name: approved
description: Indicates a PR has been approved by an approver from all required OWNERS files.
name: ok-to-test
description: Indicates a non-member PR verified by an org member that is safe to test.
Created: 2025-03-21T19:15:12Z | Merged: 2025-03-31T16:18:37Z

<!--

Hiya!  Welcome to Kubebuilder!  For a smooth PR process, please ensure
that you include the following information:

* a description of the change
* the motivation for the change
* what issue it fixes, if any, in GitHub syntax (e.g. Fixes #XYZ)

Both the description and motivation may reference other issues and PRs,
but should be mostly understandable without following the links (e.g. when
reading the git commit log).

Please don't @-mention people in PR or commit messages (do so in an
additional comment).

please add an icon to the title of this PR depending on the type:

- ⚠ (:warning:): breaking
- ✨ (:sparkles:): new non-breaking feature
- 🐛 (:bug:): bugfix
- 📖 (:book:): documentation
- 🌱 (:seedling:): infrastructure/other

See https://sigs.k8s.io/kubebuilder-release-tools for more information.

**PLEASE REMOVE THIS COMMENT BLOCK BEFORE SUBMITTING THE PR** (the bits
between the arrows)

-->

Errors in the snippet added to `cmd/main.go` when the controller and webhook are generated(like `kubebuilder create api`) was referring to something out of scope, so this has been corrected to a limited scoped error.


### Ex: cmd/main.go that was generated kubebuilder
```go
	if err = (&controller.FrigateReconciler{
		Client: mgr.GetClient(),
		Scheme: mgr.GetScheme(),
	}).SetupWithManager(mgr); err != nil {
		setupLog.Error(err, "unable to create controller", "controller", "Frigate")
		os.Exit(1)
	}
	// +kubebuilder:scaffold:builder

	if metricsCertWatcher != nil {
		setupLog.Info("Adding metrics certificate watcher to manager")
		if err := mgr.Add(metricsCertWatcher); err != nil {
			setupLog.Error(err, "unable to add metrics certificate watcher to manager")
			os.Exit(1)
		}
	}

	if webhookCertWatcher != nil {
		setupLog.Info("Adding webhook certificate watcher to manager")
		if err := mgr.Add(webhookCertWatcher); err != nil {
			setupLog.Error(err, "unable to add webhook certificate watcher to manager")
			os.Exit(1)
		}
	}

	if err := mgr.AddHealthzCheck("healthz", healthz.Ping); err != nil {
		setupLog.Error(err, "unable to set up health check")
		os.Exit(1)
	}
	if err := mgr.AddReadyzCheck("readyz", healthz.Ping); err != nil {
		setupLog.Error(err, "unable to set up ready check")
		os.Exit(1)
	}

	setupLog.Info("starting manager")
	if err := mgr.Start(ctrl.SetupSignalHandler()); err != nil {
		setupLog.Error(err, "problem running manager")
		os.Exit(1)
	}
```

### Change container image used in test from docker hub to `quay.io` registry
at https://github.com/kubernetes-sigs/kubebuilder/pull/4627/commits/870eecd9f8f9d91a5a047072a5fd1c68a3ecc1c4

e2e test was having errors due to rate limit when trying to pull container image from docker hub, so fixed the image to next official image that uses `quay.io` registry.
https://github.com/curl/curl-container


Diff:
diff --git a/docs/book/src/cronjob-tutorial/testdata/project/cmd/main.go b/docs/book/src/cronjob-tutorial/testdata/project/cmd/main.go
index a017e125f3f..bd6f543374d 100644
--- a/docs/book/src/cronjob-tutorial/testdata/project/cmd/main.go
+++ b/docs/book/src/cronjob-tutorial/testdata/project/cmd/main.go
@@ -224,7 +224,7 @@ func main() {
 
 	// +kubebuilder:docs-gen:collapse=old stuff
 
-	if err = (&controller.CronJobReconciler{
+	if err := (&controller.CronJobReconciler{
 		Client: mgr.GetClient(),
 		Scheme: mgr.GetScheme(),
 	}).SetupWithManager(mgr); err != nil {
@@ -242,7 +242,7 @@ func main() {
 	*/
 	// nolint:goconst
 	if os.Getenv("ENABLE_WEBHOOKS") != "false" {
-		if err = webhookbatchv1.SetupCronJobWebhookWithManager(mgr); err != nil {
+		if err := webhookbatchv1.SetupCronJobWebhookWithManager(mgr); err != nil {
 			setupLog.Error(err, "unable to create webhook", "webhook", "CronJob")
 			os.Exit(1)
 		}
diff --git a/docs/book/src/getting-started/testdata/project/cmd/main.go b/docs/book/src/getting-started/testdata/project/cmd/main.go
index 4685fc78c11..07e8c79591d 100644
--- a/docs/book/src/getting-started/testdata/project/cmd/main.go
+++ b/docs/book/src/getting-started/testdata/project/cmd/main.go
@@ -202,7 +202,7 @@ func main() {
 		os.Exit(1)
 	}
 
-	if err = (&controller.MemcachedReconciler{
+	if err := (&controller.MemcachedReconciler{
 		Client: mgr.GetClient(),
 		Scheme: mgr.GetScheme(),
 	}).SetupWithManager(mgr); err != nil {
diff --git a/docs/book/src/multiversion-tutorial/testdata/project/cmd/main.go b/docs/book/src/multiversion-tutorial/testdata/project/cmd/main.go
index 2867eba4b3b..3cfa8f6a22c 100644
--- a/docs/book/src/multiversion-tutorial/testdata/project/cmd/main.go
+++ b/docs/book/src/multiversion-tutorial/testdata/project/cmd/main.go
@@ -221,7 +221,7 @@ func main() {
 		os.Exit(1)
 	}
 
-	if err = (&controller.CronJobReconciler{
+	if err := (&controller.CronJobReconciler{
 		Client: mgr.GetClient(),
 		Scheme: mgr.GetScheme(),
 	}).SetupWithManager(mgr); err != nil {
@@ -235,14 +235,14 @@ func main() {
 	*/
 	// nolint:goconst
 	if os.Getenv("ENABLE_WEBHOOKS") != "false" {
-		if err = webhookbatchv1.SetupCronJobWebhookWithManager(mgr); err != nil {
+		if err := webhookbatchv1.SetupCronJobWebhookWithManager(mgr); err != nil {
 			setupLog.Error(err, "unable to create webhook", "webhook", "CronJob")
 			os.Exit(1)
 		}
 	}
 	// nolint:goconst
 	if os.Getenv("ENABLE_WEBHOOKS") != "false" {
-		if err = webhookbatchv2.SetupCronJobWebhookWithManager(mgr); err != nil {
+		if err := webhookbatchv2.SetupCronJobWebhookWithManager(mgr); err != nil {
 			setupLog.Error(err, "unable to create webhook", "webhook", "CronJob")
 			os.Exit(1)
 		}
diff --git a/docs/book/src/reference/raising-events.md b/docs/book/src/reference/raising-events.md
index 21a73d12d66..0364d2775de 100644
--- a/docs/book/src/reference/raising-events.md
+++ b/docs/book/src/reference/raising-events.md
@@ -47,7 +47,7 @@ Events are published from a Controller using an [EventRecorder][Events]`type Cor
 which can be created for a Controller by calling `GetRecorder(name string)` on a Manager. See that we will change the implementation scaffolded in `cmd/main.go`:
 
 ```go
-	if err = (&controller.MyKindReconciler{
+	if err := (&controller.MyKindReconciler{
 		Client:   mgr.GetClient(),
 		Scheme:   mgr.GetScheme(),
 		// Note that we added the following line:
@@ -81,7 +81,7 @@ Events are published from a Controller using an [EventRecorder]`type CorrelatorO
 which can be created for a Controller by calling `GetRecorder(name string)` on a Manager. See that we will change the implementation scaffolded in `cmd/main.go`:
 
 ```go
-	if err = (&controller.MyKindReconciler{
+	if err := (&controller.MyKindReconciler{
 		Client:   mgr.GetClient(),
 		Scheme:   mgr.GetScheme(),
 		// Note that we added the following line:
diff --git a/hack/docs/internal/multiversion-tutorial/generate_multiversion.go b/hack/docs/internal/multiversion-tutorial/generate_multiversion.go
index af0d9c1c157..aaf7cc237e6 100644
--- a/hack/docs/internal/multiversion-tutorial/generate_multiversion.go
+++ b/hack/docs/internal/multiversion-tutorial/generate_multiversion.go
@@ -276,7 +276,7 @@ interfaces, a conversion webhook will be registered.
 				"Expected validation to pass for a valid update")
 		})
 	})
-	
+
 	`)
 	hackutils.CheckError("fix cronjob v1 tests after each", err)
 }
@@ -465,7 +465,7 @@ func (sp *Sample) updateWebhookV2() {
 	"fmt"`,
 		`
 	"strings"
-	
+
 	"github.com/robfig/cron"
 	apierrors "k8s.io/apimachinery/pkg/api/errors"
 	"k8s.io/apimachinery/pkg/runtime/schema"
@@ -613,7 +613,7 @@ CronJob controller's `+"`SetupWithManager`"+` method.
 
 	err = pluginutil.InsertCode(
 		filepath.Join(sp.ctx.Dir, path),
-		`if err = (&controller.CronJobReconciler{
+		`if err := (&controller.CronJobReconciler{
 		Client: mgr.GetClient(),
 		Scheme: mgr.GetScheme(),
 	}).SetupWithManager(mgr); err != nil {
diff --git a/pkg/plugins/golang/v4/scaffolds/internal/templates/cmd/main.go b/pkg/plugins/golang/v4/scaffolds/internal/templates/cmd/main.go
index c455ed663f4..f14b6919c89 100644
--- a/pkg/plugins/golang/v4/scaffolds/internal/templates/cmd/main.go
+++ b/pkg/plugins/golang/v4/scaffolds/internal/templates/cmd/main.go
@@ -108,7 +108,7 @@ const (
 `
 	addschemeCodeFragment = `utilruntime.Must(%s.AddToScheme(scheme))
 `
-	reconcilerSetupCodeFragment = `if err = (&controller.%sReconciler{
+	reconcilerSetupCodeFragment = `if err := (&controller.%sReconciler{
 		Client: mgr.GetClient(),
 		Scheme: mgr.GetScheme(),
 	}).SetupWithManager(mgr); err != nil {
@@ -116,7 +116,7 @@ const (
 		os.Exit(1)
 	}
 `
-	multiGroupReconcilerSetupCodeFragment = `if err = (&%scontroller.%sReconciler{
+	multiGroupReconcilerSetupCodeFragment = `if err := (&%scontroller.%sReconciler{
 		Client: mgr.GetClient(),
 		Scheme: mgr.GetScheme(),
 	}).SetupWithManager(mgr); err != nil {
@@ -126,7 +126,7 @@ const (
 `
 	webhookSetupCodeFragmentLegacy = `// nolint:goconst
 	if os.Getenv("ENABLE_WEBHOOKS") != "false" {
-		if err = (&%s.%s{}).SetupWebhookWithManager(mgr); err != nil {
+		if err := (&%s.%s{}).SetupWebhookWithManager(mgr); err != nil {
 			setupLog.Error(err, "unable to create webhook", "webhook", "%s")
 			os.Exit(1)
 		}
@@ -135,7 +135,7 @@ const (
 
 	webhookSetupCodeFragment = `// nolint:goconst
 	if os.Getenv("ENABLE_WEBHOOKS") != "false" {
-		if err = %s.Setup%sWebhookWithManager(mgr); err != nil {
+		if err := %s.Setup%sWebhookWithManager(mgr); err != nil {
 			setupLog.Error(err, "unable to create webhook", "webhook", "%s")
 			os.Exit(1)
 		}
@@ -277,7 +277,7 @@ func main() {
 	flag.StringVar(&webhookCertPath, "webhook-cert-path", "", "The directory that contains the webhook certificate.")
 	flag.StringVar(&webhookCertName, "webhook-cert-name", "tls.crt", "The name of the webhook certificate file.")
 	flag.StringVar(&webhookCertKey, "webhook-cert-key", "tls.key", "The name of the webhook key file.")
-	flag.StringVar(&metricsCertPath, "metrics-cert-path", "", 
+	flag.StringVar(&metricsCertPath, "metrics-cert-path", "",
 		"The directory that contains the metrics server certificate.")
 	flag.StringVar(&metricsCertName, "metrics-cert-name", "tls.crt", "The name of the metrics server certificate file.")
 	flag.StringVar(&metricsCertKey, "metrics-cert-key", "tls.key", "The name of the metrics server key file.")
@@ -315,7 +315,7 @@ func main() {
 	if len(webhookCertPath) > 0 {
 		setupLog.Info("Initializing webhook certificate watcher using provided certificates",
 			"webhook-cert-path", webhookCertPath, "webhook-cert-name", webhookCertName, "webhook-cert-key", webhookCertKey)
-	
+
 		var err error
 		webhookCertWatcher, err = certwatcher.New(
 			filepath.Join(webhookCertPath, webhookCertName),
@@ -325,7 +325,7 @@ func main() {
 			setupLog.Error(err, "Failed to initialize webhook certificate watcher")
 			os.Exit(1)
 		}
-	
+
 		webhookTLSOpts = append(webhookTLSOpts, func(config *tls.Config) {
 			config.GetCertificate = webhookCertWatcher.GetCertificate
 		})
diff --git a/testdata/project-v4-multigroup/cmd/main.go b/testdata/project-v4-multigroup/cmd/main.go
index cb54ea82df8..a9c72d44150 100644
--- a/testdata/project-v4-multigroup/cmd/main.go
+++ b/testdata/project-v4-multigroup/cmd/main.go
@@ -243,7 +243,7 @@ func main() {
 		os.Exit(1)
 	}
 
-	if err = (&crewcontroller.CaptainReconciler{
+	if err := (&crewcontroller.CaptainReconciler{
 		Client: mgr.GetClient(),
 		Scheme: mgr.GetScheme(),
 	}).SetupWithManager(mgr); err != nil {
@@ -252,19 +252,19 @@ func main() {
 	}
 	// nolint:goconst
 	if os.Getenv("ENABLE_WEBHOOKS") != "false" {
-		if err = webhookcrewv1.SetupCaptainWebhookWithManager(mgr); err != nil {
+		if err := webhookcrewv1.SetupCaptainWebhookWithManager(mgr); err != nil {
 			setupLog.Error(err, "unable to create webhook", "webhook", "Captain")
 			os.Exit(1)
 		}
 	}
-	if err = (&shipcontroller.FrigateReconciler{
+	if err := (&shipcontroller.FrigateReconciler{
 		Client: mgr.GetClient(),
 		Scheme: mgr.GetScheme(),
 	}).SetupWithManager(mgr); err != nil {
 		setupLog.Error(err, "unable to create controller", "controller", "Frigate")
 		os.Exit(1)
 	}
-	if err = (&shipcontroller.DestroyerReconciler{
+	if err := (&shipcontroller.DestroyerReconciler{
 		Client: mgr.GetClient(),
 		Scheme: mgr.GetScheme(),
 	}).SetupWithManager(mgr); err != nil {
@@ -273,12 +273,12 @@ func main() {
 	}
 	// nolint:goconst
 	if os.Getenv("ENABLE_WEBHOOKS") != "false" {
-		if err = webhookshipv1.SetupDestroyerWebhookWithManager(mgr); err != nil {
+		if err := webhookshipv1.SetupDestroyerWebhookWithManager(mgr); err != nil {
 			setupLog.Error(err, "unable to create webhook", "webhook", "Destroyer")
 			os.Exit(1)
 		}
 	}
-	if err = (&shipcontroller.CruiserReconciler{
+	if err := (&shipcontroller.CruiserReconciler{
 		Client: mgr.GetClient(),
 		Scheme: mgr.GetScheme(),
 	}).SetupWithManager(mgr); err != nil {
@@ -287,54 +287,54 @@ func main() {
 	}
 	// nolint:goconst
 	if os.Getenv("ENABLE_WEBHOOKS") != "false" {
-		if err = webhookshipv2alpha1.SetupCruiserWebhookWithManager(mgr); err != nil {
+		if err := webhookshipv2alpha1.SetupCruiserWebhookWithManager(mgr); err != nil {
 			setupLog.Error(err, "unable to create webhook", "webhook", "Cruiser")
 			os.Exit(1)
 		}
 	}
-	if err = (&seacreaturescontroller.KrakenReconciler{
+	if err := (&seacreaturescontroller.KrakenReconciler{
 		Client: mgr.GetClient(),
 		Scheme: mgr.GetScheme(),
 	}).SetupWithManager(mgr); err != nil {
 		setupLog.Error(err, "unable to create controller", "controller", "Kraken")
 		os.Exit(1)
 	}
-	if err = (&seacreaturescontroller.LeviathanReconciler{
+	if err := (&seacreaturescontroller.LeviathanReconciler{
 		Client: mgr.GetClient(),
 		Scheme: mgr.GetScheme(),
 	}).SetupWithManager(mgr); err != nil {
 		setupLog.Error(err, "unable to create controller", "controller", "Leviathan")
 		os.Exit(1)
 	}
-	if err = (&foopolicycontroller.HealthCheckPolicyReconciler{
+	if err := (&foopolicycontroller.HealthCheckPolicyReconciler{
 		Client: mgr.GetClient(),
 		Scheme: mgr.GetScheme(),
 	}).SetupWithManager(mgr); err != nil {
 		setupLog.Error(err, "unable to create controller", "controller", "HealthCheckPolicy")
 		os.Exit(1)
 	}
-	if err = (&appscontroller.DeploymentReconciler{
+	if err := (&appscontroller.DeploymentReconciler{
 		Client: mgr.GetClient(),
 		Scheme: mgr.GetScheme(),
 	}).SetupWithManager(mgr); err != nil {
 		setupLog.Error(err, "unable to create controller", "controller", "Deployment")
 		os.Exit(1)
 	}
-	if err = (&foocontroller.BarReconciler{
+	if err := (&foocontroller.BarReconciler{
 		Client: mgr.GetClient(),
 		Scheme: mgr.GetScheme(),
 	}).SetupWithManager(mgr); err != nil {
 		setupLog.Error(err, "unable to create controller", "controller", "Bar")
 		os.Exit(1)
 	}
-	if err = (&fizcontroller.BarReconciler{
+	if err := (&fizcontroller.BarReconciler{
 		Client: mgr.GetClient(),
 		Scheme: mgr.GetScheme(),
 	}).SetupWithManager(mgr); err != nil {
 		setupLog.Error(err, "unable to create controller", "controller", "Bar")
 		os.Exit(1)
 	}
-	if err = (&certmanagercontroller.CertificateReconciler{
+	if err := (&certmanagercontroller.CertificateReconciler{
 		Client: mgr.GetClient(),
 		Scheme: mgr.GetScheme(),
 	}).SetupWithManager(mgr); err != nil {
@@ -343,26 +343,26 @@ func main() {
 	}
 	// nolint:goconst
 	if os.Getenv("ENABLE_WEBHOOKS") != "false" {
-		if err = webhookcertmanagerv1.SetupIssuerWebhookWithManager(mgr); err != nil {
+		if err := webhookcertmanagerv1.SetupIssuerWebhookWithManager(mgr); err != nil {
 			setupLog.Error(err, "unable to create webhook", "webhook", "Issuer")
 			os.Exit(1)
 		}
 	}
 	// nolint:goconst
 	if os.Getenv("ENABLE_WEBHOOKS") != "false" {
-		if err = webhookcorev1.SetupPodWebhookWithManager(mgr); err != nil {
+		if err := webhookcorev1.SetupPodWebhookWithManager(mgr); err != nil {
 			setupLog.Error(err, "unable to create webhook", "webhook", "Pod")
 			os.Exit(1)
 		}
 	}
 	// nolint:goconst
 	if os.Getenv("ENABLE_WEBHOOKS") != "false" {
-		if err = webhookappsv1.SetupDeploymentWebhookWithManager(mgr); err != nil {
+		if err := webhookappsv1.SetupDeploymentWebhookWithManager(mgr); err != nil {
 			setupLog.Error(err, "unable to create webhook", "webhook", "Deployment")
 			os.Exit(1)
 		}
 	}
-	if err = (&examplecomcontroller.MemcachedReconciler{
+	if err := (&examplecomcontroller.MemcachedReconciler{
 		Client:   mgr.GetClient(),
 		Scheme:   mgr.GetScheme(),
 		Recorder: mgr.GetEventRecorderFor("memcached-controller"),
@@ -370,7 +370,7 @@ func main() {
 		setupLog.Error(err, "unable to create controller", "controller", "Memcached")
 		os.Exit(1)
 	}
-	if err = (&examplecomcontroller.BusyboxReconciler{
+	if err := (&examplecomcontroller.BusyboxReconciler{
 		Client:   mgr.GetClient(),
 		Scheme:   mgr.GetScheme(),
 		Recorder: mgr.GetEventRecorderFor("busybox-controller"),
@@ -380,12 +380,12 @@ func main() {
 	}
 	// nolint:goconst
 	if os.Getenv("ENABLE_WEBHOOKS") != "false" {
-		if err = webhookexamplecomv1alpha1.SetupMemcachedWebhookWithManager(mgr); err != nil {
+		if err := webhookexamplecomv1alpha1.SetupMemcachedWebhookWithManager(mgr); err != nil {
 			setupLog.Error(err, "unable to create webhook", "webhook", "Memcached")
 			os.Exit(1)
 		}
 	}
-	if err = (&examplecomcontroller.WordpressReconciler{
+	if err := (&examplecomcontroller.WordpressReconciler{
 		Client: mgr.GetClient(),
 		Scheme: mgr.GetScheme(),
 	}).SetupWithManager(mgr); err != nil {
@@ -394,7 +394,7 @@ func main() {
 	}
 	// nolint:goconst
 	if os.Getenv("ENABLE_WEBHOOKS") != "false" {
-		if err = webhookexamplecomv1.SetupWordpressWebhookWithManager(mgr); err != nil {
+		if err := webhookexamplecomv1.SetupWordpressWebhookWithManager(mgr); err != nil {
 			setupLog.Error(err, "unable to create webhook", "webhook", "Wordpress")
 			os.Exit(1)
 		}
diff --git a/testdata/project-v4-with-plugins/cmd/main.go b/testdata/project-v4-with-plugins/cmd/main.go
index 9f84f245175..d6f128f1b4a 100644
--- a/testdata/project-v4-with-plugins/cmd/main.go
+++ b/testdata/project-v4-with-plugins/cmd/main.go
@@ -208,7 +208,7 @@ func main() {
 		os.Exit(1)
 	}
 
-	if err = (&controller.MemcachedReconciler{
+	if err := (&controller.MemcachedReconciler{
 		Client:   mgr.GetClient(),
 		Scheme:   mgr.GetScheme(),
 		Recorder: mgr.GetEventRecorderFor("memcached-controller"),
@@ -216,7 +216,7 @@ func main() {
 		setupLog.Error(err, "unable to create controller", "controller", "Memcached")
 		os.Exit(1)
 	}
-	if err = (&controller.BusyboxReconciler{
+	if err := (&controller.BusyboxReconciler{
 		Client:   mgr.GetClient(),
 		Scheme:   mgr.GetScheme(),
 		Recorder: mgr.GetEventRecorderFor("busybox-controller"),
@@ -226,12 +226,12 @@ func main() {
 	}
 	// nolint:goconst
 	if os.Getenv("ENABLE_WEBHOOKS") != "false" {
-		if err = webhookexamplecomv1alpha1.SetupMemcachedWebhookWithManager(mgr); err != nil {
+		if err := webhookexamplecomv1alpha1.SetupMemcachedWebhookWithManager(mgr); err != nil {
 			setupLog.Error(err, "unable to create webhook", "webhook", "Memcached")
 			os.Exit(1)
 		}
 	}
-	if err = (&controller.WordpressReconciler{
+	if err := (&controller.WordpressReconciler{
 		Client: mgr.GetClient(),
 		Scheme: mgr.GetScheme(),
 	}).SetupWithManager(mgr); err != nil {
@@ -240,7 +240,7 @@ func main() {
 	}
 	// nolint:goconst
 	if os.Getenv("ENABLE_WEBHOOKS") != "false" {
-		if err = webhookexamplecomv1.SetupWordpressWebhookWithManager(mgr); err != nil {
+		if err := webhookexamplecomv1.SetupWordpressWebhookWithManager(mgr); err != nil {
 			setupLog.Error(err, "unable to create webhook", "webhook", "Wordpress")
 			os.Exit(1)
 		}
diff --git a/testdata/project-v4/cmd/main.go b/testdata/project-v4/cmd/main.go
index d2d1a54b6a3..3fa458d3731 100644
--- a/testdata/project-v4/cmd/main.go
+++ b/testdata/project-v4/cmd/main.go
@@ -211,7 +211,7 @@ func main() {
 		os.Exit(1)
 	}
 
-	if err = (&controller.CaptainReconciler{
+	if err := (&controller.CaptainReconciler{
 		Client: mgr.GetClient(),
 		Scheme: mgr.GetScheme(),
 	}).SetupWithManager(mgr); err != nil {
@@ -220,12 +220,12 @@ func main() {
 	}
 	// nolint:goconst
 	if os.Getenv("ENABLE_WEBHOOKS") != "false" {
-		if err = webhookcrewv1.SetupCaptainWebhookWithManager(mgr); err != nil {
+		if err := webhookcrewv1.SetupCaptainWebhookWithManager(mgr); err != nil {
 			setupLog.Error(err, "unable to create webhook", "webhook", "Captain")
 			os.Exit(1)
 		}
 	}
-	if err = (&controller.FirstMateReconciler{
+	if err := (&controller.FirstMateReconciler{
 		Client: mgr.GetClient(),
 		Scheme: mgr.GetScheme(),
 	}).SetupWithManager(mgr); err != nil {
@@ -234,12 +234,12 @@ func main() {
 	}
 	// nolint:goconst
 	if os.Getenv("ENABLE_WEBHOOKS") != "false" {
-		if err = webhookcrewv1.SetupFirstMateWebhookWithManager(mgr); err != nil {
+		if err := webhookcrewv1.SetupFirstMateWebhookWithManager(mgr); err != nil {
 			setupLog.Error(err, "unable to create webhook", "webhook", "FirstMate")
 			os.Exit(1)
 		}
 	}
-	if err = (&controller.AdmiralReconciler{
+	if err := (&controller.AdmiralReconciler{
 		Client: mgr.GetClient(),
 		Scheme: mgr.GetScheme(),
 	}).SetupWithManager(mgr); err != nil {
@@ -248,12 +248,12 @@ func main() {
 	}
 	// nolint:goconst
 	if os.Getenv("ENABLE_WEBHOOKS") != "false" {
-		if err = webhookcrewv1.SetupAdmiralWebhookWithManager(mgr); err != nil {
+		if err := webhookcrewv1.SetupAdmiralWebhookWithManager(mgr); err != nil {
 			setupLog.Error(err, "unable to create webhook", "webhook", "Admiral")
 			os.Exit(1)
 		}
 	}
-	if err = (&controller.CertificateReconciler{
+	if err := (&controller.CertificateReconciler{
 		Client: mgr.GetClient(),
 		Scheme: mgr.GetScheme(),
 	}).SetupWithManager(mgr); err != nil {
@@ -262,21 +262,21 @@ func main() {
 	}
 	// nolint:goconst
 	if os.Getenv("ENABLE_WEBHOOKS") != "false" {
-		if err = webhookcertmanagerv1.SetupIssuerWebhookWithManager(mgr); err != nil {
+		if err := webhookcertmanagerv1.SetupIssuerWebhookWithManager(mgr); err != nil {
 			setupLog.Error(err, "unable to create webhook", "webhook", "Issuer")
 			os.Exit(1)
 		}
 	}
 	// nolint:goconst
 	if os.Getenv("ENABLE_WEBHOOKS") != "false" {
-		if err = webhookcorev1.SetupPodWebhookWithManager(mgr); err != nil {
+		if err := webhookcorev1.SetupPodWebhookWithManager(mgr); err != nil {
 			setupLog.Error(err, "unable to create webhook", "webhook", "Pod")
 			os.Exit(1)
 		}
 	}
 	// nolint:goconst
 	if os.Getenv("ENABLE_WEBHOOKS") != "false" {
-		if err = webhookappsv1.SetupDeploymentWebhookWithManager(mgr); err != nil {
+		if err := webhookappsv1.SetupDeploymentWebhookWithManager(mgr); err != nil {
 			setupLog.Error(err, "unable to create webhook", "webhook", "Deployment")
 			os.Exit(1)
 		}


Reviews:
user: login: camilamacedo86
state: COMMENTED
author_association: MEMBER
submitted_at: 2025-03-24T20:47:53Z
user: login: camilamacedo86
state: COMMENTED
author_association: MEMBER
submitted_at: 2025-03-24T20:48:39Z
user: login: koba1t
state: COMMENTED
author_association: MEMBER
submitted_at: 2025-03-25T00:25:01Z
user: login: koba1t
state: COMMENTED
author_association: MEMBER
submitted_at: 2025-03-25T00:28:25Z
user: login: koba1t
state: COMMENTED
author_association: MEMBER
submitted_at: 2025-03-25T01:07:45Z
user: login: camilamacedo86
state: COMMENTED
author_association: MEMBER
submitted_at: 2025-03-28T10:24:09Z
user: login: camilamacedo86
body: Hi @koba1t,

Thank you so much for your contribution — really appreciated!

Just one small request: **please revert the change that adds a specific registry (quay.io/) to the image used in the e2e tests**. We try to avoid dependencies on third-party where possible, and it’s not our intention to promote any specific one. Keeping it neutral allows users to customize the registry according to their environment.

On the other hand, the changes to reduce the error scope are spot on — they're well aligned with Go best practices, and we're happy to move forward with them. Thanks for that!

**However, could you please squash the commits?**
We follow a policy of having one commit per PR to keep our Git history clean and easier to maintain. It also helps when we need to revert changes or trace specific updates more efficiently.

Lastly, since this PR impacts end users and we use PR titles for our release notes, I’ve adjusted the title accordingly. I hope that’s okay with you.


Thanks again! 🙌


state: CHANGES_REQUESTED
author_association: MEMBER
submitted_at: 2025-03-28T10:27:47Z
user: login: koba1t
state: COMMENTED
author_association: MEMBER
submitted_at: 2025-03-28T13:18:12Z
user: login: camilamacedo86
body: /lgtm
/approve
/ok-to-test
state: APPROVED
author_association: MEMBER
submitted_at: 2025-03-31T15:50:13Z

Review comments:
diff_hunk: @@ -216,13 +216,13 @@ var _ = Describe("Manager", Ordered, func() {
 			By("creating the curl-metrics pod to access the metrics endpoint")
 			cmd = exec.Command("kubectl", "run", "curl-metrics", "--restart=Never",
 				"--namespace", namespace,
-				"--image=curlimages/curl:latest",
+				"--image=quay.io/curl/curl:latest",
path: docs/book/src/cronjob-tutorial/testdata/project/test/e2e/e2e_test.go
user: login: camilamacedo86
body: Why should we scaffold by default quay.io? 
We should not impose usage of quay.io.

What problem that you face that motivates you add it?
Either, if we must to add a registry I think we might want to use docker.io instead right?
created_at: 2025-03-24T20:47:53Z
author_association: MEMBER
diff_hunk: @@ -287,54 +287,54 @@ func main() {
 	}
 	// nolint:goconst
 	if os.Getenv("ENABLE_WEBHOOKS") != "false" {
-		if err = webhookshipv2alpha1.SetupCruiserWebhookWithManager(mgr); err != nil {
+		if err := webhookshipv2alpha1.SetupCruiserWebhookWithManager(mgr); err != nil {
 			setupLog.Error(err, "unable to create webhook", "webhook", "Cruiser")
 			os.Exit(1)
 		}
 	}
-	if err = (&seacreaturescontroller.KrakenReconciler{
+	if err := (&seacreaturescontroller.KrakenReconciler{
 		Client: mgr.GetClient(),
 		Scheme: mgr.GetScheme(),
 	}).SetupWithManager(mgr); err != nil {
 		setupLog.Error(err, "unable to create controller", "controller", "Kraken")
 		os.Exit(1)
 	}
-	if err = (&seacreaturescontroller.LeviathanReconciler{
+	if err := (&seacreaturescontroller.LeviathanReconciler{
path: testdata/project-v4-multigroup/cmd/main.go
user: login: camilamacedo86
body: Why would we need to add := for all errors?
Why it would be required ?
What problem did you face that is solved within?
created_at: 2025-03-24T20:48:39Z
author_association: MEMBER
diff_hunk: @@ -216,13 +216,13 @@ var _ = Describe("Manager", Ordered, func() {
 			By("creating the curl-metrics pod to access the metrics endpoint")
 			cmd = exec.Command("kubectl", "run", "curl-metrics", "--restart=Never",
 				"--namespace", namespace,
-				"--image=curlimages/curl:latest",
+				"--image=quay.io/curl/curl:latest",
path: docs/book/src/cronjob-tutorial/testdata/project/test/e2e/e2e_test.go
user: login: koba1t
body: I think e2e test will fail due to failing to pull curl image from registry.
The current Docker Hub rate limit is quite strict, I feel making it difficult to use within GitHub Actions.
https://docs.docker.com/docker-hub/usage/pulls/
created_at: 2025-03-25T00:25:00Z
author_association: MEMBER
diff_hunk: @@ -216,13 +216,13 @@ var _ = Describe("Manager", Ordered, func() {
 			By("creating the curl-metrics pod to access the metrics endpoint")
 			cmd = exec.Command("kubectl", "run", "curl-metrics", "--restart=Never",
 				"--namespace", namespace,
-				"--image=curlimages/curl:latest",
+				"--image=quay.io/curl/curl:latest",
path: docs/book/src/cronjob-tutorial/testdata/project/test/e2e/e2e_test.go
user: login: koba1t
body: Looks like they also distribute images on ghcr.io.
https://github.com/curl/curl-container?tab=readme-ov-file#curl-container

Do you feel this is better than quay.io?
created_at: 2025-03-25T00:28:25Z
author_association: MEMBER
diff_hunk: @@ -287,54 +287,54 @@ func main() {
 	}
 	// nolint:goconst
 	if os.Getenv("ENABLE_WEBHOOKS") != "false" {
-		if err = webhookshipv2alpha1.SetupCruiserWebhookWithManager(mgr); err != nil {
+		if err := webhookshipv2alpha1.SetupCruiserWebhookWithManager(mgr); err != nil {
 			setupLog.Error(err, "unable to create webhook", "webhook", "Cruiser")
 			os.Exit(1)
 		}
 	}
-	if err = (&seacreaturescontroller.KrakenReconciler{
+	if err := (&seacreaturescontroller.KrakenReconciler{
 		Client: mgr.GetClient(),
 		Scheme: mgr.GetScheme(),
 	}).SetupWithManager(mgr); err != nil {
 		setupLog.Error(err, "unable to create controller", "controller", "Kraken")
 		os.Exit(1)
 	}
-	if err = (&seacreaturescontroller.LeviathanReconciler{
+	if err := (&seacreaturescontroller.LeviathanReconciler{
path: testdata/project-v4-multigroup/cmd/main.go
user: login: koba1t
body: I don't think we must necessarily be unified with `err :=`.
I have submitted this PR as a refactor.

Since `if err :=` and `if err =` were mixed in `cmd/main.go` generated by kubebuilder, I thought it would be better to unify one or the other.

created_at: 2025-03-25T01:07:45Z
author_association: MEMBER
diff_hunk: @@ -216,13 +216,13 @@ var _ = Describe("Manager", Ordered, func() {
 			By("creating the curl-metrics pod to access the metrics endpoint")
 			cmd = exec.Command("kubectl", "run", "curl-metrics", "--restart=Never",
 				"--namespace", namespace,
-				"--image=curlimages/curl:latest",
+				"--image=quay.io/curl/curl:latest",
path: docs/book/src/cronjob-tutorial/testdata/project/test/e2e/e2e_test.go
user: login: camilamacedo86
body: I would say that the most commonly used registry is Docker Hub.

Moreover, **I’d say that we should not to hardcode any specific registry (or create any dependency here with third parties)**, so users can easily customize the image source—either locally in their project or by specifying the desired registry when running the command.

Additionally, I’ve worked on projects that use this image in CI environments (like GitHub Actions), often with large teams collaborating across repositories, and we’ve never encountered any issues using it.
created_at: 2025-03-28T10:24:09Z
author_association: MEMBER
diff_hunk: @@ -216,13 +216,13 @@ var _ = Describe("Manager", Ordered, func() {
 			By("creating the curl-metrics pod to access the metrics endpoint")
 			cmd = exec.Command("kubectl", "run", "curl-metrics", "--restart=Never",
 				"--namespace", namespace,
-				"--image=curlimages/curl:latest",
+				"--image=quay.io/curl/curl:latest",
path: docs/book/src/cronjob-tutorial/testdata/project/test/e2e/e2e_test.go
user: login: koba1t
body: > Moreover, I’d say that we should not to hardcode any specific registry (or create any dependency here with third parties), so users can easily customize the image source

I understand the purpose of wanting to omit the registry name.
I thought this was the cause of the CI drop, but I was mistaken.

I'll remove the second commit that introduce `quay.io`.


created_at: 2025-03-28T13:18:12Z
author_association: MEMBER

PR comments:
user: login: k8s-ci-robot
created_at: 2025-03-21T19:15:16Z
body: Skipping CI for Draft Pull Request.
If you want CI signal for your change, please convert it to an actual PR.
You can still manually trigger a test run with `/test all`
author_association: CONTRIBUTOR
user: login: k8s-ci-robot
created_at: 2025-03-31T15:50:21Z
body: [APPROVALNOTIFIER] This PR is **APPROVED**

This pull-request has been approved by: *<a href="https://github.com/kubernetes-sigs/kubebuilder/pull/4627#pullrequestreview-2729749525" title="Approved">camilamacedo86</a>*, *<a href="https://github.com/kubernetes-sigs/kubebuilder/pull/4627#" title="Author self-approved">koba1t</a>*

The full list of commands accepted by this bot can be found [here](https://go.k8s.io/bot-commands?repo=kubernetes-sigs%2Fkubebuilder).

The pull request process is described [here](https://git.k8s.io/community/contributors/guide/owners.md#the-code-review-process)

<details >
Needs approval from an approver in each of these files:

- ~~[OWNERS](https://github.com/kubernetes-sigs/kubebuilder/blob/master/OWNERS)~~ [camilamacedo86]

Approvers can indicate their approval by writing `/approve` in a comment
Approvers can cancel approval by writing `/approve cancel` in a comment
</details>
<!-- META={"approvers":[]} -->
author_association: CONTRIBUTOR
user: login: koba1t
created_at: 2025-03-31T16:09:00Z
body: Thank you!
author_association: MEMBER