Skip to content

Commit e3227b4

Browse files
committed
merge from main
Signed-off-by: Scott Trent <[email protected]>
2 parents 923285e + 425ba54 commit e3227b4

31 files changed

+480
-195
lines changed

.devcontainer/devcontainer.json

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"name": "Kubebuilder DevContainer",
3+
"image": "golang:1.24",
4+
"features": {
5+
"ghcr.io/devcontainers/features/docker-in-docker:2": {},
6+
"ghcr.io/devcontainers/features/git:1": {}
7+
},
8+
9+
"runArgs": ["--network=host"],
10+
11+
"customizations": {
12+
"vscode": {
13+
"settings": {
14+
"terminal.integrated.shell.linux": "/bin/bash"
15+
},
16+
"extensions": [
17+
"ms-kubernetes-tools.vscode-kubernetes-tools",
18+
"ms-azuretools.vscode-docker"
19+
]
20+
}
21+
},
22+
23+
"onCreateCommand": "bash .devcontainer/post-install.sh"
24+
}
25+

.devcontainer/post-install.sh

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/bin/bash
2+
set -x
3+
4+
curl -Lo ./kind https://kind.sigs.k8s.io/dl/latest/kind-linux-amd64
5+
chmod +x ./kind
6+
mv ./kind /usr/local/bin/kind
7+
8+
curl -L -o kubebuilder https://go.kubebuilder.io/dl/latest/linux/amd64
9+
chmod +x kubebuilder
10+
mv kubebuilder /usr/local/bin/
11+
12+
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"
14+
chmod +x kubectl
15+
mv kubectl /usr/local/bin/kubectl
16+
17+
docker network create -d=bridge --subnet=172.19.0.0/24 kind
18+
19+
kind version
20+
kubebuilder version
21+
docker --version
22+
go version
23+
kubectl version --client

.github/workflows/lint.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
name: Lint
2+
3+
on:
4+
push:
5+
pull_request:
6+
7+
jobs:
8+
lint:
9+
name: Run on Ubuntu
10+
runs-on: ubuntu-latest
11+
steps:
12+
- name: Clone the code
13+
uses: actions/checkout@v4
14+
15+
- name: Setup Go
16+
uses: actions/setup-go@v5
17+
with:
18+
go-version-file: go.mod
19+
20+
- name: Run linter
21+
uses: golangci/golangci-lint-action@v8
22+
with:
23+
version: v2.1.0

.github/workflows/test-e2e.yml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
name: E2E Tests
2+
3+
on:
4+
push:
5+
pull_request:
6+
7+
jobs:
8+
test-e2e:
9+
name: Run on Ubuntu
10+
runs-on: ubuntu-latest
11+
steps:
12+
- name: Clone the code
13+
uses: actions/checkout@v4
14+
15+
- name: Setup Go
16+
uses: actions/setup-go@v5
17+
with:
18+
go-version-file: go.mod
19+
20+
- name: Install the latest version of kind
21+
run: |
22+
curl -Lo ./kind https://kind.sigs.k8s.io/dl/latest/kind-linux-amd64
23+
chmod +x ./kind
24+
sudo mv ./kind /usr/local/bin/kind
25+
26+
- name: Verify kind installation
27+
run: kind version
28+
29+
- name: Running Test e2e
30+
run: |
31+
go mod tidy
32+
# make test-e2e

.github/workflows/test.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
name: Tests
2+
3+
on:
4+
push:
5+
pull_request:
6+
7+
jobs:
8+
test:
9+
name: Run on Ubuntu
10+
runs-on: ubuntu-latest
11+
steps:
12+
- name: Clone the code
13+
uses: actions/checkout@v4
14+
15+
- name: Setup Go
16+
uses: actions/setup-go@v5
17+
with:
18+
go-version-file: go.mod
19+
20+
- name: Running Tests
21+
run: |
22+
go mod tidy
23+
make test

.golangci.yml

