Skip to content

Commit c0646f1

Browse files
authored
Cleanup Makefile, tests and CI (#50)
* cleanup wip * add pr trigger * happy lint * cleanup tests
1 parent 58b88b3 commit c0646f1

File tree

14 files changed

+180
-77
lines changed

14 files changed

+180
-77
lines changed

.github/workflows/build.yaml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
name: Build
2+
on:
3+
push:
4+
pull_request:
5+
6+
permissions:
7+
contents: read
8+
9+
jobs:
10+
build:
11+
runs-on: ubuntu-latest
12+
13+
steps:
14+
- uses: actions/checkout@v4
15+
16+
- uses: actions/setup-go@v5
17+
with:
18+
go-version-file: 'go.mod'
19+
cache: false
20+
21+
- name: Build
22+
run: make

.github/workflows/lint.yaml renamed to .github/workflows/test.yaml

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Lint
1+
name: CI
22
on:
33
push:
44
pull_request:
@@ -8,8 +8,8 @@ permissions:
88

99
jobs:
1010
lint:
11-
name: lint
1211
runs-on: ubuntu-latest
12+
1313
steps:
1414
- uses: actions/checkout@v4
1515

@@ -23,3 +23,17 @@ jobs:
2323
with:
2424
version: v2.3
2525
args: '--timeout=10m'
26+
27+
test:
28+
runs-on: ubuntu-latest
29+
30+
steps:
31+
- uses: actions/checkout@v4
32+
33+
- uses: actions/setup-go@v5
34+
with:
35+
go-version-file: 'go.mod'
36+
cache: false
37+
38+
- name: Tests
39+
run: make test

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,6 @@ go.work
2727
*.swo
2828
*~
2929
.tiltbuild
30+
.envtest
3031

3132
out/

.golangci.yml

Lines changed: 18 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -4,54 +4,28 @@ run:
44
allow-parallel-runners: true
55

66
linters:
7-
default: none
87
enable:
98
- bodyclose
109
- dupl
11-
- errcheck
1210
- errname
1311
- exhaustive
1412
- goconst
1513
- gocritic
1614
- goprintffuncname
1715
- gosec
18-
- govet
19-
- ineffassign
2016
- misspell
2117
- nakedret
2218
- nilerr
2319
- noctx
2420
- prealloc
2521
- rowserrcheck
2622
- sqlclosecheck
27-
- staticcheck
2823
- unconvert
2924
- unparam
30-
- unused
3125
- wastedassign
3226
- whitespace
33-
settings:
34-
goconst:
35-
min-len: 2
36-
min-occurrences: 2
37-
gocritic:
38-
enabled-tags:
39-
- diagnostic
40-
- experimental
41-
- opinionated
42-
- performance
43-
- style
44-
gocyclo:
45-
min-complexity: 10
46-
misspell:
47-
locale: US
27+
# - wsl_v5
4828
exclusions:
49-
generated: lax
50-
presets:
51-
- comments
52-
- common-false-positives
53-
- legacy
54-
- std-error-handling
5529
rules:
5630
- linters:
5731
- gochecknoglobals
@@ -62,18 +36,24 @@ linters:
6236
- staticcheck
6337
- unparam
6438
path: _test\.go
65-
paths:
66-
- third_party$
67-
- builtin$
68-
- examples$
6939

7040
formatters:
7141
enable:
42+
- gci
7243
- gofmt
73-
- goimports
74-
exclusions:
75-
generated: lax
76-
paths:
77-
- third_party$
78-
- builtin$
79-
- examples$
44+
- gofumpt
45+
settings:
46+
gci:
47+
# The default order is `standard > default > custom > blank > dot > alias > localmodule`.
48+
custom-order: true
49+
sections:
50+
- standard
51+
- default
52+
- alias
53+
- localmodule
54+
- dot
55+
- blank
56+
gofmt:
57+
rewrite-rules:
58+
- pattern: 'interface{}'
59+
replacement: 'any'

Makefile

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -58,20 +58,11 @@ generate: controller-gen ## Generate code containing DeepCopy, DeepCopyInto, and
5858

5959
.PHONY: fmt
6060
fmt: ## Run go fmt against code.
61-
go fmt ./...
62-
63-
.PHONY: vet
64-
vet: ## Run go vet against code.
65-
go vet ./...
61+
$(GOLANGCI_LINT) fmt ./...
6662

6763
.PHONY: test
68-
test: manifests generate fmt vet envtest ## Run tests.
69-
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path)" go test $$(go list ./... | grep -v /e2e) -coverprofile cover.out
70-
71-
# Utilize Kind or modify the e2e tests to load the image locally, enabling compatibility with other vendors.
72-
.PHONY: test-e2e # Run the e2e tests against a Kind k8s instance that is spun up.
73-
test-e2e:
74-
go test ./test/e2e/ -v -ginkgo.v
64+
test: manifests generate ## Run tests.
65+
go test -v -coverprofile cover.out $$(go list ./... | grep -v /e2e)
7566

7667
.PHONY: lint
7768
lint: ## Run golangci-lint linter & yamllint
@@ -84,11 +75,11 @@ lint-fix: ## Run golangci-lint linter and perform fixes
8475
##@ Build
8576

8677
.PHONY: build
87-
build: manifests generate fmt vet ## Build manager binary.
78+
build: manifests generate ## Build manager binary.
8879
go build -o bin/manager cmd/main.go
8980

