Skip to content

Commit 3f0aa0c

Browse files
📖 updating the component config tutorial to use go/v4
1 parent 321c00c commit 3f0aa0c

File tree

9 files changed

+118
-42
lines changed

9 files changed

+118
-42
lines changed

docs/book/src/component-config-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/component-config-tutorial/testdata/project/Makefile

Lines changed: 3 additions & 3 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,7 +132,7 @@ CONTROLLER_GEN ?= $(LOCALBIN)/controller-gen
132132
ENVTEST ?= $(LOCALBIN)/setup-envtest
133133

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

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

docs/book/src/component-config-tutorial/testdata/project/PROJECT

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
componentConfig: true
66
domain: tutorial.kubebuilder.io
77
layout:
8-
- go.kubebuilder.io/v3
8+
- go.kubebuilder.io/v4
99
projectName: project
1010
repo: tutorial.kubebuilder.io/project
1111
resources:

docs/book/src/component-config-tutorial/testdata/project/config/crd/patches/cainjection_in_projectconfigs.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@ apiVersion: apiextensions.k8s.io/v1
33
kind: CustomResourceDefinition
44
metadata:
55
annotations:
6-
cert-manager.io/inject-ca-from: $(CERTIFICATE_NAMESPACE)/$(CERTIFICATE_NAME)
6+
cert-manager.io/inject-ca-from: CERTIFICATE_NAMESPACE/CERTIFICATE_NAME
77
name: projectconfigs.config.tutorial.kubebuilder.io

docs/book/src/component-config-tutorial/testdata/project/config/default/kustomization.yaml

Lines changed: 103 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,12 @@ namespace: project-system
99
namePrefix: project-
1010

1111
# Labels to add to all resources and selectors.
12-
#commonLabels:
13-
# someName: someValue
12+
#labels:
13+
#- includeSelectors: true
14+
# pairs:
15+
# someName: someValue
1416

15-
bases:
17+
resources:
1618
- ../crd
1719
- ../rbac
1820
- ../manager
@@ -44,32 +46,102 @@ patchesStrategicMerge:
4446
# 'CERTMANAGER' needs to be enabled to use ca injection
4547
#- webhookcainjection_patch.yaml
4648