Lines changed: 36 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,52 @@
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
23-
- errcheck
24-
- exportloopref
9+
# - errcheck
2510
- ginkgolinter
2611
- goconst
27-
- gocyclo
28-
- gofmt
29-
- goimports
30-
- gosimple
12+
# - gocyclo
3113
- govet
3214
- ineffassign
33-
- lll
15+
# - lll
3416
- misspell
3517
- nakedret
36-
- prealloc
18+
# - prealloc
3719
- revive
38-
- staticcheck
39-
- typecheck
20+
# - staticcheck
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: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Build the manager binary
2-
FROM golang:1.22-alpine as builder
2+
FROM golang:1.24-alpine as builder
33
ARG TARGETOS
44
ARG TARGETARCH
55

@@ -14,7 +14,7 @@ RUN apk upgrade --no-cache && \
1414
# Copy the go source
1515
COPY cmd/ cmd/
1616
COPY api/ api/
17-
COPY internal/controller/ internal/controller/
17+
COPY internal/ internal/
1818

1919
# Build
2020
# the GOARCH has not a default value to allow the binary be built according to the host where the command

Makefile

Lines changed: 58 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,9 @@ endif
5252

5353
# Set the Operator SDK version to use. By default, what is installed on the system is used.
5454
# This is useful for CI or a project to utilize a specific version of the operator-sdk toolkit.
55-
OPERATOR_SDK_VERSION ?= v1.38.0
55+
OPERATOR_SDK_VERSION ?= v1.40.0
5656
# Image URL to use all building/pushing image targets
5757
IMG ?= $(IMAGE_TAG_BASE):$(VERSION)
58-
# ENVTEST_K8S_VERSION refers to the version of kubebuilder assets to be downloaded by envtest binary.
59-
ENVTEST_K8S_VERSION = 1.30.0
6058

6159
# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
6260
ifeq (,$(shell go env GOBIN))
@@ -119,13 +117,37 @@ vet: ## Run go vet against code.
119117
go vet ./...
120118

121119
.PHONY: test
122-
test: manifests generate fmt vet envtest ## Run tests.
123-
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path)" go test $$(go list ./... | grep -v /e2e) -coverprofile cover.out
124-
125-
# Utilize Kind or modify the e2e tests to load the image locally, enabling compatibility with other vendors.
126-
.PHONY: test-e2e # Run the e2e tests against a Kind k8s instance that is spun up.
127-
test-e2e:
128-
go test ./test/e2e/ -v -ginkgo.v
120+
test: manifests generate fmt vet setup-envtest ## Run tests.
121+
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) -p path)" go test $(shell go list ./... | grep -v /test/) -coverprofile cover.out
122+
123+
# TODO(user): To use a different vendor for e2e tests, modify the setup under 'tests/e2e'.
124+
# The default setup assumes Kind is pre-installed and builds/loads the Manager Docker image locally.
125+
# CertManager is installed by default; skip with:
126+
# - CERT_MANAGER_INSTALL_SKIP=true
127+
KIND_CLUSTER ?= susql-operator-test-e2e
128+
129+
.PHONY: setup-test-e2e
130+
setup-test-e2e: ## Set up a Kind cluster for e2e tests if it does not exist
131+
@command -v $(KIND) >/dev/null 2>&1 || { \
132+
echo "Kind is not installed. Please install Kind manually."; \
133+
exit 1; \
134+
}
135+
@case "$$($(KIND) get clusters)" in \
136+
*"$(KIND_CLUSTER)"*) \
137+
echo "Kind cluster '$(KIND_CLUSTER)' already exists. Skipping creation." ;; \
138+
*) \
139+
echo "Creating Kind cluster '$(KIND_CLUSTER)'..."; \
140+
$(KIND) create cluster --name $(KIND_CLUSTER) ;; \
141+
esac
142+
143+
.PHONY: test-e2e
144+
test-e2e: setup-test-e2e manifests generate fmt vet ## Run the e2e tests. Expected an isolated environment using Kind.
145+
KIND_CLUSTER=$(KIND_CLUSTER) go test ./test/e2e/ -v -ginkgo.v
146+
$(MAKE) cleanup-test-e2e
147+
148+
.PHONY: cleanup-test-e2e
149+
cleanup-test-e2e: ## Tear down the Kind cluster used for e2e tests
150+
@$(KIND) delete cluster --name $(KIND_CLUSTER)
129151

