Skip to content

Commit 012838c

Browse files
📖 update doc samples
1 parent ddb545d commit 012838c

File tree

87 files changed

+1540
-1143
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

87 files changed

+1540
-1143
lines changed

Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,8 @@ test-e2e-ci: ## Run the end-to-end tests (used in the CI)`
139139
.PHONY: test-book
140140
test-book: ## Run the cronjob tutorial's unit tests to make sure we don't break it
141141
cd ./docs/book/src/cronjob-tutorial/testdata/project && make test
142+
cd ./docs/book/src/component-config-tutorial/testdata/project && make test
143+
cd ./docs/book/src/multiversion-tutorial/testdata/project && make test
142144

143145
.PHONY: test-license
144146
test-license: ## Run the license check

docs/book/src/component-config-tutorial/testdata/project/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
*.dylib
88
bin
99
testbin/*
10+
Dockerfile.cross
1011

1112
# Test binary, build with `go test -c`
1213
*.test

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# Build the manager binary
22
FROM golang:1.19 as builder
3+
ARG TARGETOS
4+
ARG TARGETARCH
35

46
WORKDIR /workspace
57
# Copy the Go Modules manifests
@@ -15,7 +17,11 @@ COPY api/ api/
1517
COPY controllers/ controllers/
1618

1719
# Build
18-
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -o manager main.go
20+
# the GOARCH has not a default value to allow the binary be built according to the host where the command
21+
# was called. For example, if we call make docker-build in a local env which has the Apple Silicon M1 SO
22+
# the docker BUILDPLATFORM arg will be linux/arm64 when for Apple x86 it will be linux/amd64. Therefore,
23+
# 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
1925

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

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

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ vet: ## Run go vet against code.
5656

5757
.PHONY: test
5858
test: manifests generate fmt vet envtest ## Run tests.
59-
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) -p path)" go test ./... -coverprofile cover.out
59+
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path)" go test ./... -coverprofile cover.out
6060

6161
##@ Build
6262

@@ -68,6 +68,9 @@ build: generate fmt vet ## Build manager binary.
6868
run: manifests generate fmt vet ## Run a controller from your host.
6969
go run ./main.go
7070

71+
# If you wish built the manager image targeting other platforms you can use the --platform flag.
72+
# (i.e. docker build --platform linux/arm64 ). However, you must enable docker buildKit for it.
73+
# More info: https://docs.docker.com/develop/develop-images/build_enhancements/
7174
.PHONY: docker-build
7275
docker-build: test ## Build docker image with the manager.
7376
docker build -t ${IMG} .
@@ -76,6 +79,23 @@ docker-build: test ## Build docker image with the manager.
7679
docker-push: ## Push docker image with the manager.
7780
docker push ${IMG}
7881

82+
# PLATFORMS defines the target platforms for the manager image be build to provide support to multiple
83+
# architectures. (i.e. make docker-buildx IMG=myregistry/mypoperator:0.0.1). To use this option you need to:
84+
# - able to use docker buildx . More info: https://docs.docker.com/build/buildx/
85+
# - have enable BuildKit, More info: https://docs.docker.com/develop/develop-images/build_enhancements/
86+
# - be able to push the image for your registry (i.e. if you do not inform a valid value via IMG=<myregistry/image:<tag>> than the export will fail)
87+
# To properly provided solutions that supports more than one platform you should use this option.
88+
PLATFORMS ?= linux/arm64,linux/amd64,linux/s390x,linux/ppc64le
89+
.PHONY: docker-buildx
90+
docker-buildx: test ## Build and push docker image for the manager for cross-platform support
91+
# copy existing Dockerfile and insert --platform=${BUILDPLATFORM} into Dockerfile.cross, and preserve the original Dockerfile
92+
sed -e '1 s/\(^FROM\)/FROM --platform=\$$\{BUILDPLATFORM\}/; t' -e ' 1,// s//FROM --platform=\$$\{BUILDPLATFORM\}/' Dockerfile > Dockerfile.cross
93+
- docker buildx create --name project-v3-builder
94+
docker buildx use project-v3-builder
95+
- docker buildx build --push --platform=$(PLATFORMS) --tag ${IMG} -f Dockerfile.cross
96+
- docker buildx rm project-v3-builder
97+
rm Dockerfile.cross
98+
7999
##@ Deployment
80100

81101
ifndef ignore-not-found
@@ -112,8 +132,8 @@ CONTROLLER_GEN ?= $(LOCALBIN)/controller-gen
112132
ENVTEST ?= $(LOCALBIN)/setup-envtest
113133

114134
## Tool Versions
115-
KUSTOMIZE_VERSION ?= v3.8.7
116-
CONTROLLER_TOOLS_VERSION ?= v0.9.0
135+
KUSTOMIZE_VERSION ?= v4.5.5
136+
CONTROLLER_TOOLS_VERSION ?= v0.10.0
117137

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

docs/book/src/component-config-tutorial/testdata/project/api/v2/groupversion_info.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ limitations under the License.
1515
*/
1616

