Skip to content

Commit c10168f

Browse files
📖 Update multiversion-tutorial with the latest manually
1 parent 4c77ebe commit c10168f

38 files changed

+10461
-1438
lines changed
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
# More info: https://docs.docker.com/engine/reference/builder/#dockerignore-file
22
# Ignore build and test binaries.
33
bin/
4-
testbin/

docs/book/src/multiversion-tutorial/testdata/project/.gitignore

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,24 @@
55
*.dll
66
*.so
77
*.dylib
8-
bin
9-
testbin/*
8+
bin/*
109
Dockerfile.cross
1110

12-
# Test binary, build with `go test -c`
11+
# Test binary, built with `go test -c`
1312
*.test
1413

1514
# Output of the go coverage tool, specifically when used with LiteIDE
1615
*.out
1716

18-
# Kubernetes Generated files - skip generated files, except for vendored files
17+
# Go workspace file
18+
go.work
1919

20+
# Kubernetes Generated files - skip generated files, except for vendored files
2021
!vendor/**/zz_generated.*
2122

2223
# editor and IDE paraphernalia
2324
.idea
25+
.vscode
2426
*.swp
2527
*.swo
2628
*~
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
run:
2+
deadline: 5m
3+
allow-parallel-runners: true
4+
5+
issues:
6+
# don't skip warning about doc comments
7+
# don't exclude the default set of lint
8+
exclude-use-default: false
9+
# restore some of the defaults
10+
# (fill in the rest as needed)
11+
exclude-rules:
12+
- path: "api/*"
13+
linters:
14+
- lll
15+
- path: "internal/*"
16+
linters:
17+
- dupl
18+
- lll
19+
linters:
20+
disable-all: true
21+
enable:
22+
- dupl
23+
- errcheck
24+
- exportloopref
25+
- goconst
26+
- gocyclo
27+
- gofmt
28+
- goimports
29+
- gosimple
30+
- govet
31+
- ineffassign
32+
- lll
33+
- misspell
34+
- nakedret
35+
- prealloc
36+
- staticcheck
37+
- typecheck
38+
- unconvert
39+
- unparam
40+
- unused

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Build the manager binary
2-
FROM golang:1.19 as builder
2+
FROM golang:1.21 AS builder
33
ARG TARGETOS
44
ARG TARGETARCH
55

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

Lines changed: 81 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# Image URL to use all building/pushing image targets
33
IMG ?= controller:latest
44
# ENVTEST_K8S_VERSION refers to the version of kubebuilder assets to be downloaded by envtest binary.
5-
ENVTEST_K8S_VERSION = 1.27.1
5+
ENVTEST_K8S_VERSION = 1.29.0
66

77
# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
88
ifeq (,$(shell go env GOBIN))
@@ -11,6 +11,12 @@ else
1111
GOBIN=$(shell go env GOBIN)
1212
endif
1313

14+
# CONTAINER_TOOL defines the container tool to be used for building images.
15+
# Be aware that the target commands are only tested with Docker which is
16+
# scaffolded by default. However, you might want to replace it to use other
17+
# tools. (i.e. podman)
18+
CONTAINER_TOOL ?= docker
19+
1420
# Setting SHELL to bash allows bash commands to be executed by recipes.
1521
# Options are set to exit when a recipe line exits non-zero or a piped command fails.
1622
SHELL = /usr/bin/env bash -o pipefail
@@ -40,11 +46,7 @@ help: ## Display this help.
4046

4147
.PHONY: manifests
4248
manifests: controller-gen ## Generate WebhookConfiguration, ClusterRole and CustomResourceDefinition objects.
43-
# Note that the option maxDescLen=0 was added in the default scaffold in order to sort out the issue
44-
# Too long: must have at most 262144 bytes. By using kubectl apply to create / update resources an annotation
45-
# is created by K8s API to store the latest version of the resource ( kubectl.kubernetes.io/last-applied-configuration).
46-
# However, it has a size limit and if the CRD is too big with so many long descriptions as this one it will cause the failure.
47-
$(CONTROLLER_GEN) rbac:roleName=manager-role crd:maxDescLen=0 webhook paths="./..." output:crd:artifacts:config=config/crd/bases
49+
$(CONTROLLER_GEN) rbac:roleName=manager-role crd webhook paths="./..." output:crd:artifacts:config=config/crd/bases
4850

