Skip to content

Commit bd3baa9

Browse files
committed
Fix multiversion tutorial
The multiversion tutorial had a couple of typos in it. This fixes them.
1 parent a1261b5 commit bd3baa9

19 files changed

+10306
-5766
lines changed

docs/book/src/cronjob-tutorial/cert-manager.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ provisioning the certificates for the webhook server. Other solutions should
55
also work as long as they put the certificates in the desired location.
66

77
You can follow
8-
[the cert manager document](https://docs.cert-manager.io/en/latest/getting-started/install/kubernetes.html)
8+
[the cert manager documentation](https://docs.cert-manager.io/en/latest/getting-started/install/kubernetes.html)
99
to install it.
1010

1111
Cert manager also has a component called CA injector, which is responsible for

docs/book/src/cronjob-tutorial/testdata/project/config/rbac/role.yaml

+12-12
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,18 @@ metadata:
66
creationTimestamp: null
77
name: manager-role
88
rules:
9+
- apiGroups:
10+
- batch
11+
resources:
12+
- jobs
13+
verbs:
14+
- create
15+
- delete
16+
- get
17+
- list
18+
- patch
19+
- update
20+
- watch
921
- apiGroups:
1022
- batch
1123
resources:
@@ -32,15 +44,3 @@ rules:
3244
- get
3345
- patch
3446
- update
35-
- apiGroups:
36-
- batch
37-
resources:
38-
- jobs
39-
verbs:
40-
- create
41-
- delete
42-
- get
43-
- list
44-
- patch
45-
- update
46-
- watch

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

-26
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,4 @@
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-
282
---
293
apiVersion: admissionregistration.k8s.io/v1beta1
304
kind: ValidatingWebhookConfiguration

docs/book/src/multiversion-tutorial/deployment.md

+18-6
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ bits disabled. To enable them, we need to:
77

88
- Enable `patches/webhook_in_<kind>.yaml` and
99
`patches/cainjection_in_<kind>.yaml` in
10-
`config/crds/kustomization.yaml` file.
10+
`config/crd/kustomization.yaml` file.
1111

1212
- Enable `../certmanager` and `../webhook` directories under the
1313
`bases` section in `config/default/kustomization.yaml` file.
@@ -18,6 +18,15 @@ bits disabled. To enable them, we need to:
1818
- Enable all the vars under the `CERTMANAGER` section in
1919
`config/default/kustomization.yaml` file.
2020

21+
Additionally, we'll need to set the `CRD_OPTIONS` variable to just
22+
`"crd"`, removing the `trivialVersions` option (this ensures that we
23+
actually [generate validation for each version][ref-multiver], instead of
24+
telling Kubernetes that they're the same):
25+
26+
```makefile
27+
CRD_OPTIONS ?= "crd"
28+
```
29+
2130
Now we have all our code changes and manifests in place, so let's deploy it to
2231
the cluster and test it out.
2332

@@ -28,8 +37,9 @@ with
2837
[0.9.0-alpha.0](https://github.com/jetstack/cert-manager/releases/tag/v0.9.0-alpha.0)
2938
release.
3039

31-
Once all our ducks are in a row with certificates, we can run `make deploy` (as normal)
32-
to deploy all the bits (i.e. the controller-manager deployment) onto the cluster.
40+
Once all our ducks are in a row with certificates, we can run `make
41+
install deploy` (as normal) to deploy all the bits (CRD,
42+
controller-manager deployment) onto the cluster.
3343

3444
## Testing
3545

@@ -45,14 +55,14 @@ We'll make a v2 version based on our v1 version (put it under `config/samples`)
4555
Then, we can create it on the cluster:
4656

4757
```shell
48-
kubectl apply -f config/samples/batch_v2_cronjob.yaml`
58+
kubectl apply -f config/samples/batch_v2_cronjob.yaml
4959
```
5060

5161
If we've done everything correctly, it should create successfully,
5262
and we should be able to fetch it using both the v2 resource
5363

5464
```shell
55-
kubectl get cronjobs.v2.tutorial.kubebuilder.io -o yaml
65+
kubectl get cronjobs.v2.batch.tutorial.kubebuilder.io -o yaml
5666
```
5767

5868
```yaml
@@ -62,7 +72,7 @@ kubectl get cronjobs.v2.tutorial.kubebuilder.io -o yaml
6272
and the v1 resource
6373

6474
```shell
65-
kubectl get cronjobs.v1.tutorial.kubebuilder.io -o yaml
75+
kubectl get cronjobs.v1.batch.tutorial.kubebuilder.io -o yaml
6676
```
6777
```yaml
6878
{{#include ./testdata/project/config/samples/batch_v2_cronjob.yaml}}
@@ -76,3 +86,5 @@ reconcile, even though our controller is written against our v1 API version.
7686

7787
## Troubleshooting
7888
TODO(../TODO.md) steps for troubleshoting
89+
90+
[ref-multiver]: /reference/generating-crd.md#multiple-versions "Generating CRDs: Multiple Versions"

docs/book/src/multiversion-tutorial/testdata/project/Dockerfile

-1
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Build the manager binary
2+
FROM golang:1.12.5 as builder
3+
4+
WORKDIR /workspace
5+
# Copy the Go Modules manifests
6+
COPY go.mod go.mod
7+
COPY go.sum go.sum
8+
# cache deps before building and copying source so that we don't need to re-download as much
9+
# and so that source changes don't invalidate our downloaded layer
10+
RUN go mod download
11+
12+
# Copy the go source
13+
COPY main.go main.go
14+
COPY api/ api/
15+
COPY controllers/ controllers/
16+
17+
# Build
18+
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 GO111MODULE=on go build -a -o manager main.go
19+
20+
# Use distroless as minimal base image to package the manager binary
21+
# Refer to https://github.com/GoogleContainerTools/distroless for more details
22+
FROM gcr.io/distroless/static:latest
23+
WORKDIR /
24+
COPY --from=builder /workspace/manager .
25+
ENTRYPOINT ["/manager"]

docs/book/src/multiversion-tutorial/testdata/project/Makefile

-1
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
2+
# Image URL to use all building/pushing image targets
3+
IMG ?= controller:latest
4+
# Produce CRDs that work back to Kubernetes 1.11 (no version conversion)
5+
CRD_OPTIONS ?= "crd"
6+
7+
all: manager
8+
9+
# Run tests
10+
test: generate fmt vet manifests
11+
go test ./api/... ./controllers/... -coverprofile cover.out
12+
13+
# Build manager binary
14+
manager: generate fmt vet
15+
go build -o bin/manager main.go
16+
17+
# Run against the configured Kubernetes cluster in ~/.kube/config
18+
run: generate fmt vet
19+
go run ./main.go
20+
21+
# Install CRDs into a cluster
22+
install: manifests
23+
kubectl apply -f config/crd/bases
24+
25+
# Deploy controller in the configured Kubernetes cluster in ~/.kube/config
26+
deploy: manifests
27+
kubectl apply -f config/crd/bases
28+
kustomize build config/default | kubectl apply -f -
29+
30+
# Generate manifests e.g. CRD, RBAC etc.
31+
manifests: controller-gen
32+
$(CONTROLLER_GEN) $(CRD_OPTIONS) rbac:roleName=manager-role webhook paths="./api/...;./controllers/..." output:crd:artifacts:config=config/crd/bases
33+
34+
# Run go fmt against code
35+
fmt:
36+
go fmt ./...
37+
38+
# Run go vet against code
39+
vet:
40+
go vet ./...
41+
42+
# Generate code
43+
generate: controller-gen
44+
$(CONTROLLER_GEN) object:headerFile=./hack/boilerplate.go.txt paths=./api/...
45+
46+
# Build the docker image
47+
docker-build: test
48+
docker build . -t ${IMG}
49+
@echo "updating kustomize image patch file for manager resource"
50+
sed -i'' -e 's@image: .*@image: '"${IMG}"'@' ./config/default/manager_image_patch.yaml
51+
52+
# Push the docker image
53+
docker-push:
54+
docker push ${IMG}
55+
56+
# find or download controller-gen
57+
# download controller-gen if necessary
58+
controller-gen:
59+
ifeq (, $(shell which controller-gen))
60+
go get sigs.k8s.io/controller-tools/cmd/controller-gen@v0.2.0-beta.3
61+
CONTROLLER_GEN=$(shell go env GOPATH)/bin/controller-gen
62+
else
63+
CONTROLLER_GEN=$(shell which controller-gen)
64+
endif

docs/book/src/multiversion-tutorial/testdata/project/api/v2/cronjob_conversion.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ func (src *CronJob) ConvertTo(dstRaw conversion.Hub) error {
6767
dst.Spec.Schedule = strings.Join(scheduleParts, " ")
6868

6969
/*
70-
The rest of the conversion is pretty rote.
70+
The rest of the conversion is pretty rote.
7171
*/
7272
// ObjectMeta
7373
dst.ObjectMeta = src.ObjectMeta
@@ -109,13 +109,13 @@ func (dst *CronJob) ConvertFrom(srcRaw conversion.Hub) error {
109109
return &part
110110
}
111111
dst.Spec.Schedule.Minute = partIfNeeded(schedParts[0])
112-
dst.Spec.Schedule.Hour = partIfNeeded(schedParts[0])
113-
dst.Spec.Schedule.DayOfMonth = partIfNeeded(schedParts[0])
114-
dst.Spec.Schedule.Month = partIfNeeded(schedParts[0])
115-
dst.Spec.Schedule.DayOfWeek = partIfNeeded(schedParts[0])
112+
dst.Spec.Schedule.Hour = partIfNeeded(schedParts[1])
113+
dst.Spec.Schedule.DayOfMonth = partIfNeeded(schedParts[2])
114+
dst.Spec.Schedule.Month = partIfNeeded(schedParts[3])
115+
dst.Spec.Schedule.DayOfWeek = partIfNeeded(schedParts[4])
116116

117117
/*
118-
The rest of the conversion is pretty rote.
118+
The rest of the conversion is pretty rote.
119119
*/
120120
// ObjectMeta
121121
dst.ObjectMeta = src.ObjectMeta

docs/book/src/multiversion-tutorial/testdata/project/api/v2/cronjob_types.go

-2
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,6 @@ We'll leave our spec largely unchanged, except to change the schedule field to a
3939
*/
4040
// CronJobSpec defines the desired state of CronJob
4141
type CronJobSpec struct {
42-
// +kubebuilder:validation:MinLength=0
43-
4442
// The schedule in Cron format, see https://en.wikipedia.org/wiki/Cron.
4543
Schedule CronSchedule `json:"schedule"`
4644

0 commit comments

Comments
 (0)