Repository navigation
Expand file tree
/
Copy pathMakefile
More file actions
208 lines (170 loc) · 7.21 KB
/
Copy pathMakefile
File metadata and controls
208 lines (170 loc) · 7.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
.PHONY: all build build-plugin clean deps install test test-unit test-scripts test-sanity test-all \
test-coverage coverage coverage-check \
docker-build docker-push lint lint-fix lint-verbose nolint-budget nolint-budget-update \
mod-tidy-check vulncheck check \
test-e2e test-e2e-nfs test-e2e-nvmeof test-e2e-iscsi test-e2e-smb test-e2e-scale test-e2e-snapclone \
changelog changelog-unreleased
DRIVER_NAME=tns-csi-driver
PLUGIN_NAME=kubectl-tns_csi
IMAGE_NAME=bfenski/tns-csi
REGISTRY?=docker.io
# Single source of truth for the golangci-lint version. CI workflows read this line
# (see .github/workflows/ci.yml and release.yml); keep .pre-commit-config.yaml in sync.
# Bump deliberately and fix any new warnings in the same PR.
GOLANGCI_LINT_VERSION ?= v2.15.0
# Version information - derived from git tags
VERSION ?= $(shell git describe --tags --always 2>/dev/null || echo "dev")
GIT_COMMIT ?= $(shell git rev-parse --short HEAD 2>/dev/null || echo "unknown")
BUILD_DATE ?= $(shell date -u +"%Y-%m-%dT%H:%M:%SZ")
# Go parameters
GOCMD=go
GOBUILD=$(GOCMD) build
GOCLEAN=$(GOCMD) clean
GOTEST=$(GOCMD) test
GOGET=$(GOCMD) get
GOMOD=$(GOCMD) mod
GOLANGCI_LINT=golangci-lint
# Build parameters with version injection
LDFLAGS=-ldflags "-s -w \
-X main.version=$(VERSION) \
-X main.gitCommit=$(GIT_COMMIT) \
-X main.buildDate=$(BUILD_DATE)"
BUILD_DIR=bin
all: build
build:
@echo "Building $(DRIVER_NAME)..."
@mkdir -p $(BUILD_DIR)
$(GOBUILD) $(LDFLAGS) -o $(BUILD_DIR)/$(DRIVER_NAME) ./cmd/tns-csi-driver
build-plugin:
@echo "Building $(PLUGIN_NAME)..."
@mkdir -p $(BUILD_DIR)
$(GOBUILD) -ldflags "-s -w -X main.version=$(VERSION) -X main.commit=$(GIT_COMMIT)" \
-o $(BUILD_DIR)/$(PLUGIN_NAME) ./cmd/kubectl-tns-csi
@echo "Plugin built: $(BUILD_DIR)/$(PLUGIN_NAME)"
@echo "Install with: cp $(BUILD_DIR)/$(PLUGIN_NAME) /usr/local/bin/"
clean:
@echo "Cleaning..."
$(GOCLEAN)
rm -rf $(BUILD_DIR)
test:
@echo "Running tests..."
$(GOTEST) -v ./...
lint:
@echo "Running golangci-lint (CI pins $(GOLANGCI_LINT_VERSION))..."
@$(GOLANGCI_LINT) version 2>/dev/null | grep -q "$(GOLANGCI_LINT_VERSION:v%=%)" || \
echo "warning: local golangci-lint is not $(GOLANGCI_LINT_VERSION); results may differ from CI"
$(GOLANGCI_LINT) run --config .golangci.yml ./...
lint-fix:
@echo "Running golangci-lint with auto-fix..."
$(GOLANGCI_LINT) run --config .golangci.yml --fix ./...
lint-verbose:
@echo "Running golangci-lint (verbose)..."
$(GOLANGCI_LINT) run --config .golangci.yml -v ./...
# Ratchet on //nolint directives (see nolint-budget.txt). After removing directives,
# run `make nolint-budget-update` and commit the lowered budget.
nolint-budget:
bash scripts/ci/nolint-budget_test.sh >/dev/null
bash scripts/ci/nolint-budget.sh
nolint-budget-update:
bash scripts/ci/nolint-budget.sh --update
deps:
@echo "Downloading dependencies..."
$(GOMOD) download
$(GOMOD) tidy
docker-build:
@echo "Building Docker image $(IMAGE_NAME):$(VERSION)..."
docker build \
--build-arg VERSION=$(VERSION) \
--build-arg GIT_COMMIT=$(GIT_COMMIT) \
--build-arg BUILD_DATE=$(BUILD_DATE) \
-t $(IMAGE_NAME):$(VERSION) .
docker tag $(IMAGE_NAME):$(VERSION) $(IMAGE_NAME):latest
docker-push:
@echo "Pushing Docker image $(IMAGE_NAME):$(VERSION)..."
docker push $(IMAGE_NAME):$(VERSION)
docker push $(IMAGE_NAME):latest
install:
@echo "Installing $(DRIVER_NAME)..."
$(GOBUILD) $(LDFLAGS) -o $(GOPATH)/bin/$(DRIVER_NAME) ./cmd/tns-csi-driver
# Sanity tests
test-sanity:
@echo "Running CSI sanity tests..."
./tests/sanity/test-sanity.sh
# Unit tests: race detector on, randomized order, driver + CLI packages (what CI runs).
test-unit:
@echo "Running unit tests..."
$(GOTEST) -v -short -race -shuffle=on ./pkg/... ./cmd/...
# Shell-script unit tests (test runners live in tests/sanity).
test-scripts:
@echo "Running script tests..."
bash tests/sanity/sanity-script_test.sh
bash tests/chart/csidriver_attach_required_test.sh
bash tests/chart/controller_security_context_test.sh
# Fail if go.mod/go.sum are not tidy. Read-only: prints the needed diff, never edits files.
mod-tidy-check:
@echo "Checking go.mod/go.sum are tidy..."
@$(GOMOD) tidy -diff || (echo "go.mod/go.sum not tidy: run 'go mod tidy'" && exit 1)
# Known-vulnerability scan of reachable code (needs network for the vuln DB; not part of check).
GOVULNCHECK_VERSION ?= v1.9.0
vulncheck:
@echo "Running govulncheck $(GOVULNCHECK_VERSION)..."
$(GOCMD) run golang.org/x/vuln/cmd/govulncheck@$(GOVULNCHECK_VERSION) ./...
# Everything a PR must pass. CI runs the same checks (lint via golangci-lint-action).
check: build lint mod-tidy-check test-unit test-scripts test-sanity
@echo "All checks passed"
# Coverage profile for the driver and CLI packages (consumed by coverage-check and SonarQube).
coverage:
@echo "Running tests with coverage..."
$(GOTEST) -short -coverprofile=coverage.out -covermode=atomic ./pkg/... ./cmd/...
@echo "Coverage report: coverage.out"
# Coverage + JSON test report for SonarQube.
test-coverage: coverage
$(GOTEST) -v -short -json ./pkg/... > test-report.json || true
@echo "Test report: test-report.json"
# Coverage ratchet: enforce the floors in .testcoverage.yml.
# COVERAGE_BREAKDOWN=<file> also write a breakdown (CI uploads it from main).
# COVERAGE_BASE_BREAKDOWN=<file> also fail if total coverage drops below that breakdown.
GO_TEST_COVERAGE_VERSION ?= v2.20.1
# go-test-coverage v2.20+ needs Go 1.27; only the tool runs on this toolchain (fetched on
# demand), the tests that produce coverage.out still use the repo's Go version.
GO_TEST_COVERAGE_TOOLCHAIN ?= go1.27.4
COVERAGE_BREAKDOWN ?=
COVERAGE_BASE_BREAKDOWN ?=
# Allowed drop in total coverage vs the base, in percentage points. A small tolerance absorbs
# run-to-run noise from timing-dependent paths; floors still catch real erosion.
COVERAGE_DIFF_THRESHOLD ?= -0.5
coverage-check: coverage
GOTOOLCHAIN=$(GO_TEST_COVERAGE_TOOLCHAIN) $(GOCMD) run github.com/vladopajic/go-test-coverage/v2@$(GO_TEST_COVERAGE_VERSION) --config=.testcoverage.yml \
$(if $(COVERAGE_BREAKDOWN),--breakdown-file-name=$(COVERAGE_BREAKDOWN)) \
$(if $(COVERAGE_BASE_BREAKDOWN),--diff-base-breakdown-file-name=$(COVERAGE_BASE_BREAKDOWN) --diff-threshold=$(COVERAGE_DIFF_THRESHOLD))
test-all: test-unit test-sanity
@echo "All tests completed"
# E2E tests (requires Ginkgo CLI and TrueNAS connection)
test-e2e:
@echo "Running all E2E tests..."
ginkgo -v --timeout=60m ./tests/e2e/...
test-e2e-nfs:
@echo "Running NFS E2E tests..."
ginkgo -v --timeout=25m ./tests/e2e/nfs/...
test-e2e-nvmeof:
@echo "Running NVMe-oF E2E tests..."
ginkgo -v --timeout=40m ./tests/e2e/nvmeof/...
test-e2e-iscsi:
@echo "Running iSCSI E2E tests..."
ginkgo -v --timeout=40m ./tests/e2e/iscsi/...
test-e2e-smb:
@echo "Running SMB E2E tests..."
ginkgo -v --timeout=25m ./tests/e2e/smb/...
test-e2e-scale:
@echo "Running Scale E2E tests (CSI operations with non-CSI noise data)..."
ginkgo -v --timeout=30m ./tests/e2e/scale/...
test-e2e-snapclone:
@echo "Running Snapshot/Clone Stress E2E tests..."
ginkgo -v --timeout=120m ./tests/e2e/snapclone/...
# Changelog generation (requires git-cliff: cargo install git-cliff)
changelog:
@echo "Generating changelog..."
git-cliff -o CHANGELOG.md
changelog-unreleased:
@echo "Generating unreleased changelog..."
git-cliff --unreleased