Skip to content

Commit 4186920

Browse files
authored
Merge pull request #961 from DirectXMan12/docs/local-webhook-flag
📖 allow running cronjob tutorial w/o webhoooks
2 parents b3fcf22 + 5631729 commit 4186920

File tree

9 files changed

+63
-1205
lines changed

9 files changed

+63
-1205
lines changed

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

Lines changed: 16 additions & 3 deletions
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/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ docker-push:
5757
# download controller-gen if necessary
5858
controller-gen:
5959
ifeq (, $(shell which controller-gen))
60-
go get sigs.k8s.io/controller-tools/cmd/[email protected]beta.3
60+
go get sigs.k8s.io/controller-tools/cmd/[email protected]rc.0
6161
CONTROLLER_GEN=$(shell go env GOPATH)/bin/controller-gen
6262
else
6363
CONTROLLER_GEN=$(shell which controller-gen)

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

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/book/src/cronjob-tutorial/testdata/project/config/crd/bases/batch.tutorial.kubebuilder.io_cronjobs.yaml

Lines changed: 1 addition & 1193 deletions
Large diffs are not rendered by default.

docs/book/src/cronjob-tutorial/testdata/project/config/webhook/manifests.yaml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,30 @@
11

2+
---
3+
apiVersion: admissionregistration.k8s.io/v1beta1
4+
kind: MutatingWebhookConfiguration
5+
metadata:
6+
creationTimestamp: null
7+
name: mutating-webhook-configuration
8+
webhooks:
9+
- clientConfig:
10+
caBundle: Cg==
11+
service:
12+
name: webhook-service
13+
namespace: system
14+
path: /mutate-batch-tutorial-kubebuilder-io-v1-cronjob
15+
failurePolicy: Fail
16+
name: mcronjob.kb.io
17+
rules:
18+
- apiGroups:
19+
- batch.tutorial.kubebuilder.io
20+
apiVersions:
21+
- v1
22+
operations:
23+
- CREATE
24+
- UPDATE
25+
resources:
26+
- cronjobs
27+
228
---
329
apiVersion: admissionregistration.k8s.io/v1beta1
430
kind: ValidatingWebhookConfiguration

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,5 @@ require (
1818
k8s.io/api v0.0.0-20190409021203-6e4e0e4f393b
1919
k8s.io/apimachinery v0.0.0-20190404173353-6a84e37a896d
2020
k8s.io/client-go v11.0.1-0.20190409021438-1a26190bd76a+incompatible
21-
sigs.k8s.io/controller-runtime v0.2.0-beta.5
21+
sigs.k8s.io/controller-runtime v0.2.0-rc.0
2222
)

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,8 +143,8 @@ k8s.io/kube-openapi v0.0.0-20180731170545-e3762e86a74c h1:3KSCztE7gPitlZmWbNwue/
143143
k8s.io/kube-openapi v0.0.0-20180731170545-e3762e86a74c/go.mod h1:BXM9ceUBTj2QnfH2MK1odQs778ajze1RxcmP6S8RVVc=
144144
k8s.io/utils v0.0.0-20190506122338-8fab8cb257d5 h1:VBM/0P5TWxwk+Nw6Z+lAw3DKgO76g90ETOiA6rfLV1Y=
145145
k8s.io/utils v0.0.0-20190506122338-8fab8cb257d5/go.mod h1:sZAwmy6armz5eXlNoLmJcl4F1QuKu7sr+mFQ0byX7Ew=
146-
sigs.k8s.io/controller-runtime v0.2.0-beta.5 h1:W2jTb239QEwQ+HejhTCF9GriFPy2zmo1I6pPmJTeEy8=
147-
sigs.k8s.io/controller-runtime v0.2.0-beta.5/go.mod h1:HweyYKQ8fBuzdu2bdaeBJvsFgAi/OqBBnrVGXcqKhME=
146+
sigs.k8s.io/controller-runtime v0.2.0-rc.0 h1:49JLOielmXfrd44Cmk2c0eeIkQ/Vq4AvfqsZqya16/E=
147+
sigs.k8s.io/controller-runtime v0.2.0-rc.0/go.mod h1:HweyYKQ8fBuzdu2bdaeBJvsFgAi/OqBBnrVGXcqKhME=
148148
sigs.k8s.io/testing_frameworks v0.1.1 h1:cP2l8fkA3O9vekpy5Ks8mmA0NW/F7yBdXf8brkWhVrs=
149149
sigs.k8s.io/testing_frameworks v0.1.1/go.mod h1:VVBKrHmJ6Ekkfz284YKhQePcdycOzNH9qL6ht1zEr/U=
150150
sigs.k8s.io/yaml v1.1.0 h1:4A07+ZFc2wgJwo8YNlQpr1rVlgUDlxXHhPJciaPY5gs=

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

Lines changed: 14 additions & 3 deletions
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

Lines changed: 1 addition & 1 deletion
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)