forked from libopenstorage/openstorage
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
457 lines (375 loc) · 14.3 KB
/
Makefile
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
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
HAS_SDKTEST := $(shell command -v sdk-test 2> /dev/null)
BRANCH := $(shell git rev-parse --abbrev-ref HEAD)
ifeq ($(TRAVIS_BRANCH), master)
MOCKSDKSERVERTAG := latest
else
ifeq ($(BRANCH), master)
MOCKSDKSERVERTAG := latest
else
MOCKSDKSERVERTAG := $(shell go run tools/sdkver/sdkver.go)
endif
endif
REGISTRY = openstorage
IMAGE_MOCKSDKSERVER := $(REGISTRY)/mock-sdk-server:$(MOCKSDKSERVERTAG)
ifndef TAGS
TAGS := daemon
endif
ifndef PKGS
PKGS := $(shell go list ./... 2>&1 | grep -v 'vendor' | grep -v 'sanity')
endif
ifeq ($(BUILD_TYPE),debug)
BUILDFLAGS := -gcflags "-N -l"
endif
ifdef HAVE_BTRFS
TAGS+=btrfs_noversion have_btrfs
endif
ifdef HAVE_CHAINFS
TAGS+=have_chainfs
endif
ifndef PROTOC
PROTOC = protoc
endif
ifndef PROTOS_PATH
PROTOS_PATH = $(GOPATH)/src
endif
ifndef PROTOSRC_PATH
PROTOSRC_PATH = $(PROTOS_PATH)/github.com/libopenstorage/openstorage
endif
OSDSANITY:=cmd/osd-sanity/osd-sanity
.PHONY: \
all \
deps \
update-deps \
test-deps \
update-test-deps \
vendor-update \
vendor-without-update \
vendor-gomod \
vendor \
build \
install \
proto \
lint \
vet \
fmt \
packr \
errcheck \
pretest \
test \
hack-tests \
docs \
docker-build-osd-dev \
docker-build \
docker-test \
docker-build-osd-internal \
docker-build-osd \
launch \
launch-local-btrfs \
install-flexvolume-plugin \
$(OSDSANITY)-install \
$(OSDSANITY)-clean \
clean \
generate \
generate-mockfiles \
e2e \
verify \
osd-tests \
pr-lint \
pr-verify \
pr-unit-tests \
sdk-check-version
all: build $(OSDSANITY)
# TOOLS build rules
#
$(GOPATH)/bin/golint:
@echo "Installing missing $@ ..."
GO111MODULE=off go get -u github.com/golang/lint/golint
$(GOPATH)/bin/errcheck:
@echo "Installing missing $@ ..."
GO111MODULE=off go get -u github.com/kisielk/errcheck
$(GOPATH)/bin/packr2:
@echo "Installing missing $@ ..."
GO111MODULE=off go get -u github.com/gobuffalo/packr/...
$(GOPATH)/bin/cover:
@echo "Installing missing $@ ..."
GO111MODULE=off go get -u golang.org/x/tools/cmd/cover
$(GOPATH)/bin/gotestcover:
@echo "Installing missing $@ ..."
GO111MODULE=off go get -u github.com/pierrre/gotestcover
$(GOPATH)/bin/contextcheck:
@echo "Installing missing $@ ..."
GO111MODULE=off go get -u github.com/sylvia7788/contextcheck
$(GOPATH)/bin/misspell:
@echo "Installing missing $@ ..."
GO111MODULE=off go get -u github.com/client9/misspell/cmd/misspell
$(GOPATH)/bin/gomock:
GO111MODULE=off go get github.com/golang/mock/gomock
$(GOPATH)/bin/mockgen:
GO111MODULE=off go get github.com/golang/mock/mockgen
# DEPS build rules
#
deps:
GO111MODULE=off go get -d -v $(PKGS)
update-deps:
GO111MODULE=off go get -d -v -u -f $(PKGS)
test-deps:
GO111MODULE=off go get -d -v -t $(PKGS)
update-test-deps:
GO111MODULE=off go get -tags "$(TAGS)" -d -v -t -u -f $(PKGS)
vendor-update:
GOOS=linux GOARCH=amd64 go get -tags "daemon btrfs_noversion have_btrfs have_chainfs" -d -v -t -u -f $(PKGS)
vendor-gomod:
GOOS=linux GOARCH=amd64 go mod tidy
GOOS=linux GOARCH=amd64 go mod vendor
vendor: vendor-gomod
build: packr
go build -tags "$(TAGS)" $(BUILDFLAGS) $(PKGS)
install: packr $(OSDSANITY)-install
go install -gcflags="all=-N -l" -tags "$(TAGS)" $(PKGS)
go install github.com/libopenstorage/openstorage/cmd/osd-token-generator
$(OSDSANITY):
@$(MAKE) -C cmd/osd-sanity
$(OSDSANITY)-install:
@$(MAKE) -C cmd/osd-sanity install
$(OSDSANITY)-clean:
@$(MAKE) -C cmd/osd-sanity clean
docker-build-proto:
docker build -t quay.io/openstorage/osd-proto --network=host -f Dockerfile.proto .
docker-proto:
docker run \
--privileged --rm \
-v $(shell pwd):/go/src/github.com/libopenstorage/openstorage \
-e "GOPATH=/go" \
-e "DOCKER_PROTO=yes" \
-e "PATH=/bin:/usr/bin:/usr/local/bin:/go/bin:/usr/local/go/bin" \
quay.io/openstorage/osd-proto \
make proto mockgen
proto: $(GOPATH)/bin/protoc-gen-go $(GOPATH)/bin/protoc-gen-grpc-gateway $(GOPATH)/bin/protoc-gen-swagger
ifndef DOCKER_PROTO
$(error Do not run directly. Run 'make docker-proto' instead.)
endif
@echo ">>> Generating protobuf definitions from api/api.proto"
$(PROTOC) -I $(PROTOSRC_PATH) \
-I /usr/local/include \
-I $(PROTOS_PATH)/github.com/grpc-ecosystem/grpc-gateway/third_party/googleapis \
--go_out=plugins=grpc:. \
$(PROTOSRC_PATH)/api/api.proto
$(PROTOC) -I $(PROTOSRC_PATH) \
-I /usr/local/include \
-I $(PROTOS_PATH)/github.com/grpc-ecosystem/grpc-gateway/third_party/googleapis \
--grpc-gateway_out=logtostderr=true:. \
$(PROTOSRC_PATH)/api/api.proto
$(PROTOC) -I $(PROTOSRC_PATH) \
-I /usr/local/include \
-I $(PROTOS_PATH)/github.com/grpc-ecosystem/grpc-gateway/third_party/googleapis \
--swagger_out=logtostderr=true:$(PROTOSRC_PATH)/api/server/sdk \
$(PROTOSRC_PATH)/api/api.proto
@echo ">>> Upgrading swagger 2.0 to openapi 3.0"
mv api/server/sdk/api/api.swagger.json api/server/sdk/api/20api.swagger.json
swagger2openapi api/server/sdk/api/20api.swagger.json -o api/server/sdk/api/api.swagger.json
rm -f api/server/sdk/api/20api.swagger.json
@echo ">>> Generating grpc protobuf definitions from pkg/flexvolume/flexvolume.proto"
$(PROTOC) -I/usr/local/include -I$(PROTOSRC_PATH) -I$(PROTOS_PATH)/github.com/grpc-ecosystem/grpc-gateway/third_party/googleapis --go_out=plugins=grpc:. $(PROTOSRC_PATH)/pkg/flexvolume/flexvolume.proto
$(PROTOC) -I/usr/local/include -I$(PROTOSRC_PATH) -I$(PROTOS_PATH)/github.com/grpc-ecosystem/grpc-gateway/third_party/googleapis --grpc-gateway_out=logtostderr=true:. $(PROTOSRC_PATH)/pkg/flexvolume/flexvolume.proto
@echo ">>> Generating protobuf definitions from pkg/jsonpb/testing/testing.proto"
$(PROTOC) -I $(PROTOSRC_PATH) $(PROTOSRC_PATH)/pkg/jsonpb/testing/testing.proto --go_out=plugins=grpc:.
@echo ">>> Updating SDK versions"
go run tools/sdkver/sdkver.go --swagger api/server/sdk/api/api.swagger.json
lint: $(GOPATH)/bin/golint
golint $(PKGS)
vet:
@if [ $(shell go vet $(PKGS) | grep -v ".*contains sync.Mutex.*" | wc -l) != 0 ]; then\
echo "go vet failed (ignore the errors associate with sync.Mutex";\
exit 1;\
fi
fmt:
go fmt $(go list ./... | grep -v vendor) | grep -v "api.pb.go" | wc -l | grep "^0";
errcheck: $(GOPATH)/bin/errcheck
errcheck -tags "$(TAGS)" $(PKGS)
contextcheck: $(GOPATH)/bin/contextcheck
contextcheck $(PKGS)
misspell: $(GOPATH)/bin/misspell
git ls-files | grep -v vendor | grep -v .pb.go | grep -v .js | grep -v .css | xargs misspell
pretest: lint vet errcheck
install-sdk-test:
ifndef HAS_SDKTEST
@echo "Installing sdk-test"
@-GO111MODULE=off go get -d -u github.com/libopenstorage/sdk-test 1>/dev/null 2>&1
@(cd $(GOPATH)/src/github.com/libopenstorage/sdk-test/cmd/sdk-test && make install )
endif
test-sdk: install-sdk-test launch-sdk
timeout 30 sh -c 'until curl --silent -X GET -d {} http://localhost:9110/v1/clusters/inspectcurrent | grep STATUS_OK; do sleep 1; done'
sdk-test -ginkgo.noColor -ginkgo.noisySkippings=false -sdk.endpoint=localhost:9100 -sdk.cpg=$(GOPATH)/src/github.com/libopenstorage/sdk-test/cmd/sdk-test/cb.yaml
# TODO: Remove GODEBUG and fix test certs
test: packr
GODEBUG=x509ignoreCN=0 go test -tags "$(TAGS)" $(TESTFLAGS) $(PKGS)
docs: $(GOPATH)/bin/gomock $(GOPATH)/bin/swagger $(GOPATH)/bin/mockgen
go generate ./cmd/osd/main.go
packr: $(GOPATH)/bin/packr2
packr2 clean
packr2
generate-mockfiles: $(GOPATH)/bin/gomock $(GOPATH)/bin/swagger $(GOPATH)/bin/mockgen
go generate $(PKGS)
generate: docs generate-mockfiles
sdk: docker-proto docker-build-mock-sdk-server
docker-build-mock-sdk-server: packr
rm -rf _tmp
mkdir -p _tmp
CGO_ENABLED=0 GOOS=linux go build \
-a -ldflags '-extldflags "-static"' \
-tags "$(TAGS)" \
-o ./_tmp/osd \
./cmd/osd
docker build -t $(IMAGE_MOCKSDKSERVER) -f Dockerfile.sdk .
rm -rf _tmp
docker-build-osd-dev-base:
docker build -t quay.io/openstorage/osd-dev-base -f Dockerfile.osd-dev-base .
push-mock-sdk-server: docker-build-mock-sdk-server
docker push $(IMAGE_MOCKSDKSERVER)
docker-build-osd-dev:
# This image is local only and will not be pushed
docker build -t openstorage/osd-dev -f Dockerfile.osd-dev .
docker-build: docker-build-osd-dev
docker run \
--privileged \
-v /var/run/docker.sock:/var/run/docker.sock \
-e AWS_ACCESS_KEY_ID \
-e AWS_SECRET_ACCESS_KEY \
-e "TAGS=$(TAGS)" \
-e "PKGS=$(PKGS)" \
-e "BUILDFLAGS=$(BUILDFLAGS)" \
openstorage/osd-dev \
make build
docker-test: docker-build-osd-dev
docker run \
--privileged \
-v /var/run/docker.sock:/var/run/docker.sock \
-v /mnt:/mnt \
-e AWS_REGION \
-e AWS_ZONE \
-e AWS_INSTANCE_NAME \
-e AWS_ACCESS_KEY_ID \
-e AWS_SECRET_ACCESS_KEY \
-e GOOGLE_APPLICATION_CREDENTIALS \
-e GCE_INSTANCE_NAME \
-e GCE_INSTANCE_ZONE \
-e GCE_INSTANCE_PROJECT \
-e AZURE_INSTANCE_NAME \
-e AZURE_SUBSCRIPTION_ID \
-e AZURE_RESOURCE_GROUP_NAME \
-e AZURE_ENVIRONMENT \
-e AZURE_TENANT_ID \
-e AZURE_CLIENT_ID \
-e AZURE_CLIENT_SECRET \
-e "TAGS=$(TAGS)" \
-e "PKGS=$(PKGS)" \
-e "BUILDFLAGS=$(BUILDFLAGS)" \
-e "TESTFLAGS=$(TESTFLAGS)" \
-e "GO111MODULE=auto" \
openstorage/osd-dev \
make test
docker-build-osd-internal:
rm -rf _tmp
mkdir -p _tmp
go build -a -tags "$(TAGS)" -o _tmp/osd cmd/osd/main.go
docker build -t quay.io/openstorage/osd -f Dockerfile.osd .
docker-build-osd: docker-build-osd-dev
docker run \
-v /var/run/docker.sock:/var/run/docker.sock \
-e "TAGS=$(TAGS)" \
-e "PKGS=$(PKGS)" \
-e "BUILDFLAGS=$(BUILDFLAGS)" \
openstorage/osd-dev \
make docker-build-osd-internal
launch-sdk-quick:
@-docker stop sdk > /dev/null 2>&1
docker run --rm --name sdk \
-d -p 9110:9110 -p 9100:9100 \
$(IMAGE_MOCKSDKSERVER)
launch-sdk: sdk launch-sdk-quick
launch: docker-build-osd
docker run \
--privileged \
-d \
-v $(shell pwd)/etc:/etc \
-v /run/docker/plugins:/run/docker/plugins \
-v /var/lib/osd/:/var/lib/osd/ \
-p 9005:9005 \
-p 9100:9100 \
-p 9110:9110 \
quay.io/openstorage/osd -d -f /etc/config/config.yaml
# must set HAVE_BTRFS
launch-local-btrfs: install
sudo bash -x etc/btrfs/init.sh
sudo $(shell which osd) -d -f etc/config/config_btrfs.yaml
install-flexvolume:
go install -a -tags "$(TAGS)" github.com/libopenstorage/openstorage/pkg/flexvolume github.com/libopenstorage/openstorage/pkg/flexvolume/cmd/flexvolume
install-flexvolume-plugin: install-flexvolume
sudo rm -rf /usr/libexec/kubernetes/kubelet/volume/exec-plugins/openstorage~openstorage
sudo mkdir -p /usr/libexec/kubernetes/kubelet/volume/exec-plugins/openstorage~openstorage
sudo chmod 777 /usr/libexec/kubernetes/kubelet/volume/exec-plugins/openstorage~openstorage
cp $(GOPATH)/bin/flexvolume /usr/libexec/kubernetes/kubelet/volume/exec-plugins/openstorage~openstorage/openstorage
clean: $(OSDSANITY)-clean
go clean -i $(PKGS)
packr2 clean
# Generate test-coverage HTML report
# - note: the 'go test -coverprofile...' does append results, so we're merging individual pkgs in for-loop
coverage: packr $(GOPATH)/bin/cover $(GOPATH)/bin/gotestcover
gotestcover -coverprofile=coverage.out $(PKGS)
go tool cover -html=coverage.out -o coverage.html
@echo "INFO: Summary of coverage"
go tool cover -func=coverage.out
@cp coverage.out coverage.html /mnt/ && \
echo "INFO: libopenstorage coverage saved at /mnt/coverage.{html,out}"
docker-coverage: docker-build-osd-dev
docker run \
--privileged \
-v /var/run/docker.sock:/var/run/docker.sock \
-v /mnt:/mnt \
-e AWS_ACCESS_KEY_ID \
-e AWS_SECRET_ACCESS_KEY \
-e "TAGS=$(TAGS)" \
-e "PKGS=$(PKGS)" \
-e "BUILDFLAGS=$(BUILDFLAGS)" \
-e "TESTFLAGS=$(TESTFLAGS)" \
openstorage/osd-dev \
make coverage
docker-images: docker-build-proto docker-build-osd-dev-base
push-docker-images: docker-images
docker push quay.io/openstorage/osd-dev-base
docker push quay.io/openstorage/osd-proto
# This needs to be adjusted for each release branch according
# to the SDK Version.
# For master (until released), major should be 0 and patch should be 0.
# For release branches, major and minor should be frozen.
sdk-check-version:
go run tools/sdkver/sdkver.go --check-major=0 --check-patch=0
mockgen:
GO111MODULE=off go get github.com/golang/mock/gomock
GO111MODULE=off go get github.com/golang/mock/mockgen
mockgen -destination=api/mock/mock_storagepool.go -package=mock github.com/libopenstorage/openstorage/api OpenStoragePoolServer,OpenStoragePoolClient
mockgen -destination=api/mock/mock_cluster.go -package=mock github.com/libopenstorage/openstorage/api OpenStorageClusterServer,OpenStorageClusterClient
mockgen -destination=api/mock/mock_node.go -package=mock github.com/libopenstorage/openstorage/api OpenStorageNodeServer,OpenStorageNodeClient
mockgen -destination=api/mock/mock_diags.go -package=mock github.com/libopenstorage/openstorage/api OpenStorageDiagsServer,OpenStorageDiagsClient
mockgen -destination=api/mock/mock_volume.go -package=mock github.com/libopenstorage/openstorage/api OpenStorageVolumeServer,OpenStorageVolumeClient
mockgen -destination=api/mock/mock_watch.go -package=mock github.com/libopenstorage/openstorage/api OpenStorageWatchServer,OpenStorageWatchClient
mockgen -destination=api/mock/mock_bucket.go -package=mock github.com/libopenstorage/openstorage/api OpenStorageBucketServer,OpenStorageBucketClient
mockgen -destination=cluster/mock/cluster.mock.go -package=mock github.com/libopenstorage/openstorage/cluster Cluster
mockgen -destination=api/mock/mock_fstrim.go -package=mock github.com/libopenstorage/openstorage/api OpenStorageFilesystemTrimServer,OpenStorageFilesystemTrimClient
mockgen -destination=api/mock/mock_fscheck.go -package=mock github.com/libopenstorage/openstorage/api OpenStorageFilesystemCheckServer,OpenStorageFilesystemCheckClient
mockgen -destination=api/server/mock/mock_schedops_k8s.go -package=mock github.com/portworx/sched-ops/k8s/core Ops
mockgen -destination=volume/drivers/mock/driver.mock.go -package=mock github.com/libopenstorage/openstorage/volume VolumeDriver
mockgen -destination=bucket/drivers/mock/bucket_driver.mock.go -package=mock github.com/libopenstorage/openstorage/bucket BucketDriver
osd-tests: install
./hack/csi-sanity-test.sh
./hack/docker-integration-test.sh
e2e: docker-build-osd
cd test && ./run.bash
verify: vet sdk-check-version docker-test e2e
pr-verify: vet fmt sdk-check-version
git-validation -run DCO,short-subject
make docker-proto
git diff $(find . -name "*.pb.*go" -o -name "api.swagger.json" | grep -v vendor) | wc -l | grep "^0"
hack/check-api-version.sh
git grep -rw GPL vendor | grep LICENSE | egrep -v "yaml.v2" | wc -l | grep "^0"
pr-test: osd-tests docker-test e2e