4951
.PHONY: generate
5052
generate: controller-gen ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations.
@@ -60,7 +62,20 @@ vet: ## Run go vet against code.
6062

6163
.PHONY: test
6264
test: manifests generate fmt vet envtest ## Run tests.
63-
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path)" go test ./... -coverprofile cover.out
65+
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path)" go test $$(go list ./... | grep -v /e2e) -coverprofile cover.out
66+
67+
# Utilize Kind or modify the e2e tests to load the image locally, enabling compatibility with other vendors.
68+
.PHONY: test-e2e # Run the e2e tests against a Kind k8s instance that is spun up.
69+
test-e2e:
70+
go test ./test/e2e/ -v -ginkgo.v
71+
72+
.PHONY: lint
73+
lint: golangci-lint ## Run golangci-lint linter & yamllint
74+
$(GOLANGCI_LINT) run
75+
76+
.PHONY: lint-fix
77+
lint-fix: golangci-lint ## Run golangci-lint linter and perform fixes
78+
$(GOLANGCI_LINT) run --fix
6479

6580
##@ Build
6681

@@ -76,12 +91,12 @@ run: manifests generate fmt vet ## Run a controller from your host.
7691
# (i.e. docker build --platform linux/arm64). However, you must enable docker buildKit for it.
7792
# More info: https://docs.docker.com/develop/develop-images/build_enhancements/
7893
.PHONY: docker-build
79-
docker-build: test ## Build docker image with the manager.
80-
docker build -t ${IMG} .
94+
docker-build: ## Build docker image with the manager.
95+
$(CONTAINER_TOOL) build -t ${IMG} .
8196

8297
.PHONY: docker-push
8398
docker-push: ## Push docker image with the manager.
84-
docker push ${IMG}
99+
$(CONTAINER_TOOL) push ${IMG}
85100

86101
# PLATFORMS defines the target platforms for the manager image be built to provide support to multiple
87102
# architectures. (i.e. make docker-buildx IMG=myregistry/mypoperator:0.0.1). To use this option you need to:
@@ -91,15 +106,26 @@ docker-push: ## Push docker image with the manager.
91106
# To adequately provide solutions that are compatible with multiple platforms, you should consider using this option.
92107
PLATFORMS ?= linux/arm64,linux/amd64,linux/s390x,linux/ppc64le
93108
.PHONY: docker-buildx
94-
docker-buildx: test ## Build and push docker image for the manager for cross-platform support
109+
docker-buildx: ## Build and push docker image for the manager for cross-platform support
95110
# copy existing Dockerfile and insert --platform=${BUILDPLATFORM} into Dockerfile.cross, and preserve the original Dockerfile
96111
sed -e '1 s/\(^FROM\)/FROM --platform=\$$\{BUILDPLATFORM\}/; t' -e ' 1,// s//FROM --platform=\$$\{BUILDPLATFORM\}/' Dockerfile > Dockerfile.cross
97-
- docker buildx create --name project-v3-builder
98-
docker buildx use project-v3-builder
99-
- docker buildx build --push --platform=$(PLATFORMS) --tag ${IMG} -f Dockerfile.cross .
100-
- docker buildx rm project-v3-builder
112+
- $(CONTAINER_TOOL) buildx create --name project-v3-builder
113+
$(CONTAINER_TOOL) buildx use project-v3-builder
114+
- $(CONTAINER_TOOL) buildx build --push --platform=$(PLATFORMS) --tag ${IMG} -f Dockerfile.cross .
115+
- $(CONTAINER_TOOL) buildx rm project-v3-builder
101116
rm Dockerfile.cross
102117

