-
Notifications
You must be signed in to change notification settings - Fork 114
/
Makefile
322 lines (271 loc) · 11.9 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
VERSION := $(shell git describe --always --tags --dirty)
COMMIT := $(shell git rev-parse HEAD)
DATE := $(shell date +'%Y-%m-%dT%H:%M%:z')
CNINFRA_AGENT := go.ligato.io/cn-infra/v2/agent
LDFLAGS = -s -w -X $(CNINFRA_AGENT).BuildVersion=$(VERSION) -X $(CNINFRA_AGENT).CommitHash=$(COMMIT) -X $(CNINFRA_AGENT).BuildDate=$(DATE)
COVER_DIR ?= /tmp/
export GO111MODULE=on
export GOPROXY=https://goproxy.io
# Build commands
build: contiv-agent contiv-ksr contiv-crd contiv-cni contiv-stn contiv-init contiv-netctl contiv-ui-backend
# Run all
all: lint build test install
# Build agent
contiv-agent:
@echo "# building contiv-agent"
cd cmd/contiv-agent && go build -v -i -ldflags "${LDFLAGS}" -tags="${GO_BUILD_TAGS}"
# Build contiv-ksr
contiv-ksr:
@echo "# building contiv-ksr"
cd cmd/contiv-ksr && go build -v -i -ldflags "${LDFLAGS}"
# Build contiv-crd
contiv-crd:
@echo "# building contiv-crd"
cd cmd/contiv-crd && go build -v -i -ldflags "${LDFLAGS}" -tags="${GO_BUILD_TAGS}"
# Build contiv-cni
contiv-cni:
@echo "# building contiv-cni"
cd cmd/contiv-cni && go build -v -i -ldflags "-linkmode external -extldflags -static"
# Build contiv-stn
contiv-stn:
@echo "# building contiv-stn"
cd cmd/contiv-stn && go build -v -i -ldflags '-s -w -X main.BuildVersion=$(VERSION) -X main.BuildDate=$(DATE)'
# Build contiv-init
contiv-init:
@echo "# building contiv-init"
cd cmd/contiv-init && go build -v -i -ldflags "${LDFLAGS}" -tags="${GO_BUILD_TAGS}"
# Build contiv-netctl
contiv-netctl:
@echo "# building contiv-netctl"
cd cmd/contiv-netctl && go build -v -i -ldflags "${LDFLAGS}" -tags="${GO_BUILD_TAGS}"
#Build contiv-ui-backend
contiv-ui-backend:
@echo "# building contiv-ui-backend"
cd cmd/contiv-ui-backend && go build -v -i -ldflags "${LDFLAGS}" -tags="${GO_BUILD_TAGS}"
# Install commands
install:
@echo "# installing commands"
cd cmd/contiv-agent && go install -v -ldflags "${LDFLAGS}" -tags="${GO_BUILD_TAGS}"
cd cmd/contiv-ksr && go install -v -ldflags "${LDFLAGS}"
cd cmd/contiv-crd && go install -v -ldflags "${LDFLAGS}"
cd cmd/contiv-cni && go install -v -ldflags "${LDFLAGS}"
cd cmd/contiv-stn && go install -v -ldflags "${LDFLAGS}"
cd cmd/contiv-init && go install -v -ldflags "${LDFLAGS}"
cd cmd/contiv-netctl && go install -v -ldflags "${LDFLAGS}"
# Clean commands
clean:
@echo "# cleaning binaries"
rm -f cmd/contiv-agent/contiv-agent
rm -f cmd/contiv-cni/contiv-cni
rm -f cmd/contiv-ksr/contiv-ksr
rm -f cmd/contiv-crd/contiv-crd
rm -f cmd/contiv-stn/contiv-stn
rm -f cmd/contiv-init/contiv-init
rm -f cmd/contiv-netctl/contiv-netctl
rm -f cmd/contiv-ui-backend/contiv-ui-backend
# Run tests
test:
@echo "# running unit tests"
go test ./cmd/contiv-cni -tags="${GO_BUILD_TAGS}"
go test ./plugins/ipnet -tags="${GO_BUILD_TAGS}"
go test ./plugins/ipam -tags="${GO_BUILD_TAGS}"
go test ./plugins/ksr -tags="${GO_BUILD_TAGS}"
go test ./plugins/policy/configurator -tags="${GO_BUILD_TAGS}"
go test ./plugins/policy/renderer/cache -tags="${GO_BUILD_TAGS}"
go test ./plugins/policy/renderer/acl -tags="${GO_BUILD_TAGS}"
go test ./plugins/policy/cache -tags="${GO_BUILD_TAGS}"
go test ./plugins/policy/cache/namespaceidx -tags="${GO_BUILD_TAGS}"
go test ./plugins/policy/cache/podidx -tags="${GO_BUILD_TAGS}"
go test ./plugins/policy/cache/policyidx -tags="${GO_BUILD_TAGS}"
go test ./plugins/statscollector -tags="${GO_BUILD_TAGS}"
go test ./plugins/service/renderer/srv6 -tags="${GO_BUILD_TAGS}"
go test ./plugins/service/renderer/nat44 -tags="${GO_BUILD_TAGS}"
go test ./plugins/crd/datastore -tags="${GO_BUILD_TAGS}"
go test ./plugins/crd/validator/l2 -tags="${GO_BUILD_TAGS}"
go test ./plugins/crd/validator/l3 -tags="${GO_BUILD_TAGS}"
#go test ./plugins/crd/cache -tags="${GO_BUILD_TAGS}"
go test ./plugins/sfc/renderer/srv6 -tags="${GO_BUILD_TAGS}"
# Run tests with race
test-race:
@echo "# running unit tests with -race"
go test ./cmd/contiv-cni -race -tags="${GO_BUILD_TAGS}"
go test ./plugins/ipnet -race -tags="${GO_BUILD_TAGS}"
go test ./plugins/ipam -race -tags="${GO_BUILD_TAGS}"
go test ./plugins/ksr -race -tags="${GO_BUILD_TAGS}"
go test ./plugins/policy/configurator -race -tags="${GO_BUILD_TAGS}"
go test ./plugins/policy/renderer/cache -race -tags="${GO_BUILD_TAGS}"
go test ./plugins/policy/renderer/acl -race -tags="${GO_BUILD_TAGS}"
go test ./plugins/policy/cache -race -tags="${GO_BUILD_TAGS}"
go test ./plugins/policy/cache/namespaceidx -race -tags="${GO_BUILD_TAGS}"
go test ./plugins/policy/cache/podidx -race -tags="${GO_BUILD_TAGS}"
go test ./plugins/policy/cache/policyidx -race -tags="${GO_BUILD_TAGS}"
go test ./plugins/statscollector -race -tags="${GO_BUILD_TAGS}"
go test ./plugins/service/renderer/srv6 -race -tags="${GO_BUILD_TAGS}"
go test ./plugins/service/renderer/nat44 -race -tags="${GO_BUILD_TAGS}"
go test ./plugins/crd/datastore -tags="${GO_BUILD_TAGS}"
go test ./plugins/crd/validator/l2 -tags="${GO_BUILD_TAGS}"
go test ./plugins/crd/validator/l3 -tags="${GO_BUILD_TAGS}"
#go test ./plugins/crd/cache -tags="${GO_BUILD_TAGS}"
# Get coverage report tools
get-covtools:
go install github.com/wadey/gocovmerge
# Run coverage report
test-cover: get-covtools
@echo "# running unit tests with coverage analysis"
go test -covermode=count -coverprofile=${COVER_DIR}cov_u1.out ./cmd/contiv-cni -tags="${GO_BUILD_TAGS}"
go test -covermode=count -coverprofile=${COVER_DIR}cov_u2.out ./plugins/ipnet -tags="${GO_BUILD_TAGS}"
go test -covermode=count -coverprofile=${COVER_DIR}cov_u3.out ./plugins/ipam -tags="${GO_BUILD_TAGS}"
go test -covermode=count -coverprofile=${COVER_DIR}cov_u6.out ./plugins/ksr -tags="${GO_BUILD_TAGS}"
go test -covermode=count -coverprofile=${COVER_DIR}cov_u7.out ./plugins/policy/configurator -tags="${GO_BUILD_TAGS}"
go test -covermode=count -coverprofile=${COVER_DIR}cov_u8.out ./plugins/policy/renderer/cache -tags="${GO_BUILD_TAGS}"
go test -covermode=count -coverprofile=${COVER_DIR}cov_u9.out ./plugins/policy/renderer/acl -tags="${GO_BUILD_TAGS}"
go test -covermode=count -coverprofile=${COVER_DIR}cov_u10.out -coverpkg=./plugins/service/processor,./plugins/service/configurator ./plugins/service/renderer/srv6 -tags="${GO_BUILD_TAGS}"
go test -covermode=count -coverprofile=${COVER_DIR}cov_u11.out -coverpkg=./plugins/service/processor,./plugins/service/configurator ./plugins/service/renderer/nat44 -tags="${GO_BUILD_TAGS}"
go test -covermode=count -coverprofile=${COVER_DIR}cov_u12.out ./plugins/policy/cache -tags="${GO_BUILD_TAGS}"
go test -covermode=count -coverprofile=${COVER_DIR}cov_u13.out ./plugins/policy/cache/namespaceidx -tags="${GO_BUILD_TAGS}"
go test -covermode=count -coverprofile=${COVER_DIR}cov_u14.out ./plugins/policy/cache/podidx -tags="${GO_BUILD_TAGS}"
go test -covermode=count -coverprofile=${COVER_DIR}cov_u15.out ./plugins/policy/cache/policyidx -tags="${GO_BUILD_TAGS}"
go test -covermode=count -coverprofile=${COVER_DIR}cov_u16.out ./plugins/statscollector -tags="${GO_BUILD_TAGS}"
go test -covermode=count -coverprofile=${COVER_DIR}cov_u17.out ./plugins/crd/datastore -tags="${GO_BUILD_TAGS}"
go test -covermode=count -coverprofile=${COVER_DIR}cov_u18.out ./plugins/crd/validator/l2 -tags="${GO_BUILD_TAGS}"
go test -covermode=count -coverprofile=${COVER_DIR}cov_u19.out ./plugins/crd/validator/l3 -tags="${GO_BUILD_TAGS}"
#go test -covermode=count -coverprofile=${COVER_DIR}cov_u20.out ./plugins/crd/cache -tags="${GO_BUILD_TAGS}"
@echo "# merging coverage results"
gocovmerge \
${COVER_DIR}cov_u1.out \
${COVER_DIR}cov_u2.out \
${COVER_DIR}cov_u3.out \
${COVER_DIR}cov_u6.out \
${COVER_DIR}cov_u7.out \
${COVER_DIR}cov_u8.out \
${COVER_DIR}cov_u9.out \
${COVER_DIR}cov_u10.out \
${COVER_DIR}cov_u11.out \
${COVER_DIR}cov_u12.out \
${COVER_DIR}cov_u13.out \
${COVER_DIR}cov_u14.out \
${COVER_DIR}cov_u15.out \
${COVER_DIR}cov_u16.out \
${COVER_DIR}cov_u17.out \
${COVER_DIR}cov_u18.out \
${COVER_DIR}cov_u19.out \
> ${COVER_DIR}coverage.out
@echo "# coverage data generated into ${COVER_DIR}coverage.out"
# Run coverage report with HTML output
test-cover-html: test-cover
go tool cover -html=${COVER_DIR}coverage.out -o ${COVER_DIR}coverage.html
@echo "# coverage report generated into ${COVER_DIR}coverage.html"
# Run coverage report with XML output
test-cover-xml: test-cover
gocov convert ${COVER_DIR}coverage.out | gocov-xml > ${COVER_DIR}coverage.xml
@echo "# coverage report generated into ${COVER_DIR}coverage.xml"
# Get generator tools
get-generators:
go install -mod=readonly github.com/golang/protobuf/protoc-gen-go
# Generate sources
generate: get-generators
@echo "# generating sources"
cd plugins/nodesync && go generate
cd plugins/ipam && go generate
cd plugins/podmanager && go generate
cd plugins/ksr && go generate
cd cmd/contiv-stn && go generate
cd plugins/crd/handler/nodeconfig && go generate
cd plugins/crd/handler/servicefunctionchain && go generate
cd plugins/crd/handler/customnetwork && go generate
cd plugins/crd/handler/externalinterface && go generate
# Get linter tools
get-linters:
@echo " => installing linters"
go get -v golang.org/x/lint/golint
pip install --user yamllint
curl https://raw.githubusercontent.com/helm/helm/master/scripts/get | bash
# Run code analysis
lint:
@echo "# running code analysis"
./scripts/golint.sh
./scripts/govet.sh
# Run YAML lint tool
lint-yaml:
@echo "# running YAML lint"
yamllint --strict --config-file=.yamllint.yml .
# Run HELM lint tool
lint-helm:
@echo "# running HELM lint"
helm lint k8s/contiv-vpp/
helm lint k8s/contiv-vpp-ui/
# Check if manifest YAMLs need to be re-generated
check-manifests:
@echo "Checking manifest YAMLs"
./scripts/check_manifests.sh
# Run metalinter tool
metalinter:
docker build -t vpp_metalinter -f ./docker/development/Dockerfile.metalinter .
docker run --rm vpp_metalinter
# Format code
format:
@echo "# formatting the code"
./scripts/gofmt.sh
# Check if the files are go formatted
check-format:
@echo "# checking go fmt"
./scripts/check_fmt.sh
LINKCHECK := $(shell command -v markdown-link-check 2> /dev/null)
# Get link check tool
get-linkcheck:
ifndef LINKCHECK
sudo apt-get update && sudo apt-get install npm
npm install -g [email protected]
endif
# Validate links in markdown files
check-links: get-linkcheck
./scripts/check_links.sh
# Install Go dependencies
dep-install:
@echo "# downloading Go dependencies"
go mod download
# Update Go dependencies
dep-update:
@echo "# updating Go dependencies"
go mod tidy
dep-check:
@echo "# verifying dependencies"
go mod verify
@if ! git diff --quiet go.mod ; then \
echo "check failed"; \
exit 1 ; \
fi
describe:
./scripts/contiv_describe.sh
docker-images:
cd docker && ./build-all.sh -s
cd docker && ./push-all.sh -s
docker-dev: contiv-agent contiv-init
cd docker/development && ./build.sh
vagrant-images:
cd docker && ./save.sh -s
generate-crd:
plugins/crd/controller/update-codegen.sh
generate-manifest:
helm template k8s/contiv-vpp/ > k8s/contiv-vpp.yaml
generate-manifest-arm64:
helm template k8s/contiv-vpp -f k8s/contiv-vpp/values-arm64.yaml,k8s/contiv-vpp/values.yaml > k8s/contiv-vpp-arm64.yaml
helm-package:
helm package k8s/contiv-vpp/
helm-yaml-latest:
helm template k8s/contiv-vpp/ -f k8s/contiv-vpp/values.yaml,k8s/contiv-vpp/values-latest.yaml > k8s/contiv-vpp.yaml
helm-yaml-arm64-latest:
helm template k8s/contiv-vpp -f k8s/contiv-vpp/values-arm64.yaml,k8s/contiv-vpp/values.yaml,k8s/contiv-vpp/values-latest.yaml > k8s/contiv-vpp-arm64.yaml
# starts dev version of UI accessible at localhost:4200 CORS check must be turned off
run-debug-ui:
cd ui && npm install && node_modules/@angular/cli/bin/ng serve --host 0.0.0.0
.PHONY: build all \
install clean test test-race \
get-covtools test-cover test-cover-html test-cover-xml \
get-generators generate \
get-linters lint metalinter lint-yaml lint-helm format check-format \
get-linkcheck check-links \
dep-install \
docker-images docker-dev vagrant-images\
describe generate-manifest helm-package helm-yaml \
generate-manifest-arm64 helm-yaml-arm64 run-debug-ui