Skip to content

Commit cae1ab7

Browse files
authored
Switch to using local golang ci lint and cleanup Makefile (#176)
Managing the Golang CI Lint version is a bit cumbersome when it is hard coded in the Makefile. This switches to using the local version. In the end the version specified in the GH actions flow with be the authority.
1 parent 37d48b5 commit cae1ab7

1 file changed

Lines changed: 27 additions & 44 deletions

File tree

Makefile

Lines changed: 27 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -18,29 +18,23 @@ all: build
1818

1919
##@ Development
2020

21+
## Generate WebhookConfiguration, ClusterRole and CustomResourceDefinition objects.
2122
.PHONY: manifests
22-
manifests: ## Generate WebhookConfiguration, ClusterRole and CustomResourceDefinition objects.
23+
manifests:
2324
go tool controller-gen crd paths="./..." output:crd:artifacts:config=helm/kubernetes-operator/crds
2425
go tool crd-ref-docs --log-level error --output-path docs/api-reference.md --renderer markdown --source-path api/v1alpha1 --config docs/.crd-ref-docs.yaml
2526

27+
## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations.
2628
.PHONY: generate
27-
generate: ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations.
29+
generate:
2830
go tool controller-gen applyconfiguration:headerFile="hack/boilerplate.go.txt" object:headerFile="hack/boilerplate.go.txt" paths="./..."
2931

30-
.PHONY: fmt
31-
fmt: ## Run go fmt against code.
32-
go fmt ./...
33-
34-
.PHONY: vet
35-
vet: ## Run go vet against code.
36-
go vet ./...
37-
3832
.PHONY: test
39-
test: manifests fmt vet setup-envtest ## Run tests.
33+
test: manifests setup-envtest
4034
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path)" go test -v $$(go list ./... | grep -v /e2e) -coverprofile cover.out
4135

