forked from projectcalico/calicoctl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile.calico-node
357 lines (312 loc) · 14.3 KB
/
Makefile.calico-node
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
# Include the build file for calico/node (This also pulls in Makefile.calicoctl)
include Makefile.calicoctl
# we can use "custom" build image and test image name
SYSTEMTEST_CONTAINER?=calico/test:$(SYSTEMTEST_CONTAINER_VER)
# calicoctl and calico/node current share a single version - this is it.
CALICOCONTAINERS_VERSION?=$(shell git describe --tags --dirty --always)
###############################################################################
# Subcomponent versions:
BIRD_VER := v0.2.2-alpha1
GOBGPD_VER := v0.1.2
FELIX_VER := 2.1.0
LIBNETWORK_PLUGIN_VER := v1.1.0
CONFD_VER := v0.10.0-scale
SYSTEMTEST_CONTAINER_VER := latest
###############################################################################
# URL for Calico binaries
# confd binary
CONFD_URL?=https://github.com/projectcalico/confd/releases/download/$(CONFD_VER)/confd.static
# bird binaries
BIRD_URL?=https://github.com/projectcalico/calico-bird/releases/download/$(BIRD_VER)/bird
BIRD6_URL?=https://github.com/projectcalico/calico-bird/releases/download/$(BIRD_VER)/bird6
BIRDCL_URL?=https://github.com/projectcalico/calico-bird/releases/download/$(BIRD_VER)/birdcl
CALICO_BGP_DAEMON_URL?=https://github.com/projectcalico/calico-bgp-daemon/releases/download/$(GOBGPD_VER)/calico-bgp-daemon
GOBGP_URL?=https://github.com/projectcalico/calico-bgp-daemon/releases/download/$(GOBGPD_VER)/gobgp
###############################################################################
# calico/node build. Contains the following areas
# - Populate the calico_node/filesystem
# - Build the container itself
###############################################################################
NODE_CONTAINER_DIR=calico_node
NODE_CONTAINER_NAME?=calico/node
NODE_CONTAINER_FILES=$(shell find $(NODE_CONTAINER_DIR)/filesystem -type f)
NODE_CONTAINER_CREATED=$(NODE_CONTAINER_DIR)/.calico_node.created
NODE_CONTAINER_BIN_DIR=$(NODE_CONTAINER_DIR)/filesystem/bin
NODE_CONTAINER_BINARIES=startup allocate-ipip-addr calico-felix bird calico-bgp-daemon confd libnetwork-plugin
FELIX_CONTAINER_NAME?=calico/felix:$(FELIX_VER)
LIBNETWORK_PLUGIN_CONTAINER_NAME?=calico/libnetwork-plugin:$(LIBNETWORK_PLUGIN_VER)
STARTUP_DIR=$(NODE_CONTAINER_DIR)/startup
STARTUP_FILES=$(shell find $(STARTUP_DIR) -name '*.go')
ALLOCATE_IPIP_DIR=$(NODE_CONTAINER_DIR)/allocateipip
ALLOCATE_IPIP_FILES=$(shell find $(ALLOCATE_IPIP_DIR) -name '*.go')
TEST_CONTAINER_NAME?=calico/test:latest
TEST_CONTAINER_FILES=$(shell find tests/ -type f ! -name '*.created')
test_image: calico_test.created ## Create the calico/test image
calico_test.created: $(TEST_CONTAINER_FILES)
cd calico_test && docker build -f Dockerfile.calico_test -t $(TEST_CONTAINER_NAME) .
touch calico_test.created
calico/node: $(NODE_CONTAINER_CREATED) ## Create the calico/node image
calico-node.tar: $(NODE_CONTAINER_CREATED)
docker save --output $@ $(NODE_CONTAINER_NAME)
# Build ACI (the APPC image file format) of calico/node.
# Requires docker2aci installed on host: https://github.com/appc/docker2aci
calico-node-latest.aci: calico-node.tar
docker2aci $<
# Build calico/node docker image - explicitly depend on the container binaries.
$(NODE_CONTAINER_CREATED): $(NODE_CONTAINER_DIR)/Dockerfile $(NODE_CONTAINER_FILES) $(addprefix $(NODE_CONTAINER_BIN_DIR)/,$(NODE_CONTAINER_BINARIES))
docker build -t $(NODE_CONTAINER_NAME) $(NODE_CONTAINER_DIR)
touch $@
# Get felix binaries
.PHONY: update-felix
$(NODE_CONTAINER_BIN_DIR)/calico-felix update-felix:
-docker rm -f calico-felix
# Latest felix binaries are stored in automated builds of calico/felix.
# To get them, we create (but don't start) a container from that image.
docker create --name calico-felix $(FELIX_CONTAINER_NAME)
# Then we copy the files out of the container. Since docker preserves
# mtimes on its copy, check the file really did appear, then touch it
# to make sure that downstream targets get rebuilt.
docker cp calico-felix:/code/. $(NODE_CONTAINER_BIN_DIR) && \
test -e $(NODE_CONTAINER_BIN_DIR)/calico-felix && \
touch $(NODE_CONTAINER_BIN_DIR)/calico-felix
-docker rm -f calico-felix
# Get libnetwork-plugin binaries
$(NODE_CONTAINER_BIN_DIR)/libnetwork-plugin:
-docker rm -f calico-$(@F)
# Latest libnetwork-plugin binaries are stored in automated builds of calico/libnetwork-plugin.
# To get them, we pull that image, then copy the binaries out to our host
docker create --name calico-$(@F) $(LIBNETWORK_PLUGIN_CONTAINER_NAME)
docker cp calico-$(@F):/$(@F) $(@D)
-docker rm -f calico-$(@F)
# Get the confd binary
$(NODE_CONTAINER_BIN_DIR)/confd:
$(CURL) -L $(CONFD_URL) -o $@
chmod +x $@
# Get the calico-bgp-daemon binary
$(NODE_CONTAINER_BIN_DIR)/calico-bgp-daemon:
$(CURL) -L $(GOBGP_URL) -o $(@D)/gobgp
$(CURL) -L $(CALICO_BGP_DAEMON_URL) -o $@
chmod +x $(@D)/*
# Get bird binaries
$(NODE_CONTAINER_BIN_DIR)/bird:
# This make target actually downloads the bird6 and birdcl binaries too
# Copy patched BIRD daemon with tunnel support.
$(CURL) -L $(BIRD6_URL) -o $(@D)/bird6
$(CURL) -L $(BIRDCL_URL) -o $(@D)/birdcl
$(CURL) -L $(BIRD_URL) -o $@
chmod +x $(@D)/*
$(NODE_CONTAINER_BIN_DIR)/startup: dist/startup
mkdir -p $(NODE_CONTAINER_BIN_DIR)
cp dist/startup $(NODE_CONTAINER_BIN_DIR)/startup
$(NODE_CONTAINER_BIN_DIR)/allocate-ipip-addr: dist/allocate-ipip-addr
mkdir -p $(NODE_CONTAINER_BIN_DIR)
cp dist/allocate-ipip-addr $(NODE_CONTAINER_BIN_DIR)/allocate-ipip-addr
## Build startup.go
startup:
GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -v -i -o dist/startup $(LDFLAGS) "./calico_node/startup/startup.go"
dist/startup: $(STARTUP_FILES) vendor
mkdir -p dist
mkdir -p .go-pkg-cache
docker run --rm \
-e LOCAL_USER_ID=$(LOCAL_USER_ID) \
-v $(CURDIR)/.go-pkg-cache:/go/pkg/:rw \
-v $(CURDIR):/go/src/$(PACKAGE_NAME):ro \
-v $(CURDIR)/dist:/go/src/$(PACKAGE_NAME)/dist \
$(CALICO_BUILD) sh -c '\
cd /go/src/$(PACKAGE_NAME) && \
make startup'
## Build allocate_ipip_addr.go
allocate-ipip-addr:
GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -v -i -o dist/allocate-ipip-addr $(LDFLAGS) "./calico_node/allocateipip/allocate_ipip_addr.go"
dist/allocate-ipip-addr: $(ALLOCATE_IPIP_FILES) vendor
mkdir -p dist
mkdir -p .go-pkg-cache
docker run --rm \
-e LOCAL_USER_ID=$(LOCAL_USER_ID) \
-v $(CURDIR)/.go-pkg-cache:/go/pkg/:rw \
-v $(CURDIR):/go/src/$(PACKAGE_NAME):ro \
-v $(CURDIR)/dist:/go/src/$(PACKAGE_NAME)/dist \
$(CALICO_BUILD) sh -c '\
cd /go/src/$(PACKAGE_NAME) && \
make allocate-ipip-addr'
###############################################################################
# Tests
# - Support for running etcd (both securely and insecurely)
# - Running UTs and STs
###############################################################################
# These variables can be overridden by setting an environment variable.
###############################################################################
# Common build variables
# Path to the sources.
# Default value: directory with Makefile
SOURCE_DIR?=$(dir $(lastword $(MAKEFILE_LIST)))
SOURCE_DIR:=$(abspath $(SOURCE_DIR))
LOCAL_IP_ENV?=$(shell ip route get 8.8.8.8 | head -1 | awk '{print $$7}')
ST_TO_RUN?=tests/st/
# Can exclude the slower tests with "-a '!slow'"
ST_OPTIONS?=
HOST_CHECKOUT_DIR?=$(shell pwd)
# curl should failed on 404
CURL=curl -sSf
## Generate the keys and certificates for running etcd with SSL.
ssl-certs: certs/.certificates.created ## Generate self-signed SSL certificates
certs/.certificates.created:
mkdir -p certs
$(CURL) -L "https://github.com/projectcalico/cfssl/releases/download/1.2.1/cfssl" -o certs/cfssl
$(CURL) -L "https://github.com/projectcalico/cfssl/releases/download/1.2.1/cfssljson" -o certs/cfssljson
chmod a+x certs/cfssl
chmod a+x certs/cfssljson
certs/cfssl gencert -initca tests/st/ssl-config/ca-csr.json | certs/cfssljson -bare certs/ca
certs/cfssl gencert \
-ca certs/ca.pem \
-ca-key certs/ca-key.pem \
-config tests/st/ssl-config/ca-config.json \
tests/st/ssl-config/req-csr.json | certs/cfssljson -bare certs/client
certs/cfssl gencert \
-ca certs/ca.pem \
-ca-key certs/ca-key.pem \
-config tests/st/ssl-config/ca-config.json \
tests/st/ssl-config/req-csr.json | certs/cfssljson -bare certs/server
touch certs/.certificates.created
busybox.tar:
docker pull busybox:latest
docker save --output busybox.tar busybox:latest
routereflector.tar:
docker pull calico/routereflector:latest
docker save --output routereflector.tar calico/routereflector:latest
workload.tar:
cd workload && docker build -t workload .
docker save --output workload.tar workload
stop-etcd:
@-docker rm -f calico-etcd calico-etcd-ssl
.PHONY: run-etcd-ssl
## Run etcd in a container with SSL verification. Used primarily by STs.
run-etcd-ssl: certs/.certificates.created add-ssl-hostname
$(MAKE) stop-etcd
docker run --detach \
--net=host \
-v $(SOURCE_DIR)/certs:/etc/calico/certs \
--name calico-etcd-ssl quay.io/coreos/etcd \
etcd \
--cert-file "/etc/calico/certs/server.pem" \
--key-file "/etc/calico/certs/server-key.pem" \
--trusted-ca-file "/etc/calico/certs/ca.pem" \
--advertise-client-urls "https://etcd-authority-ssl:2379,https://localhost:2379" \
--listen-client-urls "https://0.0.0.0:2379"
IPT_ALLOW_ETCD:=-A INPUT -i docker0 -p tcp --dport 2379 -m comment --comment "calico-st-allow-etcd" -j ACCEPT
.PHONY: st-checks
st-checks:
# Check that we're running as root.
test `id -u` -eq '0' || { echo "STs must be run as root to allow writes to /proc"; false; }
# Insert an iptables rule to allow access from our test containers to etcd
# running on the host.
iptables-save | grep -q 'calico-st-allow-etcd' || iptables $(IPT_ALLOW_ETCD)
## Run the STs in a container
.PHONY: st
st: dist/calicoctl dist/calicoctl-v1.0.2 busybox.tar routereflector.tar calico-node.tar workload.tar run-etcd-host calico_test.created
# Use the host, PID and network namespaces from the host.
# Privileged is needed since 'calico node' write to /proc (to enable ip_forwarding)
# Map the docker socket in so docker can be used from inside the container
# HOST_CHECKOUT_DIR is used for volume mounts on containers started by this one.
# All of code under test is mounted into the container.
# - This also provides access to calicoctl and the docker client
# $(MAKE) st-checks
docker run --uts=host \
--pid=host \
--net=host \
--privileged \
-e HOST_CHECKOUT_DIR=$(HOST_CHECKOUT_DIR) \
-e DEBUG_FAILURES=$(DEBUG_FAILURES) \
-e MY_IP=$(LOCAL_IP_ENV) \
-e NODE_CONTAINER_NAME=$(NODE_CONTAINER_NAME) \
--rm -ti \
-v /var/run/docker.sock:/var/run/docker.sock \
-v $(SOURCE_DIR):/code \
$(SYSTEMTEST_CONTAINER) \
sh -c 'nosetests $(ST_TO_RUN) -sv --nologcapture --with-xunit --xunit-file="/code/nosetests.xml" --with-timer $(ST_OPTIONS)'
$(MAKE) stop-etcd
## Run the STs in a container using etcd with SSL certificate/key/CA verification.
.PHONY: st-ssl
st-ssl: run-etcd-ssl dist/calicoctl busybox.tar calico-node.tar routereflector.tar workload.tar calico_test.created
# Use the host, PID and network namespaces from the host.
# Privileged is needed since 'calico node' write to /proc (to enable ip_forwarding)
# Map the docker socket in so docker can be used from inside the container
# HOST_CHECKOUT_DIR is used for volume mounts on containers started by this one.
# All of code under test is mounted into the container.
# - This also provides access to calicoctl and the docker client
# Mount the full path to the etcd certs directory.
# - docker copies this directory directly from the host, but the
# calicoctl node command reads the files from the test container
$(MAKE) st-checks
docker run --uts=host \
--pid=host \
--net=host \
--privileged \
-e HOST_CHECKOUT_DIR=$(HOST_CHECKOUT_DIR) \
-e DEBUG_FAILURES=$(DEBUG_FAILURES) \
-e MY_IP=$(LOCAL_IP_ENV) \
-e NODE_CONTAINER_NAME=$(NODE_CONTAINER_NAME) \
-e ETCD_SCHEME=https \
-e ETCD_CA_CERT_FILE=$(SOURCE_DIR)/certs/ca.pem \
-e ETCD_CERT_FILE=$(SOURCE_DIR)/certs/client.pem \
-e ETCD_KEY_FILE=$(SOURCE_DIR)/certs/client-key.pem \
--rm -ti \
-v /var/run/docker.sock:/var/run/docker.sock \
-v $(SOURCE_DIR):/code \
-v $(SOURCE_DIR)/certs:$(SOURCE_DIR)/certs \
$(SYSTEMTEST_CONTAINER) \
sh -c 'nosetests $(ST_TO_RUN) -sv --nologcapture --with-xunit --xunit-file="/code/nosetests.xml" --with-timer $(ST_OPTIONS)'
$(MAKE) stop-etcd
.PHONY: add-ssl-hostname
add-ssl-hostname:
# Set "LOCAL_IP etcd-authority-ssl" in /etc/hosts to use as a hostname for etcd with ssl
if ! grep -q "etcd-authority-ssl" /etc/hosts; then \
echo "\n# Host used by Calico's ETCD with SSL\n$(LOCAL_IP_ENV) etcd-authority-ssl" >> /etc/hosts; \
fi
## Etcd is used by the tests
.PHONY: run-etcd
run-etcd:
@-docker rm -f calico-etcd
docker run --detach \
-p 2379:2379 \
--name calico-etcd quay.io/coreos/etcd \
etcd \
--advertise-client-urls "http://$(LOCAL_IP_ENV):2379,http://127.0.0.1:2379" \
--listen-client-urls "http://0.0.0.0:2379"
## Etcd is used by the STs
.PHONY: run-etcd-host
run-etcd-host:
@-docker rm -f calico-etcd
docker run --detach \
--net=host \
--name calico-etcd quay.io/coreos/etcd \
etcd \
--advertise-client-urls "http://$(LOCAL_IP_ENV):2379,http://127.0.0.1:2379" \
--listen-client-urls "http://0.0.0.0:2379"
###############################################################################
# calico_node FVs
###############################################################################
.PHONY: node-fv
## Run the Functional Verification tests locally, must have local etcd running
node-fv:
# Run tests in random order find tests recursively (-r).
ginkgo -cover -r --skipPackage vendor calico_node/*
@echo
@echo '+==============+'
@echo '| All coverage |'
@echo '+==============+'
@echo
@find ./calico_node/ -iname '*.coverprofile' | xargs -I _ go tool cover -func=_
@echo
@echo '+==================+'
@echo '| Missing coverage |'
@echo '+==================+'
@echo
@find ./calico_node/ -iname '*.coverprofile' | xargs -I _ go tool cover -func=_ | grep -v '100.0%'
PHONY: node-test-containerized
## Run the tests in a container. Useful for CI, Mac dev.
node-test-containerized: vendor run-etcd-host
docker run --rm -v $(CURDIR):/go/src/$(PACKAGE_NAME):rw \
-e LOCAL_USER_ID=$(LOCAL_USER_ID) \
--net=host \
$(CALICO_BUILD) sh -c 'cd /go/src/$(PACKAGE_NAME) && make node-fv'