Skip to content

Commit

Permalink
fix make generate errors
Browse files Browse the repository at this point in the history
  • Loading branch information
lowang-bh committed Sep 3, 2023
1 parent 334e8a2 commit 79da654
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 39 deletions.
8 changes: 0 additions & 8 deletions hack/docs/internal/cronjob-tutorial/generate_cronjob.go
Original file line number Diff line number Diff line change
Expand Up @@ -362,14 +362,6 @@ CronJob controller's`+" `"+`SetupWithManager`+"`"+` method.
}`, `
// +kubebuilder:docs-gen:collapse=old stuff`)
CheckError("fixing main.go", err)

err = pluginutil.ReplaceInFile(
filepath.Join(sp.ctx.Dir, "cmd/main.go"),
` if err = (&batchv1.CronJob{}).SetupWebhookWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create webhook", "webhook", "CronJob")
os.Exit(1)
}`, `}`)
CheckError("fixing main.go", err)
}

func updateWebhook(sp *Sample) {
Expand Down
3 changes: 2 additions & 1 deletion hack/docs/internal/cronjob-tutorial/main_revisited.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,5 @@ const MainEnableWebhook = `
if err = (&batchv1.CronJob{}).SetupWebhookWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create webhook", "webhook", "CronJob")
os.Exit(1)
}`
}
}`
48 changes: 30 additions & 18 deletions testdata/project-v4-multigroup/cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,11 @@ func main() {
setupLog.Error(err, "unable to create controller", "controller", "Captain")
os.Exit(1)
}
if err = (&crewv1.Captain{}).SetupWebhookWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create webhook", "webhook", "Captain")
os.Exit(1)
if os.Getenv("ENABLE_WEBHOOKS") != "false" {
if err = (&crewv1.Captain{}).SetupWebhookWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create webhook", "webhook", "Captain")
os.Exit(1)
}
}
if err = (&shipcontroller.FrigateReconciler{
Client: mgr.GetClient(),
Expand All @@ -135,9 +137,11 @@ func main() {
setupLog.Error(err, "unable to create controller", "controller", "Frigate")
os.Exit(1)
}
if err = (&shipv1beta1.Frigate{}).SetupWebhookWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create webhook", "webhook", "Frigate")
os.Exit(1)
if os.Getenv("ENABLE_WEBHOOKS") != "false" {
if err = (&shipv1beta1.Frigate{}).SetupWebhookWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create webhook", "webhook", "Frigate")
os.Exit(1)
}
}
if err = (&shipcontroller.DestroyerReconciler{
Client: mgr.GetClient(),
Expand All @@ -146,9 +150,11 @@ func main() {
setupLog.Error(err, "unable to create controller", "controller", "Destroyer")
os.Exit(1)
}
if err = (&shipv1.Destroyer{}).SetupWebhookWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create webhook", "webhook", "Destroyer")
os.Exit(1)
if os.Getenv("ENABLE_WEBHOOKS") != "false" {
if err = (&shipv1.Destroyer{}).SetupWebhookWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create webhook", "webhook", "Destroyer")
os.Exit(1)
}
}
if err = (&shipcontroller.CruiserReconciler{
Client: mgr.GetClient(),
Expand All @@ -157,9 +163,11 @@ func main() {
setupLog.Error(err, "unable to create controller", "controller", "Cruiser")
os.Exit(1)
}
if err = (&shipv2alpha1.Cruiser{}).SetupWebhookWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create webhook", "webhook", "Cruiser")
os.Exit(1)
if os.Getenv("ENABLE_WEBHOOKS") != "false" {
if err = (&shipv2alpha1.Cruiser{}).SetupWebhookWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create webhook", "webhook", "Cruiser")
os.Exit(1)
}
}
if err = (&seacreaturescontroller.KrakenReconciler{
Client: mgr.GetClient(),
Expand Down Expand Up @@ -210,9 +218,11 @@ func main() {
setupLog.Error(err, "unable to create controller", "controller", "Lakers")
os.Exit(1)
}
if err = (&testprojectorgv1.Lakers{}).SetupWebhookWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create webhook", "webhook", "Lakers")
os.Exit(1)
if os.Getenv("ENABLE_WEBHOOKS") != "false" {
if err = (&testprojectorgv1.Lakers{}).SetupWebhookWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create webhook", "webhook", "Lakers")
os.Exit(1)
}
}
if err = (&examplecomcontroller.MemcachedReconciler{
Client: mgr.GetClient(),
Expand All @@ -230,9 +240,11 @@ func main() {
setupLog.Error(err, "unable to create controller", "controller", "Busybox")
os.Exit(1)
}
if err = (&examplecomv1alpha1.Memcached{}).SetupWebhookWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create webhook", "webhook", "Memcached")
os.Exit(1)
if os.Getenv("ENABLE_WEBHOOKS") != "false" {
if err = (&examplecomv1alpha1.Memcached{}).SetupWebhookWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create webhook", "webhook", "Memcached")
os.Exit(1)
}
}
//+kubebuilder:scaffold:builder

Expand Down
8 changes: 5 additions & 3 deletions testdata/project-v4-with-deploy-image/cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,11 @@ func main() {
setupLog.Error(err, "unable to create controller", "controller", "Busybox")
os.Exit(1)
}
if err = (&examplecomv1alpha1.Memcached{}).SetupWebhookWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create webhook", "webhook", "Memcached")
os.Exit(1)
if os.Getenv("ENABLE_WEBHOOKS") != "false" {
if err = (&examplecomv1alpha1.Memcached{}).SetupWebhookWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create webhook", "webhook", "Memcached")
os.Exit(1)
}
}
//+kubebuilder:scaffold:builder

Expand Down
24 changes: 15 additions & 9 deletions testdata/project-v4/cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,11 @@ func main() {
setupLog.Error(err, "unable to create controller", "controller", "Captain")
os.Exit(1)
}
if err = (&crewv1.Captain{}).SetupWebhookWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create webhook", "webhook", "Captain")
os.Exit(1)
if os.Getenv("ENABLE_WEBHOOKS") != "false" {
if err = (&crewv1.Captain{}).SetupWebhookWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create webhook", "webhook", "Captain")
os.Exit(1)
}
}
if err = (&controller.FirstMateReconciler{
Client: mgr.GetClient(),
Expand All @@ -107,9 +109,11 @@ func main() {
setupLog.Error(err, "unable to create controller", "controller", "FirstMate")
os.Exit(1)
}
if err = (&crewv1.FirstMate{}).SetupWebhookWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create webhook", "webhook", "FirstMate")
os.Exit(1)
if os.Getenv("ENABLE_WEBHOOKS") != "false" {
if err = (&crewv1.FirstMate{}).SetupWebhookWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create webhook", "webhook", "FirstMate")
os.Exit(1)
}
}
if err = (&controller.AdmiralReconciler{
Client: mgr.GetClient(),
Expand All @@ -118,9 +122,11 @@ func main() {
setupLog.Error(err, "unable to create controller", "controller", "Admiral")
os.Exit(1)
}
if err = (&crewv1.Admiral{}).SetupWebhookWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create webhook", "webhook", "Admiral")
os.Exit(1)
if os.Getenv("ENABLE_WEBHOOKS") != "false" {
if err = (&crewv1.Admiral{}).SetupWebhookWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create webhook", "webhook", "Admiral")
os.Exit(1)
}
}
if err = (&controller.LakerReconciler{
Client: mgr.GetClient(),
Expand Down

0 comments on commit 79da654

Please sign in to comment.