Repository navigation
Expand file tree
/
Copy pathMakefile
More file actions
208 lines (172 loc) · 6.94 KB
/
Copy pathMakefile
File metadata and controls
208 lines (172 loc) · 6.94 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
# Setting SHELL to bash allows bash commands to be executed by recipes.
# Options are set to exit when a recipe line exits non-zero or a piped command fails.
SHELL = /usr/bin/env bash -o pipefail
.SHELLFLAGS = -ec
BUILD_IMAGES ?= stackit-csi-plugin cloud-controller-manager
SOURCES := Makefile go.mod go.sum $(shell find $(DEST) -name '*.go' 2>/dev/null)
VERSION ?= $(shell git describe --dirty --tags --match='v*' 2>/dev/null || git rev-parse --short HEAD)
REGISTRY ?= ghcr.io
REPO ?= stackitcloud/cloud-provider-stackit
PLATFORMS ?= amd64 arm64
IS_DEV ?= true
LDFLAGS ?= -s -w
E2E_RUN_ID ?= $(or $(PROW_JOB_ID),local-test-e2e)
E2E_PARALLEL_NODES ?= 4
.PHONY: all
all: verify
##@ Tools
include ./hack/tools.mk
build: $(BUILD_IMAGES)
$(BUILD_IMAGES): $(SOURCES) ensure-bin-dir
CGO_ENABLED=0 go build \
-trimpath \
-ldflags "$(LDFLAGS)" \
-o bin/$@ \
./cmd/$@/main.go
.PHONY: ensure-bin-dir
ensure-bin-dir:
@mkdir -p bin
.PHONY: images
images: $(foreach image,$(BUILD_IMAGES),image-$(image))
CCM_CONTROLLERS ?= node-route-controller
CCM_CLUSTER_NAME ?= kubernetes
CCM_CLUSTER_CIDR ?= 100.64.0.0/13
run-cloud-controller-manager: cloud-controller-manager
STACKIT_SERVICE_ACCOUNT_TOKEN=$$(stackit auth get-access-token -o pretty) \
bin/cloud-controller-manager --cloud-provider=stackit \
--cluster-name=$(CCM_CLUSTER_NAME) \
--controllers=$(CCM_CONTROLLERS) \
--cloud-config=dev/config.yaml \
--cluster-cidr $(CCM_CLUSTER_CIDR) \
--secure-port=0 \
--metrics-address="" \
--leader-elect=false \
--kubeconfig=$${KUBECONFIG}
# lazy reference, evaluated when called
LOCAL = false
ifeq ($(LOCAL),true)
# includes busybox as extra dependency true check needed tools
APKO_EXTRA_PACKAGES = busybox
endif
image-%: $(APKO) $(KO)
APKO_EXTRA_PACKAGES=$(APKO_EXTRA_PACKAGES) \
LOCAL=$(LOCAL) \
VERSION=$(VERSION) \
PLATFORMS="$(PLATFORMS)" \
REGISTRY=$(REGISTRY) \
REPO=$(REPO)/$* \
IS_DEV=$(IS_DEV) \
./hack/build.sh $*
.PHONY: image-stackit-csi-plugin-test
image-stackit-csi-plugin-test: export KO_CONFIG_PATH = test/.ko-kubetest2.yaml
image-stackit-csi-plugin-test: export IS_DEV = true
image-stackit-csi-plugin-test: export VERSION := $(VERSION)-kubetest2
image-stackit-csi-plugin-test: image-stackit-csi-plugin
.PHONY: clean-tools-bin
clean-tools-bin: ## Empty the tools binary directory.
rm -rf $(TOOLS_BIN_DIR)/* $(TOOLS_BIN_DIR)/.version_*
.PHONY: fmt
fmt: $(GOIMPORTS_REVISER) ## Run go fmt against code.
go fmt ./...
$(GOIMPORTS_REVISER) .
.PHONY: modules
modules: ## Runs go mod to ensure modules are up to date.
go mod tidy
.PHONY: test
test: ## Run tests.
./hack/test.sh ./cmd/... ./pkg/... ./test/...
.PHONY: test-cover
test-cover: ## Run tests with coverage.
go test -coverprofile cover.out ./...
go tool cover -html cover.out -o cover.html
##@ Verification
.PHONY: lint
lint: $(GOLANGCI_LINT) ## Run golangci-lint against code. Use GOOS=linux since otherwise we will have wrong lints for linux only code
GOOS=linux $(GOLANGCI_LINT) run ./...
.PHONY: check
check: lint test ## Check everything (lint + test).
.PHONY: verify-fmt
verify-fmt: fmt ## Verify go code is formatted.
@if !(git diff --quiet HEAD); then \
echo "unformatted files detected, please run 'make fmt'"; exit 1; \
fi
.PHONY: verify-modules
verify-modules: modules ## Verify go module files are up to date.
@if !(git diff --quiet HEAD -- go.sum go.mod); then \
echo "go module files are out of date, please run 'make modules'"; exit 1; \
fi
.PHONY: verify-generate
verify-generate: generate ## Verify go module files are up to date.
@if !(git diff --quiet HEAD); then \
echo "generate created a diff, please run 'make generate'"; exit 1; \
fi
.PHONY: verify
verify: verify-fmt verify-modules verify-generate check
verify-e2e: verify-e2e-csi
verify-e2e-csi-sequential: FOCUS = "External.Storage.*(\[Feature:|\[Disruptive\]|\[Serial\])"
verify-e2e-csi-sequential: E2E_FLAGS = -v
verify-e2e-csi-sequential: verify-e2e-csi
verify-e2e-csi-parallel: FOCUS = "External.Storage"
verify-e2e-csi-parallel: SKIP = "\[Feature:|\[Disruptive\]|\[Serial\]"
verify-e2e-csi-parallel: E2E_FLAGS = -v -p
verify-e2e-csi-parallel: verify-e2e-csi
verify-e2e-csi: $(KUBERNETES_TEST)
$(KUBERNETES_TEST_GINKGO) \
$(E2E_FLAGS) \
-focus=$(FOCUS) \
-skip=$(SKIP) \
$(KUBERNETES_TEST) -- \
-storage.testdriver=$(PWD)/test/csi-plugin/block-storage.yaml
verify-image-stackit-csi-plugin: LOCAL = true
verify-image-stackit-csi-plugin: APKO_EXTRA_PACKAGES = busybox
verify-image-stackit-csi-plugin: image-stackit-csi-plugin
@echo "verifying binaries in image"
@docker run -v ./tools/csi-deps-check.sh:/tools/csi-deps-check.sh --entrypoint=/tools/csi-deps-check.sh $(REGISTRY)/$(REPO)/stackit-csi-plugin-dev:$(VERSION)
KUBETEST2_STACKIT := $(TOOLS_BIN_DIR)/kubetest2-stackit
$(KUBETEST2_STACKIT): go.mod go.sum $(shell find ./test ./pkg -name '*.go' 2>/dev/null)
go build -trimpath -o $@ ./test
.PHONY: test-e2e
test-e2e: image-stackit-csi-plugin-test $(KUBETEST2_TESTER_GINKGO) $(KUBETEST2_STACKIT)
exec $(KUBETEST2_STACKIT) \
--up \
--down \
--test=ginkgo \
--run-id "$(E2E_RUN_ID)" \
--rundir "$(CURDIR)/_rundir" \
--region "eu01" \
--kubernetes-version "$(E2E_K8S_VERSION)" \
--availability-zone "eu01-1" \
--machine-type "$(E2E_MACHINE_TYPE)" \
--node-image-name "$(E2E_IMAGE_NAME)" \
--node-image-version "$(E2E_IMAGE_VERSION)" \
--nodepool-name "default" \
--volume-size 100 \
--kubeconfig-expiration-seconds 3600 \
--csi-image-name "$(REGISTRY)/$(REPO)/stackit-csi-plugin-dev" \
--csi-image-tag "$(VERSION)-kubetest2" \
--metadata "csi-version=$(VERSION)-kubetest2,k8s-version=v$(E2E_K8S_VERSION)" \
-- \
--test-package-version="v$(E2E_K8S_VERSION)" \
--focus-regex="External.Storage" \
--skip-regex="\[Feature:|\[Disruptive\]|\[Serial\]" \
--ginkgo-args="-v" \
--parallel="$(E2E_PARALLEL_NODES)" \
--test-args="--storage.testdriver=$(CURDIR)/_rundir/$(E2E_RUN_ID)/csi-testdriver.yaml" \
--timeout="90m"
# generate mock types for the following services (space-separated list)
.PHONY: mocks
mocks: $(MOCKGEN)
# clean mocks
@find . -name '*_mock.go' -delete || true
# API mocks
@$(MOCKGEN) -destination ./pkg/mock/loadbalancer/loadbalancer.go -package loadbalancer github.com/stackitcloud/stackit-sdk-go/services/loadbalancer/v2api DefaultAPI
@$(MOCKGEN) -destination ./pkg/mock/iaas/iaas.go -package iaas github.com/stackitcloud/stackit-sdk-go/services/iaas/v2api DefaultAPI
# client mocks
@$(MOCKGEN) -destination ./pkg/stackit/metadata/metadata_mock.go -package metadata ./pkg/stackit/metadata IMetadata
@$(MOCKGEN) -destination ./pkg/csi/util/mount/mount_mock.go -package mount ./pkg/csi/util/mount IMount
@$(MOCKGEN) -destination ./pkg/stackit/client/mock/iaas_mock.go -typed -package client ./pkg/stackit/client IaaSClient
@$(MOCKGEN) -destination ./pkg/stackit/client/mock/loadbalancer_mock.go -typed -package client ./pkg/stackit/client LoadBalancingClient
@$(MOCKGEN) -destination ./pkg/stackit/client/mock/mock.go -package client ./pkg/stackit/client Factory
.PHONY: generate
generate: mocks
go generate ./...