9081
.PHONY: run
91-
run: manifests generate fmt vet ## Run a controller from your host.
82+
run: manifests generate ## Run a controller from your host.
9283
go run ./cmd/main.go
9384

9485
# If you wish to build the manager image targeting other platforms you can use the --platform flag.
@@ -186,25 +177,25 @@ $(LOCALBIN):
186177
GOLANGCI_LINT_VERSION ?= v2.3.0
187178
KUSTOMIZE_VERSION ?= v5.3.0
188179
CONTROLLER_TOOLS_VERSION ?= v0.14.0
189-
ENVTEST_VERSION ?= latest
180+
ENVTEST_VERSION ?= v0.0.0-20250505003155-b6c5897febe5
181+
ENVTEST_K8S_VERSION := 1.31.0
190182

191183
KUBECTL ?= kubectl
192184
GOLANGCI_LINT ?= go run github.com/golangci/golangci-lint/v2/cmd/golangci-lint@$(GOLANGCI_LINT_VERSION)
193185
KUSTOMIZE ?= go run sigs.k8s.io/kustomize/kustomize/v5@$(KUSTOMIZE_VERSION)
194186

187+
ENVTEST ?= go run sigs.k8s.io/controller-runtime/tools/setup-envtest@$(ENVTEST_VERSION)
188+
ENVTEST_DIR ?= $(shell pwd)/.envtest
189+
export KUBEBUILDER_ASSETS ?= $(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(ENVTEST_DIR) -p path)
190+
195191
## Tool Binaries
196192
CONTROLLER_GEN ?= $(LOCALBIN)/controller-gen-$(CONTROLLER_TOOLS_VERSION)
197-
ENVTEST ?= $(LOCALBIN)/setup-envtest-$(ENVTEST_VERSION)
198193

199194
.PHONY: controller-gen
200195
controller-gen: $(CONTROLLER_GEN) ## Download controller-gen locally if necessary.
201196
$(CONTROLLER_GEN): $(LOCALBIN)
202197
$(call go-install-tool,$(CONTROLLER_GEN),sigs.k8s.io/controller-tools/cmd/controller-gen,$(CONTROLLER_TOOLS_VERSION))
203198

204-
.PHONY: envtest
205-
envtest: $(ENVTEST) ## Download setup-envtest locally if necessary.
206-
$(ENVTEST): $(LOCALBIN)
207-
$(call go-install-tool,$(ENVTEST),sigs.k8s.io/controller-runtime/tools/setup-envtest,$(ENVTEST_VERSION))
208199

209200
# go-install-tool will 'go install' any package with custom target and name of binary, if it doesn't exist
210201
# $1 - target path with name of binary (ideally with version)

cmd/main.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,29 +25,29 @@ import (
2525

2626
"github.com/go-logr/stdr"
2727
"k8s.io/apimachinery/pkg/runtime"
28-
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
2928
"k8s.io/client-go/discovery/cached/memory"
3029
"k8s.io/client-go/kubernetes"
31-
clientgoscheme "k8s.io/client-go/kubernetes/scheme"
3230
"k8s.io/client-go/tools/clientcmd"
31+
"sigs.k8s.io/controller-runtime/pkg/healthz"
3332
"sigs.k8s.io/controller-runtime/pkg/manager"
33+
"sigs.k8s.io/controller-runtime/pkg/webhook"
3434

3535
upstream "github.com/rancher/k3k/pkg/apis/k3k.io/v1alpha1"
36-
// Import all Kubernetes client auth plugins (e.g. Azure, GCP, OIDC, etc.)
37-
// to ensure that exec-entrypoint and run can make use of them.
38-
_ "k8s.io/client-go/plugin/pkg/client/auth"
36+
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
37+
clientgoscheme "k8s.io/client-go/kubernetes/scheme"
3938
clusterv1beta1 "sigs.k8s.io/cluster-api/api/v1beta1"
4039
ctrl "sigs.k8s.io/controller-runtime"
41-
"sigs.k8s.io/controller-runtime/pkg/healthz"
4240
metricsserver "sigs.k8s.io/controller-runtime/pkg/metrics/server"
43-
"sigs.k8s.io/controller-runtime/pkg/webhook"
4441

4542
controlplanev1alpha1 "github.com/rancher/cluster-api-provider-k3k/api/controlplane/v1alpha1"
4643
infrastructurev1alpha1 "github.com/rancher/cluster-api-provider-k3k/api/infrastructure/v1alpha1"
4744
controlplanecontroller "github.com/rancher/cluster-api-provider-k3k/internal/controller/controlplane"
4845
infrastructurecontroller "github.com/rancher/cluster-api-provider-k3k/internal/controller/infrastructure"
4946
"github.com/rancher/cluster-api-provider-k3k/internal/helm"
50-
//+kubebuilder:scaffold:imports
47+
48+
// Import all Kubernetes client auth plugins (e.g. Azure, GCP, OIDC, etc.)
49+
// to ensure that exec-entrypoint and run can make use of them.
50+
_ "k8s.io/client-go/plugin/pkg/client/auth"
5151
)
5252

5353
var (
File renamed without changes.
File renamed without changes.
File renamed without changes.

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ go 1.24.2
55
require (
66
github.com/go-logr/logr v1.4.3
77
github.com/go-logr/stdr v1.2.2
8+
github.com/onsi/gomega v1.36.0
89
github.com/rancher/k3k v0.3.3
910
helm.sh/helm/v3 v3.15.3
1011
k8s.io/api v0.31.4

0 commit comments

Comments
 (0)