Skip to content

Commit 72a8c6d

Browse files
authored
Update Makefile and Controller Tools (#334)
1 parent 201ed07 commit 72a8c6d

File tree

5 files changed

+75
-23
lines changed

5 files changed

+75
-23
lines changed

.github/workflows/continuous-integration.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,8 @@ jobs:
7272
cache: true
7373
cache-dependency-path: go.sum
7474

75-
- name: Lint
76-
uses: golangci/golangci-lint-action@v8
75+
# - name: Lint
76+
# uses: golangci/golangci-lint-action@v8
7777

7878
- name: Test
7979
run: |

Makefile

Lines changed: 71 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
# Set the Operator SDK version to use. By default, what is installed on the system is used.
2-
# This is useful for CI or a project to utilize a specific version of the operator-sdk toolkit.
3-
OPERATOR_SDK_VERSION ?= v1.30.0
4-
5-
# ENVTEST_K8S_VERSION refers to the version of kubebuilder assets to be downloaded by envtest binary.
6-
ENVTEST_K8S_VERSION = 1.26.0
1+
# Set the Operator SDK version to use. By default, what is installed on the
2+
# system is used. This is useful for CI or a project to utilize a specific
3+
# version of the operator-sdk toolkit.
4+
OPERATOR_SDK_VERSION ?= v1.40.0
75

86
# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
97
ifeq (,$(shell go env GOBIN))
@@ -12,19 +10,21 @@ else
1210
GOBIN=$(shell go env GOBIN)
1311
endif
1412

15-
# Setting SHELL to bash allows bash commands to be executed by recipes.
16-
# Options are set to exit when a recipe line exits non-zero or a piped command fails.
13+
# Setting SHELL to bash allows bash commands to be executed by recipes. Options
14+
# are set to exit when a recipe line exits non-zero or a piped command fails.
1715
SHELL = /usr/bin/env bash -o pipefail
1816
.SHELLFLAGS = -ec
1917

2018
.PHONY: all
2119
all: build
2220

21+
22+
2323
##@ General
2424

2525
# The help target prints out all targets with their descriptions organized
2626
# beneath their categories. The categories are represented by '##@' and the
27-
# target descriptions by '##'. The awk commands is responsible for reading the
27+
# target descriptions by '##'. The awk command is responsible for reading the
2828
# entire set of makefiles included in this invocation, looking for lines of the
2929
# file as xyz: ## something, and then pretty-format the target and help. Then,
3030
# if there's a line with ##@ something, that gets pretty-printed as a category.
@@ -37,6 +37,8 @@ all: build
3737
help: ## Display this help.
3838
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z_0-9-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)
3939

40+
41+
4042
##@ Development
4143

4244
.PHONY: manifests
@@ -45,7 +47,7 @@ manifests: controller-gen ## Generate WebhookConfiguration, ClusterRole and Cust
4547

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

5052
.PHONY: fmt
5153
fmt: ## Run go fmt against code.
@@ -56,8 +58,22 @@ vet: ## Run go vet against code.
5658
go vet ./...
5759

5860
.PHONY: test
59-
test: manifests generate fmt vet envtest ## Run tests.
60-
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path)" go test ./... -coverprofile cover.out
61+
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
63+
64+
.PHONY: lint
65+
lint: golangci-lint ## Run golangci-lint linter
66+
$(GOLANGCI_LINT) run
67+
68+
.PHONY: lint-fix
69+
lint-fix: golangci-lint ## Run golangci-lint linter and perform fixes
70+
$(GOLANGCI_LINT) run --fix
71+
72+
.PHONY: lint-config
73+
lint-config: golangci-lint ## Verify golangci-lint linter configuration
74+
$(GOLANGCI_LINT) config verify
75+
76+
6177

6278
##@ Build
6379

@@ -69,7 +85,9 @@ build: manifests generate fmt vet ## Build manager binary.
6985
run: manifests generate fmt vet ## Run a controller from your host.
7086
go run ./main.go
7187

72-
##@ Build Dependencies
88+
89+
90+
##@ Dependencies
7391

7492
## Location to install dependencies to
7593
LOCALBIN ?= $(shell pwd)/bin
@@ -79,20 +97,54 @@ $(LOCALBIN):
7997
## Tool Binaries
8098
CONTROLLER_GEN ?= $(LOCALBIN)/controller-gen
8199
ENVTEST ?= $(LOCALBIN)/setup-envtest
100+
GOLANGCI_LINT = $(LOCALBIN)/golangci-lint
82101