1717
// Package v2 contains API Schema definitions for the config v2 API group
18-
//+kubebuilder:object:generate=true
19-
//+groupName=config.tutorial.kubebuilder.io
18+
// +kubebuilder:object:generate=true
19+
// +groupName=config.tutorial.kubebuilder.io
2020
package v2
2121

2222
import (

docs/book/src/component-config-tutorial/testdata/project/config/crd/bases/config.tutorial.kubebuilder.io_projectconfigs.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ apiVersion: apiextensions.k8s.io/v1
33
kind: CustomResourceDefinition
44
metadata:
55
annotations:
6-
controller-gen.kubebuilder.io/version: v0.9.0
6+
controller-gen.kubebuilder.io/version: v0.10.0
77
creationTimestamp: null
88
name: projectconfigs.config.tutorial.kubebuilder.io
99
spec:

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ patchesStrategicMerge:
3030
# endpoint w/o any authn/z, please comment the following line.
3131
- manager_auth_proxy_patch.yaml
3232

33+
3334
# Mount the controller config file for loading manager configurations
3435
# through a ComponentConfig type
3536
- manager_config_patch.yaml

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

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,22 @@ metadata:
88
spec:
99
template:
1010
spec:
11+
affinity:
12+
nodeAffinity:
13+
requiredDuringSchedulingIgnoredDuringExecution:
14+
nodeSelectorTerms:
15+
- matchExpressions:
16+
- key: kubernetes.io/arch
17+
operator: In
18+
values:
19+
- amd64
20+
- arm64
21+
- ppc64le
22+
- s390x
23+
- key: kubernetes.io/os
24+
operator: In
25+
values:
26+
- linux
1127
containers:
1228
- name: kube-rbac-proxy
1329
securityContext:
@@ -32,8 +48,3 @@ spec:
3248
requests:
3349
cpu: 5m
3450
memory: 64Mi
35-
- name: manager
36-
args:
37-
- "--health-probe-bind-address=:8081"
38-
- "--metrics-bind-address=127.0.0.1:8080"
39-
- "--leader-elect"

docs/book/src/component-config-tutorial/testdata/project/config/manager/controller_manager_config.yaml

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
1-
apiVersion: config.tutorial.kubebuilder.io/v2
2-
kind: ProjectConfig
1+
apiVersion: controller-runtime.sigs.k8s.io/v1alpha1
2+
kind: ControllerManagerConfig
3+
metadata:
4+
labels:
5+
app.kubernetes.io/name: controllermanagerconfig
6+
app.kubernetes.io/instance: controller-manager-configuration
7+
app.kubernetes.io/component: manager
8+
app.kubernetes.io/created-by: project
9+
app.kubernetes.io/part-of: project
10+
app.kubernetes.io/managed-by: kustomize
311
health:
412
healthProbeBindAddress: :8081
513
metrics:

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

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@ kind: Namespace
33
metadata:
44
labels:
55
control-plane: controller-manager
6+
app.kubernetes.io/name: namespace
7+
app.kubernetes.io/instance: system
8+
app.kubernetes.io/component: manager
9+
app.kubernetes.io/created-by: project
10+
app.kubernetes.io/part-of: project
11+
app.kubernetes.io/managed-by: kustomize
612
name: system
713
---
814
apiVersion: apps/v1
@@ -12,6 +18,12 @@ metadata:
1218
namespace: system
1319
labels:
1420
control-plane: controller-manager
21+
app.kubernetes.io/name: deployment
22+
app.kubernetes.io/instance: controller-manager
23+
app.kubernetes.io/component: manager
24+
app.kubernetes.io/created-by: project
25+
app.kubernetes.io/part-of: project
26+
app.kubernetes.io/managed-by: kustomize
1527
spec:
1628
selector:
1729
matchLabels:
@@ -24,6 +36,26 @@ spec:
2436
labels:
2537
control-plane: controller-manager
2638
spec:
39+
# TODO(user): Uncomment the following code to configure the nodeAffinity expression
40+
# according to the platforms which are supported by your solution.
41+
# It is considered best practice to support multiple architectures. You can
42+
# build your manager image using the makefile target docker-buildx.
43+
# affinity:
44+
# nodeAffinity:
45+
# requiredDuringSchedulingIgnoredDuringExecution:
46+
# nodeSelectorTerms:
47+
# - matchExpressions:
48+
# - key: kubernetes.io/arch
49+
# operator: In
50+
# values:
51+
# - amd64
52+
# - arm64
53+
# - ppc64le
54+
# - s390x
55+
# - key: kubernetes.io/os
56+
# operator: In
57+
# values:
58+
# - linux
2759
securityContext:
2860
runAsNonRoot: true
2961
# TODO(user): For common cases that do not require escalating privileges

0 commit comments

Comments
 (0)