Skip to content

Commit 7c78573

Browse files
committed
allow running cronjob tutorial w/o webhoooks
Webhook support isn't easy to set up locally, so add an env var for disabling them.
1 parent b3fcf22 commit 7c78573

File tree

4 files changed

+34
-8
lines changed

4 files changed

+34
-8
lines changed

docs/book/src/cronjob-tutorial/running.md

+16-3
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,26 @@ Now that we've installed our CRDs, we can run the controller against our
1313
cluster. This will use whatever credentials that we connect to the
1414
cluster with, so we don't need to worry about RBAC just yet.
1515

16-
Note that if you have a webhook and want to deploy it locally, you need to
17-
ensure the certificates are in the right place.
16+
<aside class="note">
17+
18+
<h1>Running webhooks locally</h1>
19+
20+
If you want to run the webhooks locally, you'll have to generate
21+
certificates for serving the webhooks, and place them in the right
22+
directory (`/tmp/k8s-webhook-server/serving-certs/tls.{crt,key}`, by
23+
default).
24+
25+
If you're not running a local API server, you'll also need to figure out
26+
how to proxy traffic from the remote cluster to your local webhook server.
27+
For this reason, we generally reccomended disabling webhooks when doing
28+
your local code-run-test cycle, as we do below.
29+
30+
</aside>
1831

1932
In a separate terminal, run
2033

2134
```bash
22-
make run
35+
make run ENABLE_WEBHOOKS=false
2336
```
2437

2538
You should see logs from the controller about starting up, but it won't do

docs/book/src/cronjob-tutorial/testdata/project/api/v1/zz_generated.deepcopy.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ package v1
2222

2323
import (
2424
corev1 "k8s.io/api/core/v1"
25+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2526
"k8s.io/apimachinery/pkg/runtime"
2627
)
2728

@@ -130,7 +131,8 @@ func (in *CronJobStatus) DeepCopyInto(out *CronJobStatus) {
130131
}
131132
if in.LastScheduleTime != nil {
132133
in, out := &in.LastScheduleTime, &out.LastScheduleTime
133-
*out = (*in).DeepCopy()
134+
*out = new(metav1.Time)
135+
(*in).DeepCopyInto(*out)
134136
}
135137
}
136138

docs/book/src/cronjob-tutorial/testdata/project/main.go

+14-3
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,20 @@ func main() {
9191
setupLog.Error(err, "unable to create controller", "controller", "Captain")
9292
os.Exit(1)
9393
}
94-
if err = (&batchv1.CronJob{}).SetupWebhookWithManager(mgr); err != nil {
95-
setupLog.Error(err, "unable to create webhook", "webhook", "Captain")
96-
os.Exit(1)
94+
95+
/*
96+
We'll also set up webhooks for our type, which we'll talk about next.
97+
We just need to add them to the manager. Since we might want to run
98+
the webhooks separately, or not run them when testing our controller
99+
locally, we'll put them behind an environment variable.
100+
101+
We'll just make sure to set `ENABLE_WEBHOOKS=false` when we run locally.
102+
*/
103+
if os.Getenv("ENABLE_WEBHOOKS") != "false" {
104+
if err = (&batchv1.CronJob{}).SetupWebhookWithManager(mgr); err != nil {
105+
setupLog.Error(err, "unable to create webhook", "webhook", "Captain")
106+
os.Exit(1)
107+
}
97108
}
98109
// +kubebuilder:scaffold:builder
99110

docs/book/src/cronjob-tutorial/webhook-implementation.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Implementing admission webhooks
1+
# Implementing defaulting/validating webhooks
22

33
If you want to implement [admission webhooks](../reference/admission-webhook.md)
44
for your CRD, the only thing you need to do is to implement the `Defaulter`

0 commit comments

Comments
 (0)