4236
.PHONY: test-e2e
43-
test-e2e: manifests fmt vet ## Run the e2e tests. Expected an isolated environment using Kind.
37+
test-e2e: manifests
4438
@command -v kind >/dev/null 2>&1 || { \
4539
echo "Kind is not installed. Please install Kind manually."; \
4640
exit 1; \
@@ -52,57 +46,54 @@ test-e2e: manifests fmt vet ## Run the e2e tests. Expected an isolated environme
5246
go test ./test/e2e/ -v -ginkgo.v
5347

5448
.PHONY: lint
55-
lint: golangci-lint ## Run golangci-lint linter
56-
$(GOLANGCI_LINT) run
57-
58-
.PHONY: lint-fix
59-
lint-fix: golangci-lint ## Run golangci-lint linter and perform fixes
60-
$(GOLANGCI_LINT) run --fix
61-
62-
.PHONY: lint-config
63-
lint-config: golangci-lint ## Verify golangci-lint linter configuration
64-
$(GOLANGCI_LINT) config verify
49+
lint:
50+
@golangci-lint run ./...
6551

6652
##@ Build
6753

6854
.PHONY: build
69-
build: manifests fmt vet ## Build manager binary.
55+
build: manifests
7056
go build -o bin/manager cmd/main.go
7157

7258
.PHONY: run
73-
run: manifests fmt vet ## Run a controller from your host.
59+
run: manifests
7460
go run ./cmd/main.go
7561

7662
.PHONY: docker-build
77-
docker-build: ## Build docker image with the manager.
63+
docker-build:
7864
docker build -t ${IMG} .
7965

66+
## Generate a consolidated YAML with CRDs and deployment.
8067
.PHONY: build-installer
81-
build-installer: manifests ## Generate a consolidated YAML with CRDs and deployment.
68+
build-installer: manifests
8269
mkdir -p manifests
83-
$(HELM) template --include-crds kubernetes-operator helm/kubernetes-operator > manifests/install.yaml
70+
helm template --include-crds kubernetes-operator helm/kubernetes-operator > manifests/install.yaml
8471

8572
##@ Deployment
8673

8774
ifndef ignore-not-found
8875
ignore-not-found = false
8976
endif
9077

78+
## Install CRDs into the K8s cluster specified in ~/.kube/config.
9179
.PHONY: install
92-
install: manifests ## Install CRDs into the K8s cluster specified in ~/.kube/config.
93-
$(KUBECTL) apply --server-side -f helm/kubernetes-operator/crds
80+
install: manifests
81+
kubectl apply --server-side -f helm/kubernetes-operator/crds
9482

83+
## Uninstall CRDs from the K8s cluster specified in ~/.kube/config. Call with ignore-not-found=true to ignore resource not found errors during deletion.
9584
.PHONY: uninstall
96-
uninstall: manifests ## Uninstall CRDs from the K8s cluster specified in ~/.kube/config. Call with ignore-not-found=true to ignore resource not found errors during deletion.
97-
$(KUBECTL) delete -f helm/kubernetes-operator/crds
85+
uninstall: manifests
86+
kubectl delete -f helm/kubernetes-operator/crds
9887

88+
## Deploy controller to the K8s cluster specified in ~/.kube/config.
9989
.PHONY: deploy
100-
deploy: manifests ## Deploy controller to the K8s cluster specified in ~/.kube/config.
101-
$(HELM) install -n netbird --create-namespace kubernetes-operator --set operator.image.tag=$(word 2,$(subst :, ,${IMG})) helm/kubernetes-operator
90+
deploy: manifests
91+
helm install -n netbird --create-namespace kubernetes-operator --set operator.image.tag=$(word 2,$(subst :, ,${IMG})) helm/kubernetes-operator
10292

93+
## Undeploy controller from the K8s cluster specified in ~/.kube/config. Call with ignore-not-found=true to ignore resource not found errors during deletion.
10394
.PHONY: undeploy
104-
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.
105-
$(HELM) uninstall -n netbird kubernetes-operator
95+
undeploy:
96+
helm uninstall -n netbird kubernetes-operator
10697

10798
##@ Dependencies
10899

@@ -112,16 +103,12 @@ $(LOCALBIN):
112103
mkdir -p $(LOCALBIN)
113104

114105
## Tool Binaries
115-
KUBECTL ?= kubectl
116106
ENVTEST ?= $(LOCALBIN)/setup-envtest
117-
GOLANGCI_LINT = $(LOCALBIN)/golangci-lint
118-
HELM ?= helm
119107

120108
#ENVTEST_VERSION is the version of controller-runtime release branch to fetch the envtest setup script (i.e. release-0.20)
121109
ENVTEST_VERSION ?= $(shell go list -m -f "{{ .Version }}" sigs.k8s.io/controller-runtime | awk -F'[v.]' '{printf "release-%d.%d", $$2, $$3}')
122110
#ENVTEST_K8S_VERSION is the version of Kubernetes to use for setting up ENVTEST binaries (i.e. 1.31)
123111
ENVTEST_K8S_VERSION ?= $(shell go list -m -f "{{ .Version }}" k8s.io/api | awk -F'[v.]' '{printf "1.%d", $$3}')
124-
GOLANGCI_LINT_VERSION ?= v1.63.4
125112

126113
.PHONY: setup-envtest
127114
setup-envtest: envtest ## Download the binaries required for ENVTEST in the local bin directory.
@@ -132,15 +119,11 @@ setup-envtest: envtest ## Download the binaries required for ENVTEST in the loca
132119
}
133120

134121
.PHONY: envtest
122+
135123
envtest: $(ENVTEST) ## Download setup-envtest locally if necessary.
136124
$(ENVTEST): $(LOCALBIN)
137125
$(call go-install-tool,$(ENVTEST),sigs.k8s.io/controller-runtime/tools/setup-envtest,$(ENVTEST_VERSION))
138126

139-
.PHONY: golangci-lint
140-
golangci-lint: $(GOLANGCI_LINT) ## Download golangci-lint locally if necessary.
141-
$(GOLANGCI_LINT): $(LOCALBIN)
142-
$(call go-install-tool,$(GOLANGCI_LINT),github.com/golangci/golangci-lint/cmd/golangci-lint,$(GOLANGCI_LINT_VERSION))
143-
144127
# go-install-tool will 'go install' any package with custom target and name of binary, if it doesn't exist
145128
# $1 - target path with name of binary
146129
# $2 - package url which can be installed

0 commit comments

Comments
 (0)