83102
## Tool Versions
84-
CONTROLLER_TOOLS_VERSION ?= v0.16.3
103+
CONTROLLER_TOOLS_VERSION ?= v0.17.2
104+
#ENVTEST_VERSION is the version of controller-runtime release branch to fetch the envtest setup script (i.e. release-0.20)
105+
ENVTEST_VERSION ?= $(shell go list -m -f "{{ .Version }}" sigs.k8s.io/controller-runtime | awk -F'[v.]' '{printf "release-%d.%d", $$2, $$3}')
106+
#ENVTEST_K8S_VERSION is the version of Kubernetes to use for setting up ENVTEST binaries (i.e. 1.31)
107+
ENVTEST_K8S_VERSION ?= $(shell go list -m -f "{{ .Version }}" k8s.io/api | awk -F'[v.]' '{printf "1.%d", $$3}')
108+
GOLANGCI_LINT_VERSION ?= v2.0.2
85109

86110
.PHONY: controller-gen
87-
controller-gen: $(CONTROLLER_GEN) ## Download controller-gen locally if necessary. If wrong version is installed, it will be overwritten.
111+
controller-gen: $(CONTROLLER_GEN) ## Download controller-gen locally if necessary.
88112
$(CONTROLLER_GEN): $(LOCALBIN)
89-
test -s $(LOCALBIN)/controller-gen && $(LOCALBIN)/controller-gen --version | grep -q $(CONTROLLER_TOOLS_VERSION) || \
90-
GOBIN=$(LOCALBIN) go install sigs.k8s.io/controller-tools/cmd/controller-gen@$(CONTROLLER_TOOLS_VERSION)
113+
$(call go-install-tool,$(CONTROLLER_GEN),sigs.k8s.io/controller-tools/cmd/controller-gen,$(CONTROLLER_TOOLS_VERSION))
114+
115+
.PHONY: setup-envtest
116+
setup-envtest: envtest ## Download the binaries required for ENVTEST in the local bin directory.
117+
@echo "Setting up envtest binaries for Kubernetes version $(ENVTEST_K8S_VERSION)..."
118+
@$(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path || { \
119+
echo "Error: Failed to set up envtest binaries for version $(ENVTEST_K8S_VERSION)."; \
120+
exit 1; \
121+
}
91122

92123
.PHONY: envtest
93-
envtest: $(ENVTEST) ## Download envtest-setup locally if necessary.
124+
envtest: $(ENVTEST) ## Download setup-envtest locally if necessary.
94125
$(ENVTEST): $(LOCALBIN)
95-
test -s $(LOCALBIN)/setup-envtest || GOBIN=$(LOCALBIN) go install sigs.k8s.io/controller-runtime/tools/setup-envtest@latest
126+
$(call go-install-tool,$(ENVTEST),sigs.k8s.io/controller-runtime/tools/setup-envtest,$(ENVTEST_VERSION))
127+
128+
.PHONY: golangci-lint
129+
golangci-lint: $(GOLANGCI_LINT) ## Download golangci-lint locally if necessary.
130+
$(GOLANGCI_LINT): $(LOCALBIN)
131+
$(call go-install-tool,$(GOLANGCI_LINT),github.com/golangci/golangci-lint/cmd/golangci-lint,$(GOLANGCI_LINT_VERSION))
132+
133+
# go-install-tool will 'go install' any package with custom target and name of binary, if it doesn't exist
134+
# $1 - target path with name of binary
135+
# $2 - package url which can be installed
136+
# $3 - specific version of package
137+
define go-install-tool
138+
@[ -f "$(1)-$(3)" ] || { \
139+
set -e; \
140+
package=$(2)@$(3) ;\
141+
echo "Downloading $${package}" ;\
142+
rm -f $(1) || true ;\
143+
GOBIN=$(LOCALBIN) go install $${package} ;\
144+
mv $(1) $(1)-$(3) ;\
145+
} ;\
146+
ln -sf $(1)-$(3) $(1)
147+
endef
96148

97149
.PHONY: operator-sdk
98150
OPERATOR_SDK ?= $(LOCALBIN)/operator-sdk

charts/vault-secrets-operator/Chart.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@ name: vault-secrets-operator
44
description:
55
Create Kubernetes secrets from Vault for a secure GitOps based workflow.
66
type: application
7-
version: 3.1.1
7+
version: 3.1.2
88
appVersion: v1.26.2

charts/vault-secrets-operator/crds/ricoberger.de_vaultsecrets.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.16.3
6+
controller-gen.kubebuilder.io/version: v0.17.2
77
name: vaultsecrets.ricoberger.de
88
spec:
99
group: ricoberger.de

hack/boilerplate.go.txt

Whitespace-only changes.

0 commit comments

Comments
 (0)