kubebuilder icon indicating copy to clipboard operation
kubebuilder copied to clipboard

Running the tutorial locally fails due to webhook certs

Open camilamacedo86 opened this issue 3 years ago • 3 comments
trafficstars

Discussed in https://github.com/kubernetes-sigs/kubebuilder/discussions/2702

Originally posted by smileisak May 26, 2022 Following the kubebuilder book tutorial, I am facing an issue when running the controller locally by disabling the webhooks.

make run ENABLE_WEBHOOKS=false

as described in the documentation: https://book.kubebuilder.io/cronjob-tutorial/running.html#running-webhooks-locally

Got this error:

1.6535567690158641e+09  ERROR   setup   problem running manager {"error": "open /var/folders/gn/jhjjkq191nl3ggqp77qsc1pr0000gn/T/k8s-webhook-server/serving-certs/tls.crt: no such file or directory"}

It looks like the environment variable is ignored.

camilamacedo86 avatar Jul 27 '22 10:07 camilamacedo86

I got same error too. My kubebuilder version is as followed Version: main.version{KubeBuilderVersion:"3.6.0", KubernetesVendor:"1.24.1", GitCommit:"f20414648f1851ae97997f4a5f8eb4329f450f6d", BuildDate:"2022-08-03T11:47:17Z", GoOs:"darwin", GoArch:"amd64"}

zamonia500 avatar Aug 14 '22 08:08 zamonia500

if os.Getenv("ENABLE_WEBHOOKS") != "false" {
        if err = (&batchv1.CronJob{}).SetupWebhookWithManager(mgr); err != nil {
            setupLog.Error(err, "unable to create webhook", "webhook", "CronJob")
            os.Exit(1)
        }
    }

this statement in main.go should recover this normally.

jakobmoellerdev avatar Aug 16 '22 07:08 jakobmoellerdev

Hi @jakobmoellersap and @zamonia500,

Technically, the webhooks can be run locally, but for it to work you need to generate certificates for the webhook server and store them at /tmp/k8s-webhook-server/serving-certs/tls.{crt,key}. For more details about running webhook locally, refer here.

Then, to disable this one we need to ensure that we have the ENV VAR exported in the same place where you will execute the make run.

Did you tried :

export ENABLE_WEBHOOKS=false make run

To see if that works?

Also, I think the fix here is only to update the docs with the above instructions. Can you check it out and would you like to contribute to the project by opening a PR so we can fix it?

camilamacedo86 avatar Aug 16 '22 08:08 camilamacedo86

/assign

yashsingh74 avatar Sep 24 '22 04:09 yashsingh74