130152
.PHONY: lint
131153
lint: golangci-lint ## Run golangci-lint linter
@@ -135,6 +157,10 @@ lint: golangci-lint ## Run golangci-lint linter
135157
lint-fix: golangci-lint ## Run golangci-lint linter and perform fixes
136158
$(GOLANGCI_LINT) run --fix
137159

160+
.PHONY: lint-config
161+
lint-config: golangci-lint ## Verify golangci-lint linter configuration
162+
$(GOLANGCI_LINT) config verify
163+
138164
##@ Build
139165

140166
.PHONY: build
@@ -195,10 +221,10 @@ PLATFORMS ?= linux/arm64,linux/amd64,linux/s390x,linux/ppc64le
195221
docker-buildx: ## Build and push docker image for the manager for cross-platform support
196222
# copy existing Dockerfile and insert --platform=${BUILDPLATFORM} into Dockerfile.cross, and preserve the original Dockerfile
197223
sed -e '1 s/\(^FROM\)/FROM --platform=\$$\{BUILDPLATFORM\}/; t' -e ' 1,// s//FROM --platform=\$$\{BUILDPLATFORM\}/' Dockerfile > Dockerfile.cross
198-
- $(CONTAINER_TOOL) buildx create --name project-v3-builder
199-
$(CONTAINER_TOOL) buildx use project-v3-builder
224+
- $(CONTAINER_TOOL) buildx create --name susql-operator-builder
225+
$(CONTAINER_TOOL) buildx use susql-operator-builder
200226
- $(CONTAINER_TOOL) buildx build --push --platform=$(PLATFORMS) --tag ${IMG} -f Dockerfile.cross .
201-
- $(CONTAINER_TOOL) buildx rm project-v3-builder
227+
- $(CONTAINER_TOOL) buildx rm susql-operator-builder
202228
rm Dockerfile.cross
203229

204230
.PHONY: build-installer
@@ -239,16 +265,19 @@ $(LOCALBIN):
239265

240266
## Tool Binaries
241267
KUBECTL ?= kubectl
268+
KIND ?= kind
242269
KUSTOMIZE ?= $(LOCALBIN)/kustomize
243270
CONTROLLER_GEN ?= $(LOCALBIN)/controller-gen
244271
ENVTEST ?= $(LOCALBIN)/setup-envtest
245272
GOLANGCI_LINT = $(LOCALBIN)/golangci-lint
246273

247274
## Tool Versions
248-
KUSTOMIZE_VERSION ?= v5.4.2
249-
CONTROLLER_TOOLS_VERSION ?= v0.15.0
250-
ENVTEST_VERSION ?= release-0.18
251-
GOLANGCI_LINT_VERSION ?= v1.59.1
275+
KUSTOMIZE_VERSION ?= v5.6.0
276+
CONTROLLER_TOOLS_VERSION ?= v0.18.0
277+
ENVTEST_VERSION ?= $(shell go list -m -f "{{ .Version }}" sigs.k8s.io/controller-runtime | awk -F'[v.]' '{printf "release-%d.%d", $$2, $$3}')
278+
#ENVTEST_K8S_VERSION refers to the version of kubebuilder assets to be downloaded by envtest binary.
279+
ENVTEST_K8S_VERSION ?= $(shell go list -m -f "{{ .Version }}" k8s.io/api | awk -F'[v.]' '{printf "1.%d", $$3}')
280+
GOLANGCI_LINT_VERSION ?= v2.1.0
252281