118+
.PHONY: build-installer
119+
build-installer: manifests generate kustomize ## Generate a consolidated YAML with CRDs and deployment.
120+
mkdir -p dist
121+
echo "---" > dist/install.yaml # Clean previous content
122+
@if [ -d "config/crd" ]; then \
123+
$(KUSTOMIZE) build config/crd > dist/install.yaml; \
124+
echo "---" >> dist/install.yaml; \
125+
fi
126+
cd config/manager && $(KUSTOMIZE) edit set image controller=${IMG}
127+
$(KUSTOMIZE) build config/default >> dist/install.yaml
128+
103129
##@ Deployment
104130

105131
ifndef ignore-not-found
@@ -108,54 +134,71 @@ endif
108134

109135
.PHONY: install
110136
install: manifests kustomize ## Install CRDs into the K8s cluster specified in ~/.kube/config.
111-
$(KUSTOMIZE) build config/crd | kubectl apply -f -
137+
$(KUSTOMIZE) build config/crd | $(KUBECTL) apply -f -
112138

113139
.PHONY: uninstall
114140
uninstall: manifests kustomize ## Uninstall CRDs from the K8s cluster specified in ~/.kube/config. Call with ignore-not-found=true to ignore resource not found errors during deletion.
115-
$(KUSTOMIZE) build config/crd | kubectl delete --ignore-not-found=$(ignore-not-found) -f -
141+
$(KUSTOMIZE) build config/crd | $(KUBECTL) delete --ignore-not-found=$(ignore-not-found) -f -
116142

117143
.PHONY: deploy
118144
deploy: manifests kustomize ## Deploy controller to the K8s cluster specified in ~/.kube/config.
119145
cd config/manager && $(KUSTOMIZE) edit set image controller=${IMG}
120-
$(KUSTOMIZE) build config/default | kubectl apply -f -
146+
$(KUSTOMIZE) build config/default | $(KUBECTL) apply -f -
121147

122148
.PHONY: undeploy
123-
undeploy: ## Undeploy controller from the K8s cluster specified in ~/.kube/config. Call with ignore-not-found=true to ignore resource not found errors during deletion.
124-
$(KUSTOMIZE) build config/default | kubectl delete --ignore-not-found=$(ignore-not-found) -f -
149+
undeploy: kustomize ## Undeploy controller from the K8s cluster specified in ~/.kube/config. Call with ignore-not-found=true to ignore resource not found errors during deletion.
150+
$(KUSTOMIZE) build config/default | $(KUBECTL) delete --ignore-not-found=$(ignore-not-found) -f -
125151

126-
##@ Build Dependencies
152+
##@ Dependencies
127153

128154
## Location to install dependencies to
129155
LOCALBIN ?= $(shell pwd)/bin
130156
$(LOCALBIN):
131157
mkdir -p $(LOCALBIN)
132158

133159
## Tool Binaries
134-
KUSTOMIZE ?= $(LOCALBIN)/kustomize
135-
CONTROLLER_GEN ?= $(LOCALBIN)/controller-gen
136-
ENVTEST ?= $(LOCALBIN)/setup-envtest
160+
KUBECTL ?= kubectl
161+
KUSTOMIZE ?= $(LOCALBIN)/kustomize-$(KUSTOMIZE_VERSION)
162+
CONTROLLER_GEN ?= $(LOCALBIN)/controller-gen-$(CONTROLLER_TOOLS_VERSION)
163+
ENVTEST ?= $(LOCALBIN)/setup-envtest-$(ENVTEST_VERSION)
164+
GOLANGCI_LINT = $(LOCALBIN)/golangci-lint-$(GOLANGCI_LINT_VERSION)
137165

138166
## Tool Versions
139-
KUSTOMIZE_VERSION ?= v5.0.0
140-
CONTROLLER_TOOLS_VERSION ?= v0.12.0
167+
KUSTOMIZE_VERSION ?= v5.3.0
168+
CONTROLLER_TOOLS_VERSION ?= v0.14.0
169+
ENVTEST_VERSION ?= release-0.17
170+
GOLANGCI_LINT_VERSION ?= v1.54.2
141171