47-
# the following config is for teaching kustomize how to do var substitution
48-
vars:
4949
# [CERTMANAGER] To enable cert-manager, uncomment all sections with 'CERTMANAGER' prefix.
50-
#- name: CERTIFICATE_NAMESPACE # namespace of the certificate CR
51-
# objref:
52-
# kind: Certificate
53-
# group: cert-manager.io
54-
# version: v1
55-
# name: serving-cert # this name should match the one in certificate.yaml
56-
# fieldref:
57-
# fieldpath: metadata.namespace
58-
#- name: CERTIFICATE_NAME
59-
# objref:
60-
# kind: Certificate
61-
# group: cert-manager.io
62-
# version: v1
63-
# name: serving-cert # this name should match the one in certificate.yaml
64-
#- name: SERVICE_NAMESPACE # namespace of the service
65-
# objref:
66-
# kind: Service
67-
# version: v1
68-
# name: webhook-service
69-
# fieldref:
70-
# fieldpath: metadata.namespace
71-
#- name: SERVICE_NAME
72-
# objref:
73-
# kind: Service
74-
# version: v1
75-
# name: webhook-service
50+
# Uncomment the following replacements to add the cert-manager CA injection annotations
51+
#replacements:
52+
# - source: # Add cert-manager annotation to ValidatingWebhookConfiguration, MutatingWebhookConfiguration and CRDs
53+
# kind: Certificate
54+
# group: cert-manager.io
55+
# version: v1
56+
# name: serving-cert # this name should match the one in certificate.yaml
57+
# fieldPath: .metadata.namespace # namespace of the certificate CR
58+
# targets:
59+
# - select:
60+
# kind: ValidatingWebhookConfiguration
61+
# fieldPaths:
62+
# - .metadata.annotations.[cert-manager.io/inject-ca-from]
63+
# options:
64+
# delimiter: '/'
65+
# index: 0
66+
# create: true
67+
# - select:
68+
# kind: MutatingWebhookConfiguration
69+
# fieldPaths:
70+
# - .metadata.annotations.[cert-manager.io/inject-ca-from]
71+
# options:
72+
# delimiter: '/'
73+
# index: 0
74+
# create: true
75+
# - select:
76+
# kind: CustomResourceDefinition
77+
# fieldPaths:
78+
# - .metadata.annotations.[cert-manager.io/inject-ca-from]
79+
# options:
80+
# delimiter: '/'
81+
# index: 0
82+
# create: true
83+
# - source:
84+
# kind: Certificate
85+
# group: cert-manager.io
86+
# version: v1
87+
# name: serving-cert # this name should match the one in certificate.yaml
88+
# fieldPath: .metadata.name
89+
# targets:
90+
# - select:
91+
# kind: ValidatingWebhookConfiguration
92+
# fieldPaths:
93+
# - .metadata.annotations.[cert-manager.io/inject-ca-from]
94+
# options:
95+
# delimiter: '/'
96+
# index: 1
97+
# create: true
98+
# - select:
99+
# kind: MutatingWebhookConfiguration
100+
# fieldPaths:
101+
# - .metadata.annotations.[cert-manager.io/inject-ca-from]
102+
# options:
103+
# delimiter: '/'
104+
# index: 1
105+
# create: true
106+
# - select:
107+
# kind: CustomResourceDefinition
108+
# fieldPaths:
109+
# - .metadata.annotations.[cert-manager.io/inject-ca-from]
110+
# options:
111+
# delimiter: '/'
112+
# index: 1
113+
# create: true
114+
# - source: # Add cert-manager annotation to the webhook Service
115+
# kind: Service
116+
# version: v1
117+
# name: webhook-service
118+
# fieldPath: .metadata.name # namespace of the service
119+
# targets:
120+
# - select:
121+
# kind: Certificate
122+
# group: cert-manager.io
123+
# version: v1
124+
# fieldPaths:
125+
# - .spec.dnsNames.0
126+
# - .spec.dnsNames.1
127+
# options:
128+
# delimiter: '.'
129+
# index: 0
130+
# create: true
131+
# - source:
132+
# kind: Service
133+
# version: v1
134+
# name: webhook-service
135+
# fieldPath: .metadata.namespace # namespace of the service
136+
# targets:
137+
# - select:
138+
# kind: Certificate
139+
# group: cert-manager.io
140+
# version: v1
141+
# fieldPaths:
142+
# - .spec.dnsNames.0
143+
# - .spec.dnsNames.1
144+
# options:
145+
# delimiter: '.'
146+
# index: 1
147+
# create: true

docs/book/src/component-config-tutorial/testdata/project/config/rbac/service_account.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ kind: ServiceAccount
33
metadata:
44
labels:
55
app.kubernetes.io/name: serviceaccount
6-
app.kubernetes.io/instance: controller-manager
6+
app.kubernetes.io/instance: controller-manager-sa
77
app.kubernetes.io/component: rbac
88
app.kubernetes.io/created-by: project
99
app.kubernetes.io/part-of: project
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
## Append samples of your project ##
2+
resources:
3+
- config_v2_projectconfig.yaml
4+
#+kubebuilder:scaffold:manifestskustomizesamples

hack/docs/internal/generate_component_config.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,14 +137,14 @@ clusterName: example-test
137137

138138
// 3. fix main
139139
err = pluginutil.InsertCode(
140-
filepath.Join(sp.ctx.Dir, "main.go"),
140+
filepath.Join(sp.ctx.Dir, "cmd/main.go"),
141141
`var err error`,
142142
`
143143
ctrlConfig := configv2.ProjectConfig{}`)
144144
CheckError("fixing main.go", err)
145145

146146
err = pluginutil.InsertCode(
147-
filepath.Join(sp.ctx.Dir, "main.go"),
147+
filepath.Join(sp.ctx.Dir, "cmd/main.go"),
148148
`AtPath(configFile)`,
149149
`.OfKind(&ctrlConfig)`)
150150
CheckError("fixing main.go", err)

0 commit comments

Comments
 (0)