Skip to content

Commit 6dcd3b0

Browse files
author
Jelle Dijkstra
committed
(chore) initial scaffold from release version: v4.10.1
1 parent c13bf7c commit 6dcd3b0

33 files changed

+1040
-561
lines changed

.devcontainer/devcontainer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "Kubebuilder DevContainer",
3-
"image": "docker.io/golang:1.23",
3+
"image": "golang:1.24",
44
"features": {
55
"ghcr.io/devcontainers/features/docker-in-docker:2": {},
66
"ghcr.io/devcontainers/features/git:1": {}

.devcontainer/post-install.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
#!/bin/bash
22
set -x
33

4-
curl -Lo ./kind https://kind.sigs.k8s.io/dl/latest/kind-linux-amd64
4+
curl -Lo ./kind https://kind.sigs.k8s.io/dl/latest/kind-linux-$(go env GOARCH)
55
chmod +x ./kind
66
mv ./kind /usr/local/bin/kind
77

8-
curl -L -o kubebuilder https://go.kubebuilder.io/dl/latest/linux/amd64
8+
curl -L -o kubebuilder https://go.kubebuilder.io/dl/latest/linux/$(go env GOARCH)
99
chmod +x kubebuilder
1010
mv kubebuilder /usr/local/bin/
1111

1212
KUBECTL_VERSION=$(curl -L -s https://dl.k8s.io/release/stable.txt)
13-
curl -LO "https://dl.k8s.io/release/$KUBECTL_VERSION/bin/linux/amd64/kubectl"
13+
curl -LO "https://dl.k8s.io/release/$KUBECTL_VERSION/bin/linux/$(go env GOARCH)/kubectl"
1414
chmod +x kubectl
1515
mv kubectl /usr/local/bin/kubectl
1616

.dockerignore

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
11
# More info: https://docs.docker.com/engine/reference/builder/#dockerignore-file
2-
# Ignore build and test binaries.
3-
bin/
2+
# Ignore everything by default and re-include only needed files
3+
**
4+
5+
# Re-include Go source files (but not *_test.go)
6+
!**/*.go
7+
**/*_test.go
8+
9+
# Re-include Go module files
10+
!go.mod
11+
!go.sum

.github/workflows/lint.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,6 @@ jobs:
1818
go-version-file: go.mod
1919

2020
- name: Run linter
21-
uses: golangci/golangci-lint-action@v6
21+
uses: golangci/golangci-lint-action@v8
2222
with:
23-
version: v1.63.4
23+
version: v2.5.0

.github/workflows/test-e2e.yml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,13 @@ jobs:
1919

2020
- name: Install the latest version of kind
2121
run: |
22-
curl -Lo ./kind https://kind.sigs.k8s.io/dl/latest/kind-linux-amd64
22+
curl -Lo ./kind https://kind.sigs.k8s.io/dl/latest/kind-linux-$(go env GOARCH)
2323
chmod +x ./kind
2424
sudo mv ./kind /usr/local/bin/kind
2525
2626
- name: Verify kind installation
2727
run: kind version
2828

29-
- name: Create kind cluster
30-
run: kind create cluster
31-
3229
- name: Running Test e2e
3330
run: |
3431
go mod tidy

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,6 @@ go.work
2525
*.swp
2626
*.swo
2727
*~
28+
29+
# Kubeconfig might contain secrets
30+
*.kubeconfig

.golangci.yml

Lines changed: 31 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,15 @@
1+
version: "2"
12
run:
2-
timeout: 5m
33
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
194
linters:
20-
disable-all: true
5+
default: none
216
enable:
7+
- copyloopvar
228
- dupl
239
- errcheck
24-
- copyloopvar
2510
- ginkgolinter
2611
- goconst
2712
- gocyclo
28-
- gofmt
29-
- goimports
30-
- gosimple
3113
- govet
3214
- ineffassign
3315
- lll
@@ -36,12 +18,35 @@ linters:
3618
- prealloc
3719
- revive
3820
- staticcheck
39-
- typecheck
4021
- unconvert
4122
- unparam
4223
- unused
43-
44-
linters-settings:
45-
revive:
24+
settings:
25+
revive:
26+
rules:
27+
- name: comment-spacings
28+
- name: import-shadowing
29+
exclusions:
30+
generated: lax
4631
rules:
47-
- name: comment-spacings
32+
- linters:
33+
- lll
34+
path: api/*
35+
- linters:
36+
- dupl
37+
- lll
38+
path: internal/*
39+
paths:
40+
- third_party$
41+
- builtin$
42+
- examples$
43+
formatters:
44+
enable:
45+
- gofmt
46+
- goimports
47+
exclusions:
48+
generated: lax
49+
paths:
50+
- third_party$
51+
- builtin$
52+
- examples$

Dockerfile

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Build the manager binary
2-
FROM docker.io/golang:1.23 AS builder
2+
FROM golang:1.24 AS builder
33
ARG TARGETOS
44
ARG TARGETARCH
55

@@ -11,13 +11,11 @@ COPY go.sum go.sum
1111
# and so that source changes don't invalidate our downloaded layer
1212
RUN go mod download
1313

14-
# Copy the go source
15-
COPY cmd/main.go cmd/main.go
16-
COPY api/ api/
17-
COPY internal/ internal/
14+
# Copy the Go source (relies on .dockerignore to filter)
15+
COPY . .
1816

1917
# Build
20-
# the GOARCH has not a default value to allow the binary be built according to the host where the command
18+
# the GOARCH has no default value to allow the binary to be built according to the host where the command
2119
# was called. For example, if we call make docker-build in a local env which has the Apple Silicon M1 SO
2220
# the docker BUILDPLATFORM arg will be linux/arm64 when for Apple x86 it will be linux/amd64. Therefore,
2321
# by leaving it empty we can ensure that the container and binary shipped on it will have the same platform.

Makefile

Lines changed: 60 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,11 @@ help: ## Display this help.
4343

4444
.PHONY: manifests
4545
manifests: controller-gen ## Generate WebhookConfiguration, ClusterRole and CustomResourceDefinition objects.
46-
$(CONTROLLER_GEN) rbac:roleName=manager-role crd webhook paths="./..." output:crd:artifacts:config=config/crd/bases
46+
"$(CONTROLLER_GEN)" rbac:roleName=manager-role crd webhook paths="./..." output:crd:artifacts:config=config/crd/bases
4747

4848
.PHONY: generate
4949
generate: controller-gen ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations.
50-
$(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./..."
50+
"$(CONTROLLER_GEN)" object:headerFile="hack/boilerplate.go.txt" paths="./..."
5151

5252
.PHONY: fmt
5353
fmt: ## Run go fmt against code.
@@ -59,35 +59,48 @@ vet: ## Run go vet against code.
5959

6060
.PHONY: test
6161
test: manifests generate fmt vet setup-envtest ## Run tests.
62-
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path)" go test $$(go list ./... | grep -v /e2e) -coverprofile cover.out
62+
KUBEBUILDER_ASSETS="$(shell "$(ENVTEST)" use $(ENVTEST_K8S_VERSION) --bin-dir "$(LOCALBIN)" -p path)" go test $$(go list ./... | grep -v /e2e) -coverprofile cover.out
6363

6464
# TODO(user): To use a different vendor for e2e tests, modify the setup under 'tests/e2e'.
6565
# The default setup assumes Kind is pre-installed and builds/loads the Manager Docker image locally.
6666
# CertManager is installed by default; skip with:
6767
# - CERT_MANAGER_INSTALL_SKIP=true
68-
.PHONY: test-e2e
69-
test-e2e: manifests generate fmt vet ## Run the e2e tests. Expected an isolated environment using Kind.
70-
@command -v kind >/dev/null 2>&1 || { \
68+
KIND_CLUSTER ?= mapserver-operator-test-e2e
69+
70+
.PHONY: setup-test-e2e
71+
setup-test-e2e: ## Set up a Kind cluster for e2e tests if it does not exist
72+
@command -v $(KIND) >/dev/null 2>&1 || { \
7173
echo "Kind is not installed. Please install Kind manually."; \
7274
exit 1; \
7375
}
74-
@kind get clusters | grep -q 'kind' || { \
75-
echo "No Kind cluster is running. Please start a Kind cluster before running the e2e tests."; \
76-
exit 1; \
77-
}
78-
go test ./test/e2e/ -v -ginkgo.v
76+
@case "$$($(KIND) get clusters)" in \
77+
*"$(KIND_CLUSTER)"*) \
78+
echo "Kind cluster '$(KIND_CLUSTER)' already exists. Skipping creation." ;; \
79+
*) \
80+
echo "Creating Kind cluster '$(KIND_CLUSTER)'..."; \
81+
$(KIND) create cluster --name $(KIND_CLUSTER) ;; \
82+
esac
83+
84+
.PHONY: test-e2e
85+
test-e2e: setup-test-e2e manifests generate fmt vet ## Run the e2e tests. Expected an isolated environment using Kind.
86+
KIND=$(KIND) KIND_CLUSTER=$(KIND_CLUSTER) go test -tags=e2e ./test/e2e/ -v -ginkgo.v
87+
$(MAKE) cleanup-test-e2e
88+
89+
.PHONY: cleanup-test-e2e
90+
cleanup-test-e2e: ## Tear down the Kind cluster used for e2e tests
91+
@$(KIND) delete cluster --name $(KIND_CLUSTER)
7992

8093
.PHONY: lint
8194
lint: golangci-lint ## Run golangci-lint linter
82-
$(GOLANGCI_LINT) run
95+
"$(GOLANGCI_LINT)" run
8396

8497
.PHONY: lint-fix
8598
lint-fix: golangci-lint ## Run golangci-lint linter and perform fixes
86-
$(GOLANGCI_LINT) run --fix
99+
"$(GOLANGCI_LINT)" run --fix
87100

88101
.PHONY: lint-config
89102
lint-config: golangci-lint ## Verify golangci-lint linter configuration
90-
$(GOLANGCI_LINT) config verify
103+
"$(GOLANGCI_LINT)" config verify
91104

92105
##@ Build
93106

@@ -130,8 +143,8 @@ docker-buildx: ## Build and push docker image for the manager for cross-platform
130143
.PHONY: build-installer
131144
build-installer: manifests generate kustomize ## Generate a consolidated YAML with CRDs and deployment.
132145
mkdir -p dist
133-
cd config/manager && $(KUSTOMIZE) edit set image controller=${IMG}
134-
$(KUSTOMIZE) build config/default > dist/install.yaml
146+
cd config/manager && "$(KUSTOMIZE)" edit set image controller=${IMG}
147+
"$(KUSTOMIZE)" build config/default > dist/install.yaml
135148

136149
##@ Deployment
137150

@@ -141,44 +154,53 @@ endif
141154

142155
.PHONY: install
143156
install: manifests kustomize ## Install CRDs into the K8s cluster specified in ~/.kube/config.
144-
$(KUSTOMIZE) build config/crd | $(KUBECTL) apply -f -
157+
@out="$$( "$(KUSTOMIZE)" build config/crd 2>/dev/null || true )"; \
158+
if [ -n "$$out" ]; then echo "$$out" | "$(KUBECTL)" apply -f -; else echo "No CRDs to install; skipping."; fi
145159

146160
.PHONY: uninstall
147161
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.
148-
$(KUSTOMIZE) build config/crd | $(KUBECTL) delete --ignore-not-found=$(ignore-not-found) -f -
162+
@out="$$( "$(KUSTOMIZE)" build config/crd 2>/dev/null || true )"; \
163+
if [ -n "$$out" ]; then echo "$$out" | "$(KUBECTL)" delete --ignore-not-found=$(ignore-not-found) -f -; else echo "No CRDs to delete; skipping."; fi
149164

150165
.PHONY: deploy
151166
deploy: manifests kustomize ## Deploy controller to the K8s cluster specified in ~/.kube/config.
152-
cd config/manager && $(KUSTOMIZE) edit set image controller=${IMG}
153-
$(KUSTOMIZE) build config/default | $(KUBECTL) apply -f -
167+
cd config/manager && "$(KUSTOMIZE)" edit set image controller=${IMG}
168+
"$(KUSTOMIZE)" build config/default | "$(KUBECTL)" apply -f -
154169

155170
.PHONY: undeploy
156171
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.
157-
$(KUSTOMIZE) build config/default | $(KUBECTL) delete --ignore-not-found=$(ignore-not-found) -f -
172+
"$(KUSTOMIZE)" build config/default | "$(KUBECTL)" delete --ignore-not-found=$(ignore-not-found) -f -
158173

159174
##@ Dependencies
160175

161176
## Location to install dependencies to
162177
LOCALBIN ?= $(shell pwd)/bin
163178
$(LOCALBIN):
164-
mkdir -p $(LOCALBIN)
179+
mkdir -p "$(LOCALBIN)"
165180

166181
## Tool Binaries
167182
KUBECTL ?= kubectl
183+
KIND ?= kind
168184
KUSTOMIZE ?= $(LOCALBIN)/kustomize
169185
CONTROLLER_GEN ?= $(LOCALBIN)/controller-gen
170186
ENVTEST ?= $(LOCALBIN)/setup-envtest
171187
GOLANGCI_LINT = $(LOCALBIN)/golangci-lint
172188

173189
## Tool Versions
174-
KUSTOMIZE_VERSION ?= v5.5.0
175-
CONTROLLER_TOOLS_VERSION ?= v0.17.2
190+
KUSTOMIZE_VERSION ?= v5.7.1
191+
CONTROLLER_TOOLS_VERSION ?= v0.19.0
192+
176193
#ENVTEST_VERSION is the version of controller-runtime release branch to fetch the envtest setup script (i.e. release-0.20)
177-
ENVTEST_VERSION ?= $(shell go list -m -f "{{ .Version }}" sigs.k8s.io/controller-runtime | awk -F'[v.]' '{printf "release-%d.%d", $$2, $$3}')
194+
ENVTEST_VERSION ?= $(shell v='$(call gomodver,sigs.k8s.io/controller-runtime)'; \
195+
[ -n "$$v" ] || { echo "Set ENVTEST_VERSION manually (controller-runtime replace has no tag)" >&2; exit 1; }; \
196+
printf '%s\n' "$$v" | sed -E 's/^v?([0-9]+)\.([0-9]+).*/release-\1.\2/')
197+
178198
#ENVTEST_K8S_VERSION is the version of Kubernetes to use for setting up ENVTEST binaries (i.e. 1.31)
179-
ENVTEST_K8S_VERSION ?= $(shell go list -m -f "{{ .Version }}" k8s.io/api | awk -F'[v.]' '{printf "1.%d", $$3}')
180-
GOLANGCI_LINT_VERSION ?= v1.63.4
199+
ENVTEST_K8S_VERSION ?= $(shell v='$(call gomodver,k8s.io/api)'; \
200+
[ -n "$$v" ] || { echo "Set ENVTEST_K8S_VERSION manually (k8s.io/api replace has no tag)" >&2; exit 1; }; \
201+
printf '%s\n' "$$v" | sed -E 's/^v?[0-9]+\.([0-9]+).*/1.\1/')
181202

203+
GOLANGCI_LINT_VERSION ?= v2.5.0
182204
.PHONY: kustomize
183205
kustomize: $(KUSTOMIZE) ## Download kustomize locally if necessary.
184206
$(KUSTOMIZE): $(LOCALBIN)
@@ -192,7 +214,7 @@ $(CONTROLLER_GEN): $(LOCALBIN)
192214
.PHONY: setup-envtest
193215
setup-envtest: envtest ## Download the binaries required for ENVTEST in the local bin directory.
194216
@echo "Setting up envtest binaries for Kubernetes version $(ENVTEST_K8S_VERSION)..."
195-
@$(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path || { \
217+
@"$(ENVTEST)" use $(ENVTEST_K8S_VERSION) --bin-dir "$(LOCALBIN)" -p path || { \
196218
echo "Error: Failed to set up envtest binaries for version $(ENVTEST_K8S_VERSION)."; \
197219
exit 1; \
198220
}
@@ -205,20 +227,24 @@ $(ENVTEST): $(LOCALBIN)
205227
.PHONY: golangci-lint
206228
golangci-lint: $(GOLANGCI_LINT) ## Download golangci-lint locally if necessary.
207229
$(GOLANGCI_LINT): $(LOCALBIN)
208-
$(call go-install-tool,$(GOLANGCI_LINT),github.com/golangci/golangci-lint/cmd/golangci-lint,$(GOLANGCI_LINT_VERSION))
230+
$(call go-install-tool,$(GOLANGCI_LINT),github.com/golangci/golangci-lint/v2/cmd/golangci-lint,$(GOLANGCI_LINT_VERSION))
209231

210232
# go-install-tool will 'go install' any package with custom target and name of binary, if it doesn't exist
211233
# $1 - target path with name of binary
212234
# $2 - package url which can be installed
213235
# $3 - specific version of package
214236
define go-install-tool
215-
@[ -f "$(1)-$(3)" ] || { \
237+
@[ -f "$(1)-$(3)" ] && [ "$$(readlink -- "$(1)" 2>/dev/null)" = "$(1)-$(3)" ] || { \
216238
set -e; \
217239
package=$(2)@$(3) ;\
218240
echo "Downloading $${package}" ;\
219-
rm -f $(1) || true ;\
220-
GOBIN=$(LOCALBIN) go install $${package} ;\
221-
mv $(1) $(1)-$(3) ;\
241+
rm -f "$(1)" ;\
242+
GOBIN="$(LOCALBIN)" go install $${package} ;\
243+
mv "$(LOCALBIN)/$$(basename "$(1)")" "$(1)-$(3)" ;\
222244
} ;\
223-
ln -sf $(1)-$(3) $(1)
245+
ln -sf "$$(realpath "$(1)-$(3)")" "$(1)"
246+
endef
247+
248+
define gomodver
249+
$(shell go list -m -f '{{if .Replace}}{{.Replace.Version}}{{else}}{{.Version}}{{end}}' $(1) 2>/dev/null)
224250
endef

PROJECT

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# This file is used to track the info used to scaffold your project
33
# and allow the plugins properly work.
44
# More info: https://book.kubebuilder.io/reference/project-config.html
5+
cliVersion: 4.10.1
56
domain: pdok.nl
67
layout:
78
- go.kubebuilder.io/v4

0 commit comments

Comments
 (0)