142-
KUSTOMIZE_INSTALL_SCRIPT ?= "https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh"
143172
.PHONY: kustomize
144-
kustomize: $(KUSTOMIZE) ## Download kustomize locally if necessary. If wrong version is installed, it will be removed before downloading.
173+
kustomize: $(KUSTOMIZE) ## Download kustomize locally if necessary.
145174
$(KUSTOMIZE): $(LOCALBIN)
146-
@if test -x $(LOCALBIN)/kustomize && ! $(LOCALBIN)/kustomize version | grep -q $(KUSTOMIZE_VERSION); then \
147-
echo "$(LOCALBIN)/kustomize version is not expected $(KUSTOMIZE_VERSION). Removing it before installing."; \
148-
rm -rf $(LOCALBIN)/kustomize; \
149-
fi
150-
test -s $(LOCALBIN)/kustomize || { curl -Ss $(KUSTOMIZE_INSTALL_SCRIPT) --output install_kustomize.sh && bash install_kustomize.sh $(subst v,,$(KUSTOMIZE_VERSION)) $(LOCALBIN); rm install_kustomize.sh; }
175+
$(call go-install-tool,$(KUSTOMIZE),sigs.k8s.io/kustomize/kustomize/v5,$(KUSTOMIZE_VERSION))
151176

152177
.PHONY: controller-gen
153-
controller-gen: $(CONTROLLER_GEN) ## Download controller-gen locally if necessary. If wrong version is installed, it will be overwritten.
178+
controller-gen: $(CONTROLLER_GEN) ## Download controller-gen locally if necessary.
154179
$(CONTROLLER_GEN): $(LOCALBIN)
155-
test -s $(LOCALBIN)/controller-gen && $(LOCALBIN)/controller-gen --version | grep -q $(CONTROLLER_TOOLS_VERSION) || \
156-
GOBIN=$(LOCALBIN) go install sigs.k8s.io/controller-tools/cmd/controller-gen@$(CONTROLLER_TOOLS_VERSION)
180+
$(call go-install-tool,$(CONTROLLER_GEN),sigs.k8s.io/controller-tools/cmd/controller-gen,$(CONTROLLER_TOOLS_VERSION))
157181

158182
.PHONY: envtest
159-
envtest: $(ENVTEST) ## Download envtest-setup locally if necessary.
183+
envtest: $(ENVTEST) ## Download setup-envtest locally if necessary.
160184
$(ENVTEST): $(LOCALBIN)
161-
test -s $(LOCALBIN)/setup-envtest || GOBIN=$(LOCALBIN) go install sigs.k8s.io/controller-runtime/tools/setup-envtest@latest
185+
$(call go-install-tool,$(ENVTEST),sigs.k8s.io/controller-runtime/tools/setup-envtest,$(ENVTEST_VERSION))
186+
187+
.PHONY: golangci-lint
188+
golangci-lint: $(GOLANGCI_LINT) ## Download golangci-lint locally if necessary.
189+
$(GOLANGCI_LINT): $(LOCALBIN)
190+
$(call go-install-tool,$(GOLANGCI_LINT),github.com/golangci/golangci-lint/cmd/golangci-lint,${GOLANGCI_LINT_VERSION})
191+
192+
# go-install-tool will 'go install' any package with custom target and name of binary, if it doesn't exist
193+
# $1 - target path with name of binary (ideally with version)
194+
# $2 - package url which can be installed
195+
# $3 - specific version of package
196+
define go-install-tool
197+
@[ -f $(1) ] || { \
198+
set -e; \
199+
package=$(2)@$(3) ;\
200+
echo "Downloading $${package}" ;\
201+
GOBIN=$(LOCALBIN) go install $${package} ;\
202+
mv "$$(echo "$(1)" | sed "s/-$(3)$$//")" $(1) ;\
203+
}
204+
endef

0 commit comments

Comments
 (0)