Skip to content

Commit fe809b7

Browse files
authored
ci: update golangci-lint, pre-commit, use global makelib (#91)
## Issue <!-- Link to the github issue this PR address, ie: #123 --> ## Description <!-- Description of the changes made --> --------- Signed-off-by: Tyler Gillson <[email protected]>
1 parent fa9da68 commit fe809b7

File tree

8 files changed

+67
-250
lines changed

8 files changed

+67
-250
lines changed

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[submodule "build"]
2+
path = build
3+
url = https://github.com/validator-labs/workflows

.golangci.yml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
run:
2+
timeout: 5m
3+
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+
exclude-files:
10+
- ".*_test\\.go"
11+
12+
linters:
13+
disable-all: true
14+
enable:
15+
- dupl
16+
- errcheck
17+
- exportloopref
18+
- ginkgolinter
19+
- goconst
20+
- gocyclo
21+
- gofmt
22+
- goimports
23+
- gosimple
24+
- govet
25+
- ineffassign
26+
- misspell
27+
- nakedret
28+
- prealloc
29+
- staticcheck
30+
- typecheck
31+
- unconvert
32+
- unparam
33+
- unused

.pre-commit-config.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,12 @@ repos:
88
hooks:
99
- id: conventional-pre-commit
1010
stages: [commit-msg]
11+
- repo: https://github.com/golangci/golangci-lint
12+
rev: v1.59.1
13+
hooks:
14+
- id: golangci-lint
15+
entry: golangci-lint run --new-from-rev HEAD --whole-files
16+
types: [go]
17+
language: golang
18+
require_serial: true
19+
pass_filenames: false

Makefile

Lines changed: 7 additions & 213 deletions
Original file line numberDiff line numberDiff line change
@@ -1,218 +1,12 @@
1-
ifneq (,$(wildcard ./.env))
2-
include .env
3-
export
4-
endif
51

2+
# -include will silently skip missing files, which allows us
3+
# to load those files with a target in the Makefile. If only
4+
# "include" was used, the make command would fail and refuse
5+
# to run a target until the include commands succeeded.
6+
-include build/makelib/common.mk
67

7-
PLUGIN_NAME := maas
88
# Image URL to use all building/pushing image targets
99
IMG ?= quay.io/validator-labs/validator-plugin-maas:latest
1010

11-
GOARCH ?= $(shell go env GOARCH)
12-
13-
# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
14-
ifeq (,$(shell go env GOBIN))
15-
GOBIN=$(shell go env GOPATH)/bin
16-
else
17-
GOBIN=$(shell go env GOBIN)
18-
endif
19-
20-
# CONTAINER_TOOL defines the container tool to be used for building images.
21-
# Be aware that the target commands are only tested with Docker which is
22-
# scaffolded by default. However, you might want to replace it to use other
23-
# tools. (i.e. podman)
24-
CONTAINER_TOOL ?= docker
25-
26-
# Setting SHELL to bash allows bash commands to be executed by recipes.
27-
# Options are set to exit when a recipe line exits non-zero or a piped command fails.
28-
SHELL = /usr/bin/env bash -o pipefail
29-
.SHELLFLAGS = -ec
30-
31-
.PHONY: all
32-
all: build
33-
34-
##@ General
35-
36-
# The help target prints out all targets with their descriptions organized
37-
# beneath their categories. The categories are represented by '##@' and the
38-
# target descriptions by '##'. The awk commands is responsible for reading the
39-
# entire set of makefiles included in this invocation, looking for lines of the
40-
# file as xyz: ## something, and then pretty-format the target and help. Then,
41-
# if there's a line with ##@ something, that gets pretty-printed as a category.
42-
# More info on the usage of ANSI control characters for terminal formatting:
43-
# https://en.wikipedia.org/wiki/ANSI_escape_code#SGR_parameters
44-
# More info on the awk command:
45-
# http://linuxcommand.org/lc3_adv_awk.php
46-
47-
.PHONY: help
48-
help: ## Display this help.
49-
@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)
50-
51-
##@ Development
52-
53-
.PHONY: manifests
54-
manifests: controller-gen ## Generate WebhookConfiguration, ClusterRole and CustomResourceDefinition objects.
55-
$(CONTROLLER_GEN) rbac:roleName=manager-role crd webhook paths="./..." output:crd:artifacts:config=config/crd/bases
56-
@cp -v config/crd/bases/validation.spectrocloud.labs_$(PLUGIN_NAME)validators.yaml chart/validator-plugin-$(PLUGIN_NAME)/crds/$(PLUGIN_NAME)validator-crd.yaml
57-
58-
.PHONY: generate
59-
generate: controller-gen ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations.
60-
$(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./..."
61-
62-
.PHONY: fmt
63-
fmt: ## Run go fmt against code.
64-
go fmt ./...
65-
66-
.PHONY: vet
67-
vet: ## Run go vet against code.
68-
go vet ./...
69-
70-
.PHONY: test
71-
test: ENVTEST_K8S_VERSION = 1.27.1
72-
test: manifests generate fmt vet envtest setup-validator ## Run tests.
73-
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path)" go test ./... -coverprofile cover.out
74-
75-
.PHONY: setup-validator
76-
setup-validator:
77-
@if [ ! -d ../validator ]; then \
78-
git clone https://github.com/validator-labs/validator ../validator; \
79-
fi
80-
81-
.PHONY: dev
82-
dev: ## Run a controller via devspace
83-
devspace dev -n validator-plugin-maas-system
84-
85-
##@ Build
86-
87-
.PHONY: build
88-
build: manifests generate fmt vet ## Build manager binary.
89-
go build -o bin/manager cmd/main.go
90-
91-
.PHONY: run
92-
run: manifests generate fmt vet ## Run a controller from your host.
93-
go run ./cmd/main.go
94-
95-
# If you wish built the manager image targeting other platforms you can use the --platform flag.
96-
# (i.e. docker build --platform linux/arm64 ). However, you must enable docker buildKit for it.
97-
# More info: https://docs.docker.com/develop/develop-images/build_enhancements/
98-
.PHONY: docker-build
99-
docker-build: test ## Build docker image with the manager.
100-
$(CONTAINER_TOOL) build -t ${IMG} . --platform linux/$(GOARCH)
101-
102-
.PHONY: docker-push
103-
docker-push: ## Push docker image with the manager.
104-
$(CONTAINER_TOOL) push ${IMG}
105-
106-
# PLATFORMS defines the target platforms for the manager image be build to provide support to multiple
107-
# architectures. (i.e. make docker-buildx IMG=myregistry/mypoperator:0.0.1). To use this option you need to:
108-
# - able to use docker buildx . More info: https://docs.docker.com/build/buildx/
109-
# - have enable BuildKit, More info: https://docs.docker.com/develop/develop-images/build_enhancements/
110-
# - be able to push the image for your registry (i.e. if you do not inform a valid value via IMG=<myregistry/image:<tag>> then the export will fail)
111-
# To properly provided solutions that supports more than one platform you should use this option.
112-
PLATFORMS ?= linux/arm64,linux/amd64,linux/s390x,linux/ppc64le
113-
.PHONY: docker-buildx
114-
docker-buildx: test ## Build and push docker image for the manager for cross-platform support
115-
# copy existing Dockerfile and insert --platform=${BUILDPLATFORM} into Dockerfile.cross, and preserve the original Dockerfile
116-
sed -e '1 s/\(^FROM\)/FROM --platform=\$$\{BUILDPLATFORM\}/; t' -e ' 1,// s//FROM --platform=\$$\{BUILDPLATFORM\}/' Dockerfile > Dockerfile.cross
117-
- $(CONTAINER_TOOL) buildx create --name project-v3-builder
118-
$(CONTAINER_TOOL) buildx use project-v3-builder
119-
- $(CONTAINER_TOOL) buildx build --push --platform=$(PLATFORMS) --tag ${IMG} -f Dockerfile.cross .
120-
- $(CONTAINER_TOOL) buildx rm project-v3-builder
121-
rm Dockerfile.cross
122-
123-
##@ Deployment
124-
125-
ifndef ignore-not-found
126-
ignore-not-found = false
127-
endif
128-
129-
.PHONY: install
130-
install: manifests kustomize ## Install CRDs into the K8s cluster specified in ~/.kube/config.
131-
$(KUSTOMIZE) build config/crd | $(KUBECTL) apply -f -
132-
133-
.PHONY: uninstall
134-
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.
135-
$(KUSTOMIZE) build config/crd | $(KUBECTL) delete --ignore-not-found=$(ignore-not-found) -f -
136-
137-
.PHONY: deploy
138-
deploy: manifests kustomize ## Deploy controller to the K8s cluster specified in ~/.kube/config.
139-
cd config/manager && $(KUSTOMIZE) edit set image controller=${IMG}
140-
$(KUSTOMIZE) build config/default | $(KUBECTL) apply -f -
141-
142-
.PHONY: undeploy
143-
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.
144-
$(KUSTOMIZE) build config/default | $(KUBECTL) delete --ignore-not-found=$(ignore-not-found) -f -
145-
146-
.PHONY: helmify
147-
helmify: manifests kustomize
148-
cd config/manager && $(KUSTOMIZE) edit set image controller=${IMG}
149-
$(KUSTOMIZE) build config/default > chart/validator-plugin-k8s.yaml
150-
151-
##@ Build Dependencies
152-
153-
## Location to install dependencies to
154-
LOCALBIN ?= $(shell pwd)/bin
155-
$(LOCALBIN):
156-
mkdir -p $(LOCALBIN)
157-
158-
## Tool Binaries
159-
KUBECTL ?= kubectl
160-
KUSTOMIZE ?= $(LOCALBIN)/kustomize
161-
CONTROLLER_GEN ?= $(LOCALBIN)/controller-gen
162-
ENVTEST ?= $(LOCALBIN)/setup-envtest
163-
164-
.PHONY: kustomize
165-
kustomize: KUSTOMIZE_VERSION ?= v5.0.1
166-
kustomize: $(KUSTOMIZE) ## Download kustomize locally if necessary. If wrong version is installed, it will be removed before downloading.
167-
$(KUSTOMIZE): $(LOCALBIN)
168-
@if test -x $(LOCALBIN)/kustomize && ! $(LOCALBIN)/kustomize version | grep -q $(KUSTOMIZE_VERSION); then \
169-
echo "$(LOCALBIN)/kustomize version is not expected $(KUSTOMIZE_VERSION). Removing it before installing."; \
170-
rm -rf $(LOCALBIN)/kustomize; \
171-
fi
172-
test -s $(LOCALBIN)/kustomize || GOBIN=$(LOCALBIN) GO111MODULE=on go install sigs.k8s.io/kustomize/kustomize/v5@$(KUSTOMIZE_VERSION)
173-
174-
.PHONY: controller-gen
175-
controller-gen: CONTROLLER_TOOLS_VERSION ?= v0.15.0
176-
controller-gen: $(CONTROLLER_GEN) ## Download controller-gen locally if necessary. If wrong version is installed, it will be overwritten.
177-
$(CONTROLLER_GEN): $(LOCALBIN)
178-
test -s $(LOCALBIN)/controller-gen && $(LOCALBIN)/controller-gen --version | grep -q $(CONTROLLER_TOOLS_VERSION) || \
179-
GOBIN=$(LOCALBIN) go install sigs.k8s.io/controller-tools/cmd/controller-gen@$(CONTROLLER_TOOLS_VERSION)
180-
181-
.PHONY: envtest
182-
envtest: $(ENVTEST) ## Download envtest-setup locally if necessary.
183-
$(ENVTEST): $(LOCALBIN)
184-
test -s $(LOCALBIN)/setup-envtest || GOBIN=$(LOCALBIN) go install sigs.k8s.io/controller-runtime/tools/setup-envtest@latest
185-
186-
187-
.PHONY: helm
188-
helm: HELM_VERSION=v3.10.1
189-
helm: OSARCH=$(shell ./hack/get-os.sh)
190-
helm: HELM = $(shell pwd)/bin/$(OSARCH)/helm
191-
helm: HELM_INSTALLER ?= "https://get.helm.sh/helm-$(HELM_VERSION)-$(OSARCH).tar.gz"
192-
helm: HELMIFY ?= $(LOCALBIN)/helmify
193-
helm: $(HELM) ## Download helm locally if necessary.
194-
$(HELM): $(LOCALBIN)
195-
[ -e "$(HELM)" ] && rm -rf "$(HELM)" || true
196-
cd $(LOCALBIN) && curl -s $(HELM_INSTALLER) | tar -xzf - -C $(LOCALBIN)
197-
198-
.PHONY: helmify
199-
helmify: $(HELMIFY) ## Download helmify locally if necessary.
200-
$(HELMIFY): $(LOCALBIN)
201-
test -s $(LOCALBIN)/helmify || GOBIN=$(LOCALBIN) go install github.com/arttor/helmify/cmd/helmify@latest
202-
203-
.PHONY: helm-build
204-
helm-build: helm helmify manifests kustomize
205-
cd config/manager && $(KUSTOMIZE) edit set image controller=$(IMG) && cd ../../
206-
$(KUSTOMIZE) build config/default | $(HELMIFY) -crd-dir
207-
208-
.PHONY: helm-package
209-
helm-package: CHART_VERSION=v0.0.1 # x-release-please-version
210-
helm-package: generate manifests
211-
$(HELM) package --version $(CHART_VERSION) chart/validator-plugin-maas/
212-
mkdir -p charts && mv validator-*.tgz charts
213-
$(HELM) repo index --url https://validator-labs.github.io/validator-plugin-mass ./chart
214-
mv charts/validator-plugin-maas/index.yaml index.yaml
215-
216-
.PHONY: frigate
217-
frigate:
218-
frigate gen chart/validator-plugin-maas --no-deps -o markdown > chart/validator-plugin-maas/README.md
11+
# Helm vars
12+
CHART_NAME=validator-plugin-maas

