Skip to content

Commit 1dc75e3

Browse files
authored
Merge pull request #3281 from camilamacedo86/update-cronjob-tutorial
📖 update cronjob tutorial sample to use go/v4
2 parents 958cda2 + 66aa98b commit 1dc75e3

25 files changed

+149
-85
lines changed

docs/book/install-and-build.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ ${cmd} /tmp/mdbook.${ext}
6767
chmod +x /tmp/mdbook
6868

6969
echo "grabbing the latest released controller-gen"
70-
go install sigs.k8s.io/controller-tools/cmd/[email protected].1
70+
go install sigs.k8s.io/controller-tools/cmd/[email protected].3
7171

7272
# make sure we add the go bin directory to our path
7373
gobin=$(go env GOBIN)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ The basic logic of our CronJob controller is this:
1818
7. Requeue when we either see a running job (done automatically) or it's
1919
time for the next scheduled run.
2020

21-
{{#literatego ./testdata/project/controllers/cronjob_controller.go}}
21+
{{#literatego ./testdata/project/internal/controller/cronjob_controller.go}}
2222

2323
That was a doozy, but now we've got a working controller. Let's test
2424
against the cluster, then, if we don't have any issues, deploy it!

docs/book/src/cronjob-tutorial/main-revisited.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@ But first, remember how we said we'd [come back to `main.go`
44
again](/cronjob-tutorial/empty-main.md)? Let's take a look and see what's
55
changed, and what we need to add.
66

7-
{{#literatego ./testdata/project/main.go}}
7+
{{#literatego ./testdata/project/cmd/main.go}}
88

99
*Now* we can implement our controller.

docs/book/src/cronjob-tutorial/testdata/generate_cronjob.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ function gen_cronjob_tutorial {
5252
mkdir project
5353
cd project
5454
header_text "creating tutorial.kubebuilder.io base ..."
55-
kubebuilder init --domain tutorial.kubebuilder.io --repo tutorial.kubebuilder.io/project --license apache2 --owner "The Kubernetes authors"
55+
kubebuilder init --plugins=go/v4 --domain tutorial.kubebuilder.io --repo tutorial.kubebuilder.io/project --license apache2 --owner "The Kubernetes authors"
5656
kubebuilder create api --group batch --version v1 --kind CronJob --resource --controller
5757
kubebuilder create webhook --group batch --version v1 --kind CronJob --defaulting --programmatic-validation
5858
go mod tidy

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,16 @@ COPY go.sum go.sum
1212
RUN go mod download
1313

1414
# Copy the go source
15-
COPY main.go main.go
15+
COPY cmd/main.go cmd/main.go
1616
COPY api/ api/
17-
COPY controllers/ controllers/
17+
COPY internal/controller/ internal/controller/
1818

1919
# Build
2020
# the GOARCH has not a default value to allow the binary be built according to the host where the command
2121
# was called. For example, if we call make docker-build in a local env which has the Apple Silicon M1 SO
2222
# the docker BUILDPLATFORM arg will be linux/arm64 when for Apple x86 it will be linux/amd64. Therefore,
2323
# by leaving it empty we can ensure that the container and binary shipped on it will have the same platform.
24-
RUN CGO_ENABLED=0 GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH} go build -a -o manager main.go
24+
RUN CGO_ENABLED=0 GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH} go build -a -o manager cmd/main.go
2525

2626
# Use distroless as minimal base image to package the manager binary
2727
# Refer to https://github.com/GoogleContainerTools/distroless for more details

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,11 @@ test: manifests generate fmt vet envtest ## Run tests.
6262

6363
.PHONY: build
6464
build: manifests generate fmt vet ## Build manager binary.
65-
go build -o bin/manager main.go
65+
go build -o bin/manager cmd/main.go
6666

6767
.PHONY: run
6868
run: manifests generate fmt vet ## Run a controller from your host.
69-
go run ./main.go
69+
go run ./cmd/main.go
7070

7171
# If you wish built the manager image targeting other platforms you can use the --platform flag.
7272
# (i.e. docker build --platform linux/arm64 ). However, you must enable docker buildKit for it.
@@ -132,8 +132,8 @@ CONTROLLER_GEN ?= $(LOCALBIN)/controller-gen
132132
ENVTEST ?= $(LOCALBIN)/setup-envtest
133133

134134
## Tool Versions
135-
KUSTOMIZE_VERSION ?= v3.8.7
136-
CONTROLLER_TOOLS_VERSION ?= v0.11.1
135+
KUSTOMIZE_VERSION ?= v5.0.0
136+
CONTROLLER_TOOLS_VERSION ?= v0.11.3
137137

138138
KUSTOMIZE_INSTALL_SCRIPT ?= "https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh"
139139
.PHONY: kustomize

docs/book/src/cronjob-tutorial/testdata/project/PROJECT

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# More info: https://book.kubebuilder.io/reference/project-config.html
55
domain: tutorial.kubebuilder.io
66
layout:
7-
- go.kubebuilder.io/v3
7+
- go.kubebuilder.io/v4
88
projectName: project
99
repo: tutorial.kubebuilder.io/project
1010
resources:

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import (
2828
. "github.com/onsi/ginkgo/v2"
2929
. "github.com/onsi/gomega"
3030

31-
admissionv1beta1 "k8s.io/api/admission/v1beta1"
31+
admissionv1 "k8s.io/api/admission/v1"
3232
//+kubebuilder:scaffold:imports
3333
"k8s.io/apimachinery/pkg/runtime"
3434
"k8s.io/client-go/rest"
@@ -78,7 +78,7 @@ var _ = BeforeSuite(func() {
7878
err = AddToScheme(scheme)
7979
Expect(err).NotTo(HaveOccurred())
8080

81-
err = admissionv1beta1.AddToScheme(scheme)
81+
err = admissionv1.AddToScheme(scheme)
8282
Expect(err).NotTo(HaveOccurred())
8383

8484
//+kubebuilder:scaffold:scheme

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ package main
2020
import (
2121
"flag"
2222
"os"
23+
"tutorial.kubebuilder.io/project/internal/controller"
2324

2425
// Import all Kubernetes client auth plugins (e.g. Azure, GCP, OIDC, etc.)
2526
// to ensure that exec-entrypoint and run can make use of them.
@@ -33,7 +34,6 @@ import (
3334
"sigs.k8s.io/controller-runtime/pkg/log/zap"
3435

3536
batchv1 "tutorial.kubebuilder.io/project/api/v1"
36-
"tutorial.kubebuilder.io/project/controllers"
3737
//+kubebuilder:scaffold:imports
3838
)
3939

@@ -109,7 +109,7 @@ func main() {
109109

110110
// +kubebuilder:docs-gen:collapse=old stuff
111111

112-
if err = (&controllers.CronJobReconciler{
112+
if err = (&controller.CronJobReconciler{
113113
Client: mgr.GetClient(),
114114
Scheme: mgr.GetScheme(),
115115
}).SetupWithManager(mgr); err != nil {

docs/book/src/cronjob-tutorial/testdata/project/config/certmanager/certificate.yaml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ apiVersion: cert-manager.io/v1
55
kind: Issuer
66
metadata:
77
labels:
8-
app.kubernetes.io/name: issuer
9-
app.kubernetes.io/instance: selfsigned-issuer
8+
app.kubernetes.io/name: certificate
9+
app.kubernetes.io/instance: serving-cert
1010
app.kubernetes.io/component: certificate
1111
app.kubernetes.io/created-by: project
1212
app.kubernetes.io/part-of: project
@@ -29,10 +29,10 @@ metadata:
2929
name: serving-cert # this name should match the one appeared in kustomizeconfig.yaml
3030
namespace: system
3131
spec:
32-
# $(SERVICE_NAME) and $(SERVICE_NAMESPACE) will be substituted by kustomize
32+
# SERVICE_NAME and SERVICE_NAMESPACE will be substituted by kustomize
3333
dnsNames:
34-
- $(SERVICE_NAME).$(SERVICE_NAMESPACE).svc
35-
- $(SERVICE_NAME).$(SERVICE_NAMESPACE).svc.cluster.local
34+
- SERVICE_NAME.SERVICE_NAMESPACE.svc
35+
- SERVICE_NAME.SERVICE_NAMESPACE.svc.cluster.local
3636
issuerRef:
3737
kind: Issuer
3838
name: selfsigned-issuer

0 commit comments

Comments
 (0)