253282
.PHONY: kustomize
254283
kustomize: $(KUSTOMIZE) ## Download kustomize locally if necessary.
@@ -260,6 +289,14 @@ controller-gen: $(CONTROLLER_GEN) ## Download controller-gen locally if necessar
260289
$(CONTROLLER_GEN): $(LOCALBIN)
261290
$(call go-install-tool,$(CONTROLLER_GEN),sigs.k8s.io/controller-tools/cmd/controller-gen,$(CONTROLLER_TOOLS_VERSION))
262291

292+
.PHONY: setup-envtest
293+
setup-envtest: envtest ## Download the binaries required for ENVTEST in the local bin directory.
294+
@echo "Setting up envtest binaries for Kubernetes version $(ENVTEST_K8S_VERSION)..."
295+
@$(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path || { \
296+
echo "Error: Failed to set up envtest binaries for version $(ENVTEST_K8S_VERSION)."; \
297+
exit 1; \
298+
}
299+
263300
.PHONY: envtest
264301
envtest: $(ENVTEST) ## Download setup-envtest locally if necessary.
265302
$(ENVTEST): $(LOCALBIN)
@@ -268,10 +305,10 @@ $(ENVTEST): $(LOCALBIN)
268305
.PHONY: golangci-lint
269306
golangci-lint: $(GOLANGCI_LINT) ## Download golangci-lint locally if necessary.
270307
$(GOLANGCI_LINT): $(LOCALBIN)
271-
$(call go-install-tool,$(GOLANGCI_LINT),github.com/golangci/golangci-lint/cmd/golangci-lint,$(GOLANGCI_LINT_VERSION))
308+
$(call go-install-tool,$(GOLANGCI_LINT),github.com/golangci/golangci-lint/v2/cmd/golangci-lint,$(GOLANGCI_LINT_VERSION))
272309

273310
# go-install-tool will 'go install' any package with custom target and name of binary, if it doesn't exist
274-
# $1 - target path with name of binary (ideally with version)
311+
# $1 - target path with name of binary
275312
# $2 - package url which can be installed
276313
# $3 - specific version of package
277314
define go-install-tool
@@ -322,6 +359,7 @@ bundle-push: ## Push the bundle image.
322359
$(call docker_push,$(BUNDLE_IMG))
323360

324361
.PHONY: opm
362+
opmVersion = "v1.55.0"
325363
OPM = $(LOCALBIN)/opm
326364
opm: ## Download opm locally if necessary.
327365
ifeq (,$(wildcard $(OPM)))
@@ -330,7 +368,7 @@ ifeq (,$(shell which opm 2>/dev/null))
330368
set -e ;\
331369
mkdir -p $(dir $(OPM)) ;\
332370
OS=$(GOOS) && ARCH=$(GOARCH) && \
333-
curl -sSLo $(OPM) https://github.com/operator-framework/operator-registry/releases/download/v1.23.0/$${OS}-$${ARCH}-opm ;\
371+
curl -sSLo $(OPM) https://github.com/operator-framework/operator-registry/releases/download/${opmVersion}/$${OS}-$${ARCH}-opm ;\
334372
chmod +x $(OPM) ;\
335373
}
336374
else

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.0.33
1+
0.0.34

bundle.Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ LABEL operators.operatorframework.io.bundle.manifests.v1=manifests/
66
LABEL operators.operatorframework.io.bundle.metadata.v1=metadata/
77
LABEL operators.operatorframework.io.bundle.package.v1=susql-operator
88
LABEL operators.operatorframework.io.bundle.channels.v1=alpha
9-
LABEL operators.operatorframework.io.metrics.builder=operator-sdk-v1.39.1
9+
LABEL operators.operatorframework.io.metrics.builder=operator-sdk-v1.41.0
1010
LABEL operators.operatorframework.io.metrics.mediatype.v1=metrics+v1
1111
LABEL operators.operatorframework.io.metrics.project_layout=go.kubebuilder.io/v4
1212

0 commit comments

Comments
 (0)