build

Submodule build added at ea93554

config/crd/bases/validation.spectrocloud.labs_maasvalidators.yaml

Lines changed: 12 additions & 7 deletions
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.12.0
6+
controller-gen.kubebuilder.io/version: v0.15.0
77
name: maasvalidators.validation.spectrocloud.labs
88
spec:
99
group: validation.spectrocloud.labs
@@ -20,14 +20,19 @@ spec:
2020
description: MaasValidator is the Schema for the maasvalidators API
2121
properties:
2222
apiVersion:
23-
description: 'APIVersion defines the versioned schema of this representation
24-
of an object. Servers should convert recognized schemas to the latest
25-
internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources'
23+
description: |-
24+
APIVersion defines the versioned schema of this representation of an object.
25+
Servers should convert recognized schemas to the latest internal value, and
26+
may reject unrecognized values.
27+
More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources
2628
type: string
2729
kind:
28-
description: 'Kind is a string value representing the REST resource this
29-
object represents. Servers may infer this from the endpoint the client
30-
submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds'
30+
description: |-
31+
Kind is a string value representing the REST resource this object represents.
32+
Servers may infer this from the endpoint the client submits requests to.
33+
Cannot be updated.
34+
In CamelCase.
35+
More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds
3136
type: string
3237
metadata:
3338
type: object

hack/get-os.sh

Lines changed: 0 additions & 28 deletions
This file was deleted.

internal/controller/maasvalidator_controller.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,8 @@ func (r *MaasValidatorReconciler) Reconcile(ctx context.Context, req ctrl.Reques
6666

6767
secretName := validator.Spec.MaasInstance.Auth.SecretName
6868
var (
69-
maasToken string = ""
70-
err error = nil
69+
maasToken string
70+
err error
7171
)
7272

7373
if maasToken, err = r.tokenFromSecret(secretName, req.Namespace); err != nil {

0 commit comments

Comments
 (0)