-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMakefile
More file actions
216 lines (177 loc) · 6.9 KB
/
Copy pathMakefile
File metadata and controls
216 lines (177 loc) · 6.9 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
209
210
211
212
213
214
215
216
REGISTRY ?= ghcr.io
USERNAME ?= vatesfr
PROJECT ?= xenorchestra-csi-driver
IMAGE ?= $(REGISTRY)/$(USERNAME)/$(PROJECT)
HELMREPO ?= $(REGISTRY)/$(USERNAME)/charts
PLATFORM ?= linux/amd64
PUSH ?= false
VERSION ?= $(shell git describe --dirty --tag --match='v*')
TAG ?= $(VERSION)
GIT_COMMIT ?= $(shell git rev-parse HEAD)
PLUGIN_NAME = xenorchestra-csi
VDI_NAME_PREFIX ?= csi-
BUILD_DATE := $(shell date -u '+%Y-%m-%d_%H:%M:%S')
GO_LDFLAGS := -extldflags "-static" -w -s
GO_LDFLAGS += -X github.com/vatesfr/xenorchestra-csi-driver/pkg/xenorchestra-csi.driverVersion=$(VERSION)
GO_LDFLAGS += -X github.com/vatesfr/xenorchestra-csi-driver/pkg/xenorchestra-csi.gitCommit=$(GIT_COMMIT)
GO_LDFLAGS += -X github.com/vatesfr/xenorchestra-csi-driver/pkg/xenorchestra-csi.buildDate=$(BUILD_DATE)
OS ?= $(shell go env GOOS)
ARCH ?= $(shell go env GOARCH)
ARCHS = amd64
TESTARGS ?= "-v"
BUILD_ARGS := --platform=$(PLATFORM)
ifeq ($(PUSH),true)
BUILD_ARGS += --push=$(PUSH)
BUILD_ARGS += --output type=image,annotation-index.org.opencontainers.image.source="https://github.com/$(USERNAME)/$(PROJECT)",annotation-index.org.opencontainers.image.description="Xen Orchestra CSI driver for Kubernetes"
else
BUILD_ARGS += --output type=docker
endif
COSING_ARGS ?=
############
# Help Menu
define HELP_MENU_HEADER
# Getting Started
To build this project, you must have the following installed:
- git
- make
- golang 1.20+
- golangci-lint
- git-cliff
- helm
- helm-docs
endef
export HELP_MENU_HEADER
help: ## This help menu.
@echo "$$HELP_MENU_HEADER"
@grep -E '^[a-zA-Z0-9%_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
############
#
# Build Abstractions
#
build-all-archs:
@for arch in $(ARCHS); do $(MAKE) ARCH=$${arch} build ; done
.PHONY: clean
clean: ## Clean
rm -rf bin
.PHONY: build
build: ## Build
CGO_ENABLED=0 GOOS=$(OS) GOARCH=$(ARCH) go build -ldflags "$(GO_LDFLAGS)" \
-o bin/${PLUGIN_NAME}-$(ARCH) ./cmd/${PLUGIN_NAME}
.PHONY: build-debug
build-debug: ## Build with debug symbols
GOOS=$(OS) GOARCH=$(ARCH) go build -gcflags=all="-N -l" -o bin/${PLUGIN_NAME}-$(ARCH) ./cmd/${PLUGIN_NAME}
.PHONY: remote-debug
remote-debug: build-debug ## Build with debug and start Delve in DAP mode
dlv dap --listen=:2345
.PHONY: lint
lint: ## Lint Code
golangci-lint run --config .golangci.yml
.PHONY: vuln
vuln: ## Check for known vulnerabilities
govulncheck ./...
.PHONY: unit
unit: ## Unit Tests
go test -tags=unit $(shell go list ./...) $(TESTARGS)
.PHONY: run
run: ## Run the application
go run ./cmd/${PLUGIN_NAME} --v 5 --node-name $(KUBE_NODE_NAME) --endpoint=unix:///csi/csi.sock --vdi-name-prefix=$(VDI_NAME_PREFIX) --cluster-tag=$(CLUSTER_TAGS) --xo-client-timeout=240s
.PHONY: mock
mock: ## Generate mocks
go generate ./...
############
.PHONY: helm-unit
helm-unit: ## Lint and render the Helm chart
# Lint the chart
helm lint charts/xenorchestra-csi-driver
# Render the chart with the CI values (inline config)
@helm template --namespace kube-system \
-f charts/xenorchestra-csi-driver/ci/values.yaml \
xenorchestra-csi-driver charts/xenorchestra-csi-driver >/dev/null
# Render the Helm test pod when tests.enabled=true
helm template --namespace kube-system \
--set tests.enabled=true \
--set tests.storageClassName=xo-test \
--set tests.image=null \
xenorchestra-csi-driver charts/xenorchestra-csi-driver | \
grep -q 'helm.sh/hook: test'
# Fall back to the default service accounts when serviceAccount.create=false
test "$$(helm template --namespace kube-system \
--set serviceAccount.create=false \
--set rbac.create=false \
xenorchestra-csi-driver charts/xenorchestra-csi-driver | \
grep -c 'serviceAccountName: default')" -eq 2
# Skip the controller Deployment and the CSIDriver when disabled
test "$$(helm template --namespace kube-system \
--set controller.enabled=false \
--set csidriver.enabled=false \
xenorchestra-csi-driver charts/xenorchestra-csi-driver | \
grep -cE 'kind: (Deployment|CSIDriver)')" -eq 0
# Skip the node DaemonSet when disabled
test "$$(helm template --namespace kube-system \
--set node.enabled=false \
xenorchestra-csi-driver charts/xenorchestra-csi-driver | \
grep -cE 'kind: DaemonSet')" -eq 0
# Skip the ServiceAccount and RBAC of the disabled component
test "$$(helm template --namespace kube-system \
--set node.enabled=false \
xenorchestra-csi-driver charts/xenorchestra-csi-driver | \
grep -c 'name: xenorchestra-csi-driver-node')" -eq 0
test "$$(helm template --namespace kube-system \
--set controller.enabled=false \
xenorchestra-csi-driver charts/xenorchestra-csi-driver | \
grep -c 'name: xenorchestra-csi-driver-controller')" -eq 0
.PHONY: helm-login
helm-login: ## Helm Login
@echo "${HELM_TOKEN}" | helm registry login $(REGISTRY) --username $(USERNAME) --password-stdin
.PHONY: helm-release
helm-release: ## Helm Release
@rm -rf dist/
@helm package charts/xenorchestra-csi-driver -d dist
@helm push dist/xenorchestra-csi-driver-*.tgz oci://$(HELMREPO) 2>&1 | tee dist/.digest
@cosign sign --yes $(COSING_ARGS) $(HELMREPO)/xenorchestra-csi-driver@$$(cat dist/.digest | awk -F "[, ]+" '/Digest/{print $$NF}')
############
.PHONY: docs
docs:
yq -i '.appVersion = "$(TAG)"' charts/xenorchestra-csi-driver/Chart.yaml -y
helm template --namespace kube-system xenorchestra-csi-driver \
--set existingConfigSecret=xenorchestra-csi-driver \
charts/xenorchestra-csi-driver > docs/deploy/csi-driver.yml
helm template --namespace kube-system xenorchestra-csi-driver \
-f charts/xenorchestra-csi-driver/values.edge.yaml \
--set existingConfigSecret=xenorchestra-csi-driver \
charts/xenorchestra-csi-driver > docs/deploy/csi-driver-edge.yml
helm template --namespace kube-system xenorchestra-csi-driver \
-f charts/xenorchestra-csi-driver/values.microk8s.yaml \
--set existingConfigSecret=xenorchestra-csi-driver \
charts/xenorchestra-csi-driver > docs/deploy/csi-driver-microk8s.yml
helm-docs --sort-values-order=file charts/xenorchestra-csi-driver
release-update:
ifdef RELEASE_TAG
git-cliff --config cliff.toml --tag $(RELEASE_TAG) --unreleased --prepend CHANGELOG.md
else
git-cliff --config cliff.toml --unreleased --prepend CHANGELOG.md
endif
############
#
# Docker Abstractions
#
docker-init:
@docker run --rm --privileged multiarch/qemu-user-static -p yes ||:
@docker context create multiarch ||:
@docker buildx create --name multiarch --driver docker-container --use ||:
@docker context use multiarch
@docker buildx inspect --bootstrap multiarch
.PHONY: images
images: ## Build images
docker buildx build $(BUILD_ARGS) \
--build-arg VERSION="$(VERSION)" \
--build-arg TAG="$(TAG)" \
--build-arg GIT_COMMIT="$(GIT_COMMIT)" \
-t $(IMAGE):$(TAG) \
-f Dockerfile .
.PHONY: images-checks
images-checks: images
trivy image --exit-code 1 --ignore-unfixed --severity HIGH,CRITICAL --no-progress $(IMAGE):$(TAG)
.PHONY: images-cosign
images-cosign:
@cosign sign --yes $(COSING_ARGS) --recursive $(IMAGE):$(TAG)