forked from contiv/netplugin
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Makefile
executable file
·340 lines (269 loc) · 13.5 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
.PHONY: all all-CI build clean default unit-test release tar checks go-version gofmt-src golint-src govet-src
DEFAULT_DOCKER_VERSION := 1.12.6
SHELL := /bin/bash
EXCLUDE_DIRS := bin docs Godeps scripts test vagrant vendor install
PKG_DIRS := $(filter-out $(EXCLUDE_DIRS),$(subst /,,$(sort $(dir $(wildcard */)))))
TO_BUILD := ./netplugin/ ./netmaster/ ./netctl/netctl/ ./mgmtfn/k8splugin/contivk8s/ ./mgmtfn/mesosplugin/netcontiv/
HOST_GOBIN := `if [ -n "$$(go env GOBIN)" ]; then go env GOBIN; else dirname $$(which go); fi`
HOST_GOROOT := `go env GOROOT`
NAME := netplugin
# We are using date based versioning, so for consistent version during a build
# we evaluate and set the value of version once in a file and use it in 'tar'
# and 'release' targets.
VERSION_FILE := $(NAME)-version
VERSION := `cat $(VERSION_FILE)`
TAR_EXT := tar.bz2
TAR_FILENAME := $(NAME)-$(VERSION).$(TAR_EXT)
TAR_LOC := .
TAR_FILE := $(TAR_LOC)/$(TAR_FILENAME)
GO_MIN_VERSION := 1.7
GO_MAX_VERSION := 1.8
GO_VERSION := $(shell go version | cut -d' ' -f3 | sed 's/go//')
GOLINT_CMD := golint -set_exit_status
GOFMT_CMD := gofmt -s -l
GOVET_CMD := go tool vet
CI_HOST_TARGETS ?= "host-unit-test host-integ-test host-build-docker-image"
SYSTEM_TESTS_TO_RUN ?= "00SSH|Basic|Network|Policy|TestTrigger|ACIM|Netprofile"
ACI_GW_IMAGE ?= "contiv/aci-gw:04-12-2017.2.2_1n"
all: build unit-test system-test ubuntu-tests
# 'all-CI' target is used by the scripts/CI.sh that passes appropriate set of
# ENV variables (from the jenkins job) to run OS (centos, ubuntu etc) and
# sandbox specific(vagrant, docker-in-docker)
all-CI: stop clean start
make ssh-build
vagrant ssh netplugin-node1 -c 'sudo -i bash -lc "source /etc/profile.d/envvar.sh \
&& cd /opt/gopath/src/github.com/contiv/netplugin \
&& make ${CI_HOST_TARGETS}"'
ifdef SKIP_SYSTEM_TEST
echo "Skipping system tests"
else
make system-test
endif
test: build unit-test system-test ubuntu-tests
default: build
deps:
./scripts/deps
godep-save:
rm -rf vendor Godeps
godep save ./...
godep-restore:
godep restore ./...
gofmt-src:
$(info +++ gofmt $(PKG_DIRS))
@for dir in $(PKG_DIRS); do $(GOFMT_CMD) $${dir} | grep "go"; [[ $$? -ne 0 ]] || exit 1; done
golint-src:
$(info +++ golint $(PKG_DIRS))
@for dir in $(PKG_DIRS); do $(GOLINT_CMD) $${dir}/... || exit 1;done
govet-src:
$(info +++ govet $(PKG_DIRS))
@for dir in $(PKG_DIRS); do $(GOVET_CMD) $${dir} || exit 1;done
misspell-src:
$(info +++ check spelling $(PKG_DIRS))
misspell -locale US -error $(PKG_DIRS)
go-version:
$(info +++ check go version)
ifneq ($(GO_VERSION), $(lastword $(sort $(GO_VERSION) $(GO_MIN_VERSION))))
$(error go version check failed, expected >= $(GO_MIN_VERSION), found $(GO_VERSION))
endif
ifneq ($(GO_VERSION), $(firstword $(sort $(GO_VERSION) $(GO_MAX_VERSION))))
$(error go version check failed, expected <= $(GO_MAX_VERSION), found $(GO_VERSION))
endif
checks: go-version gofmt-src golint-src govet-src misspell-src
run-build: deps checks clean
cd $(GOPATH)/src/github.com/contiv/netplugin && \
USE_RELEASE=${USE_RELEASE} BUILD_VERSION=${BUILD_VERSION} \
TO_BUILD="${TO_BUILD}" VERSION_FILE=${VERSION_FILE} \
scripts/build.sh
build-docker-image: start
vagrant ssh netplugin-node1 -c 'bash -lc "source /etc/profile.d/envvar.sh && cd /opt/gopath/src/github.com/contiv/netplugin && make host-build-docker-image"'
ifdef NET_CONTAINER_BUILD
install-shell-completion:
cp scripts/contrib/completion/bash/netctl /etc/bash_completion.d/netctl
else
install-shell-completion:
sudo cp scripts/contrib/completion/bash/netctl /etc/bash_completion.d/netctl
endif
build: start ssh-build stop
clean: deps
rm -rf $(GOPATH)/pkg/*/github.com/contiv/netplugin/
go clean -i -v ./...
update:
vagrant box update
# setting CONTIV_NODES=<number> while calling 'make demo' can be used to bring
# up a cluster of <number> nodes. By default <number> = 1
ifdef NET_CONTAINER_BUILD
start:
else
start:
CONTIV_DOCKER_VERSION="$${CONTIV_DOCKER_VERSION:-$(DEFAULT_DOCKER_VERSION)}" CONTIV_NODE_OS=${CONTIV_NODE_OS} vagrant up
endif
# ===================================================================
#kubernetes demo targets
k8s-demo:
cd vagrant/k8s/ && ./copy_demo.sh
k8s-demo-start:
cd vagrant/k8s/ && ./restart_cluster.sh && vagrant ssh k8master
# ===================================================================
# kubernetes cluster bringup/cleanup targets
k8s-legacy-cluster:
cd vagrant/k8s/ && ./setup_cluster.sh
k8s-cluster:
cd vagrant/k8s/ && CONTIV_K8S_USE_KUBEADM=1 ./setup_cluster.sh
k8s-l3-cluster:
CONTIV_L3=1 make k8s-cluster
k8s-destroy:
cd vagrant/k8s/ && vagrant destroy -f
k8s-l3-destroy:
cd vagrant/k8s/ && CONTIV_L3=1 vagrant destroy -f
# ===================================================================
# kubernetes test targets
k8s-legacy-test:
export CONTIV_K8S_LEGACY=1 && \
make k8s-sanity-cluster && \
cd vagrant/k8s/ && vagrant ssh k8master -c 'bash -lc "cd /opt/gopath/src/github.com/contiv/netplugin && make run-build"' && \
./start_sanity_service.sh
cd $(GOPATH)/src/github.com/contiv/netplugin/scripts/python && PYTHONIOENCODING=utf-8 ./createcfg.py -scheduler 'k8s'
CONTIV_K8S_LEGACY=1 CONTIV_NODES=3 go test -v -timeout 540m ./test/systemtests -check.v -check.abort -check.f "00SSH|TestBasic|TestNetwork|ACID|TestPolicy|TestTrigger"
cd vagrant/k8s && vagrant destroy -f
k8s-test: k8s-cluster
cd vagrant/k8s/ && vagrant ssh k8master -c 'bash -lc "cd /opt/gopath/src/github.com/contiv/netplugin && make run-build"'
cd $(GOPATH)/src/github.com/contiv/netplugin/scripts/python && PYTHONIOENCODING=utf-8 ./createcfg.py -scheduler 'k8s' -binpath contiv/bin -install_mode 'kubeadm'
CONTIV_K8S_USE_KUBEADM=1 CONTIV_NODES=3 go test -v -timeout 540m ./test/systemtests -check.v -check.abort -check.f "00SSH|TestBasic|TestNetwork|TestPolicy"
cd vagrant/k8s && vagrant destroy -f
k8s-l3-test: k8s-l3-cluster
cd vagrant/k8s/ && vagrant ssh k8master -c 'bash -lc "cd /opt/gopath/src/github.com/contiv/netplugin && make run-build"'
cd $(GOPATH)/src/github.com/contiv/netplugin/scripts/python && PYTHONIOENCODING=utf-8 ./createcfg.py -scheduler 'k8s' -binpath contiv/bin -install_mode 'kubeadm' -contiv_l3=1
CONTIV_K8S_USE_KUBEADM=1 CONTIV_NODES=3 go test -v -timeout 540m ./test/systemtests -check.v -check.abort -check.f "00SSH|TestBasic|TestNetwork|TestPolicy"
cd vagrant/k8s && CONTIV_L3=1 vagrant destroy -f
# ===================================================================
# Mesos demo targets
mesos-docker-demo:
cd vagrant/mesos-docker && \
vagrant up && \
vagrant ssh node1 -c 'bash -lc "source /etc/profile.d/envvar.sh && cd /opt/gopath/src/github.com/contiv/netplugin && make run-build"' && \
vagrant ssh node1 -c 'bash -lc "source /etc/profile.d/envvar.sh && cd /opt/gopath/src/github.com/contiv/netplugin && ./scripts/python/startPlugin.py -nodes 192.168.33.10,192.168.33.11"'
mesos-docker-destroy:
cd vagrant/mesos-docker && vagrant destroy -f
nomad-docker:
cd vagrant/nomad-docker && vagrant up
VAGRANT_CWD=./vagrant/nomad-docker/ vagrant ssh netplugin-node1 -c 'bash -lc "source /etc/profile.d/envvar.sh && cd /opt/gopath/src/github.com/contiv/netplugin && make host-restart"'
mesos-cni-demo:
$(MAKE) -C vagrant/mesos-cni $@
mesos-cni-destroy:
$(MAKE) -C vagrant/mesos-cni $@
demo-ubuntu:
CONTIV_NODE_OS=ubuntu make demo
ifdef NET_CONTAINER_BUILD
stop:
else
stop:
CONTIV_NODES=$${CONTIV_NODES:-3} vagrant destroy -f
endif
demo: ssh-build
vagrant ssh netplugin-node1 -c 'bash -lc "source /etc/profile.d/envvar.sh && cd /opt/gopath/src/github.com/contiv/netplugin && make host-restart host-swarm-restart"'
ssh:
@vagrant ssh netplugin-node1 -c 'bash -lc "cd /opt/gopath/src/github.com/contiv/netplugin/ && bash"' || echo 'Please run "make demo"'
ifdef NET_CONTAINER_BUILD
ssh-build:
cd /go/src/github.com/contiv/netplugin && make run-build install-shell-completion
else
ssh-build: start
vagrant ssh netplugin-node1 -c 'bash -lc "source /etc/profile.d/envvar.sh && cd /opt/gopath/src/github.com/contiv/netplugin && make run-build install-shell-completion"'
endif
unit-test: stop clean
./scripts/unittests -vagrant
integ-test: stop clean start ssh-build
vagrant ssh netplugin-node1 -c 'sudo -i bash -lc "source /etc/profile.d/envvar.sh && cd /opt/gopath/src/github.com/contiv/netplugin && make host-integ-test"'
ubuntu-tests:
CONTIV_NODE_OS=ubuntu make clean build unit-test system-test stop
system-test:start
cd $(GOPATH)/src/github.com/contiv/netplugin/scripts/python && PYTHONIOENCODING=utf-8 ./createcfg.py
go test -v -timeout 480m ./test/systemtests -check.v -check.abort -check.f $(SYSTEM_TESTS_TO_RUN)
l3-test:
CONTIV_L3=2 CONTIV_NODES=3 make stop start ssh-build
cd $(GOPATH)/src/github.com/contiv/netplugin/scripts/python && PYTHONIOENCODING=utf-8 ./createcfg.py -contiv_l3 2
CONTIV_L3=2 CONTIV_NODES=3 go test -v -timeout 900m ./test/systemtests -check.v -check.abort
CONTIV_L3=2 CONTIV_NODES=3 make stop
#l3-demo setup for docker/swarm
l3-demo: demo
vagrant ssh netplugin-node1 -c 'netctl global set --fwd-mode routing'
l3bgp-demo:
CONTIV_L3=1 CONTIV_NODES=3 vagrant up
make ssh-build
vagrant ssh netplugin-node1 -c 'sudo -i bash -lc "cd /opt/gopath/src/github.com/contiv/netplugin && make host-restart"'
vagrant ssh netplugin-node1 -c 'sh /opt/gopath/src/github.com/contiv/netplugin/scripts/l3bgp_demo.sh'
host-build:
@echo "dev: making binaries..."
/bin/bash -c 'source /etc/profile.d/envvar.sh; make run-build'
host-unit-test:
@echo dev: running unit tests...
cd $(GOPATH)/src/github.com/contiv/netplugin && sudo -E PATH=$(PATH) scripts/unittests
host-unit-test-coverage:
@echo dev: running unit tests...
cd $(GOPATH)/src/github.com/contiv/netplugin && sudo -E PATH=$(PATH) scripts/unittests --coverage-basic
host-unit-test-coverage-detail:
@echo dev: running unit tests...
cd $(GOPATH)/src/github.com/contiv/netplugin && sudo -E PATH=$(PATH) scripts/unittests --coverage-detail
host-integ-test: host-cleanup start-aci-gw
@echo dev: running integration tests...
sudo -E /usr/local/go/bin/go test -v -timeout 20m ./test/integration/ -check.v -encap vlan -fwd-mode bridge
sudo -E /usr/local/go/bin/go test -v -timeout 20m ./test/integration/ -check.v -encap vxlan -fwd-mode bridge
sudo -E /usr/local/go/bin/go test -v -timeout 20m ./test/integration/ -check.v -encap vxlan -fwd-mode routing
sudo -E /usr/local/go/bin/go test -v -timeout 20m ./test/integration/ -check.v -check.f "AppProfile" -encap vlan -fwd-mode bridge --fabric-mode aci
start-aci-gw:
@echo dev: starting aci gw...
docker pull $(ACI_GW_IMAGE)
docker run --net=host -itd -e "APIC_URL=SANITY" -e "APIC_USERNAME=IGNORE" -e "APIC_PASSWORD=IGNORE" --name=contiv-aci-gw $(ACI_GW_IMAGE)
host-build-docker-image:
./scripts/netContain/build_image.sh
host-cleanup:
@echo dev: cleaning up services...
cd $(GOPATH)/src/github.com/contiv/netplugin/scripts/python && PYTHONIOENCODING=utf-8 ./cleanup.py -nodes ${CLUSTER_NODE_IPS}
host-swarm-restart:
@echo dev: restarting swarm ...
cd $(GOPATH)/src/github.com/contiv/netplugin/scripts/python && PYTHONIOENCODING=utf-8 ./startSwarm.py -nodes ${CLUSTER_NODE_IPS} -swarm ${CONTIV_DOCKER_SWARM}
host-restart:
@echo dev: restarting services...
cd $(GOPATH)/src/github.com/contiv/netplugin/scripts/python && PYTHONIOENCODING=utf-8 ./startPlugin.py -nodes ${CLUSTER_NODE_IPS}
# create the rootfs for v2plugin. this is required for docker plugin create command
host-pluginfs-create:
@echo dev: creating a docker v2plugin rootfs ...
sh scripts/v2plugin_rootfs.sh
# if rootfs already exists, copy newly compiled contiv binaries and start plugin on local host
host-plugin-update:
@echo dev: updating docker v2plugin ...
docker plugin disable ${CONTIV_V2PLUGIN_NAME}
docker plugin rm -f ${CONTIV_V2PLUGIN_NAME}
cp bin/netplugin bin/netmaster bin/netctl install/v2plugin/rootfs
docker plugin create ${CONTIV_V2PLUGIN_NAME} install/v2plugin
docker plugin enable ${CONTIV_V2PLUGIN_NAME}
# cleanup all containers, plugins and start the v2plugin on all hosts
host-plugin-restart:
@echo dev: restarting services...
cp bin/netplugin bin/netmaster bin/netctl install/v2plugin/rootfs
cd $(GOPATH)/src/github.com/contiv/netplugin/scripts/python && PYTHONIOENCODING=utf-8 ./startPlugin.py -nodes ${CLUSTER_NODE_IPS} -plugintype "v2plugin"
# complete workflow to create rootfs, create/enable plugin and start swarm-mode
demo-v2plugin:
CONTIV_V2PLUGIN_NAME="$${CONTIV_V2PLUGIN_NAME:-contiv/v2plugin:0.1}" CONTIV_DOCKER_VERSION="$${CONTIV_DOCKER_VERSION:-1.13.1}" CONTIV_DOCKER_SWARM="$${CONTIV_DOCKER_SWARM:-swarm_mode}" make ssh-build
vagrant ssh netplugin-node1 -c 'bash -lc "source /etc/profile.d/envvar.sh && cd /opt/gopath/src/github.com/contiv/netplugin && make host-pluginfs-create host-plugin-restart host-swarm-restart"'
# release a v2 plugin
host-plugin-release:
@echo dev: creating a docker v2plugin ...
sh scripts/v2plugin_rootfs.sh
docker plugin create ${CONTIV_V2PLUGIN_NAME} install/v2plugin
@echo dev: pushing ${CONTIV_V2PLUGIN_NAME} to docker hub
@echo dev: (need docker login with user in contiv org)
docker plugin push ${CONTIV_V2PLUGIN_NAME}
only-tar:
tar: clean-tar
CONTIV_NODES=1 ${MAKE} build
@tar -jcf $(TAR_FILE) -C $(GOPATH)/src/github.com/contiv/netplugin/bin netplugin netmaster netctl contivk8s netcontiv -C $(GOPATH)/src/github.com/contiv/netplugin/scripts contrib/completion/bash/netctl -C $(GOPATH)/src/github.com/contiv/netplugin/scripts get-contiv-diags
clean-tar:
@rm -f $(TAR_LOC)/*.$(TAR_EXT)
@rm -f ${VERSION_FILE}
# GITHUB_USER and GITHUB_TOKEN are needed be set to run github-release
release: tar
TAR_FILENAME=$(TAR_FILENAME) TAR_FILE=$(TAR_FILE) VERSION=$(VERSION) \
OLD_VERSION=${OLD_VERSION} BUILD_VERSION=${BUILD_VERSION} \
USE_RELEASE=${USE_RELEASE} scripts/release.sh
@make clean-tar