forked from projectcalico/node
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
739 lines (633 loc) · 29.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
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
PACKAGE_NAME?=github.com/projectcalico/node
GO_BUILD_VER?=v0.58
ORGANIZATION=projectcalico
SEMAPHORE_PROJECT_ID?=$(SEMAPHORE_NODE_PROJECT_ID)
RELEASE_REGISTRIES ?=gcr.io/projectcalico-org eu.gcr.io/projectcalico-org asia.gcr.io/projectcalico-org us.gcr.io/projectcalico-org
RELEASE_BRANCH_PREFIX ?=release
DEV_TAG_SUFFIX ?=0.dev
# If this is a release, also tag and push additional images.
ifeq ($(RELEASE),true)
NODE_IMAGE ?=node
DEV_REGISTRIES ?=quay.io/calico calico $(RELEASE_REGISTRIES)
else
NODE_IMAGE ?=calico/node
DEV_REGISTRIES ?=quay.io docker.io
endif
BUILD_IMAGES ?=$(NODE_IMAGE)
LIBBPF_DOCKER_PATH=/go/src/github.com/projectcalico/node/bin/third-party/libbpf/src
LIBBPF_PATH=./bin/third-party/libbpf/src
# Build mounts for running in "local build" mode. This allows an easy build using local development code,
# assuming that there is a local checkout of libcalico in the same directory as this repo.
ifdef LOCAL_BUILD
PHONY: set-up-local-build
LOCAL_BUILD_DEP:=set-up-local-build
EXTRA_DOCKER_ARGS+=-v $(CURDIR)/../libcalico-go:/go/src/github.com/projectcalico/libcalico-go:rw \
-v $(CURDIR)/../felix:/go/src/github.com/projectcalico/felix:rw \
-v $(CURDIR)/../typha:/go/src/github.com/projectcalico/typha:rw \
-v $(CURDIR)/../confd:/go/src/github.com/projectcalico/confd:rw
$(LOCAL_BUILD_DEP):
$(DOCKER_RUN) $(CALICO_BUILD) go mod edit -replace=github.com/projectcalico/libcalico-go=../libcalico-go \
-replace=github.com/projectcalico/felix=../felix \
-replace=github.com/projectcalico/typha=../typha \
-replace=github.com/kelseyhightower/confd=../confd
endif
# Add in local static-checks
LOCAL_CHECKS=check-boring-ssl
###############################################################################
# Download and include Makefile.common
# Additions to EXTRA_DOCKER_ARGS need to happen before the include since
# that variable is evaluated when we declare DOCKER_RUN and siblings.
###############################################################################
MAKE_BRANCH?=$(GO_BUILD_VER)
MAKE_REPO?=https://raw.githubusercontent.com/projectcalico/go-build/$(MAKE_BRANCH)
Makefile.common: Makefile.common.$(MAKE_BRANCH)
cp "$<" "$@"
Makefile.common.$(MAKE_BRANCH):
# Clean up any files downloaded from other branches so they don't accumulate.
rm -f Makefile.common.*
curl --fail $(MAKE_REPO)/Makefile.common -o "$@"
include Makefile.common
# Required for eBPF support in ARM64
ifeq ($(ARCH),arm64)
# Forces ARM64 build image to be used in a crosscompilation run.
CALICO_BUILD:=$(CALICO_BUILD)-$(ARCH)
# Prevents docker from tagging the output image incorrectly as amd64.
TARGET_PLATFORM=--platform=linux/arm64/v8
endif
###############################################################################
# Versions and location of dependencies used in the build.
BIRD_VERSION=v0.3.3-184-g202a2186
BIRD_IMAGE ?= calico/bird:$(BIRD_VERSION)-$(ARCH)
BIRD_SOURCE=filesystem/included-source/bird-$(BIRD_VERSION).tar.gz
FELIX_GPL_SOURCE=filesystem/included-source/felix-ebpf-gpl.tar.gz
INCLUDED_SOURCE=$(BIRD_SOURCE) $(FELIX_GPL_SOURCE)
# Versions and locations of dependencies used in tests.
CALICOCTL_VER?=master
CNI_VER?=master
TEST_CONTAINER_NAME_VER?=latest
CTL_CONTAINER_NAME?=calico/ctl:$(CALICOCTL_VER)-$(ARCH)
TEST_CONTAINER_NAME?=calico/test:$(TEST_CONTAINER_NAME_VER)-$(ARCH)
# If building on amd64 omit the arch in the container name. Fixme!
ETCD_IMAGE?=quay.io/coreos/etcd:$(ETCD_VERSION)
ifneq ($(BUILDARCH),amd64)
ETCD_IMAGE=$(ETCD_IMAGE)-$(ARCH)
endif
# TODO: Update this to use newer version of Kubernetes.
HYPERKUBE_IMAGE?=gcr.io/google_containers/hyperkube-$(ARCH):v1.17.0
TEST_CONTAINER_FILES=$(shell find tests/ -type f ! -name '*.created')
# Variables controlling the image
NODE_CONTAINER_CREATED=.calico_node.created-$(ARCH)
NODE_CONTAINER_BIN_DIR=./dist/bin/
NODE_CONTAINER_BINARY = $(NODE_CONTAINER_BIN_DIR)/calico-node-$(ARCH)
WINDOWS_BINARY = $(NODE_CONTAINER_BIN_DIR)/calico-node.exe
# Variables for the Windows packaging.
# Name of the Windows release ZIP archive.
WINDOWS_ARCHIVE_ROOT := windows-packaging/CalicoWindows
WINDOWS_ARCHIVE_BINARY := $(WINDOWS_ARCHIVE_ROOT)/calico-node.exe
WINDOWS_ARCHIVE_TAG?=$(GIT_VERSION)
WINDOWS_ARCHIVE := dist/calico-windows-$(WINDOWS_ARCHIVE_TAG).zip
# Version of NSSM to download.
WINDOWS_NSSM_VERSION=2.24
# Explicit list of files that we copy in from the mod cache. This is required because the copying rules we use are pattern-based
# and they only work with an explicit rule of the form "$(WINDOWS_MOD_CACHED_FILES): <file path from project root>" (otherwise,
# make has no way to know that the mod cache target produces the files we need).
WINDOWS_MOD_CACHED_FILES := \
windows-packaging/config-bgp.ps1 \
windows-packaging/config-bgp.psm1 \
windows-packaging/conf.d/blocks.toml \
windows-packaging/conf.d/peerings.toml \
windows-packaging/templates/blocks.ps1.template \
windows-packaging/templates/peerings.ps1.template \
# Files to include in the Windows ZIP archive. We need to list some of these explicitly
# because we need to force them to be built/copied into place.
WINDOWS_ARCHIVE_FILES := \
$(WINDOWS_ARCHIVE_BINARY) \
$(WINDOWS_ARCHIVE_ROOT)/README.txt \
$(WINDOWS_ARCHIVE_ROOT)/*.ps1 \
$(WINDOWS_ARCHIVE_ROOT)/node/node-service.ps1 \
$(WINDOWS_ARCHIVE_ROOT)/felix/felix-service.ps1 \
$(WINDOWS_ARCHIVE_ROOT)/confd/confd-service.ps1 \
$(WINDOWS_ARCHIVE_ROOT)/confd/config-bgp.ps1 \
$(WINDOWS_ARCHIVE_ROOT)/confd/config-bgp.psm1 \
$(WINDOWS_ARCHIVE_ROOT)/confd/conf.d/blocks.toml \
$(WINDOWS_ARCHIVE_ROOT)/confd/conf.d/peerings.toml \
$(WINDOWS_ARCHIVE_ROOT)/confd/templates/blocks.ps1.template \
$(WINDOWS_ARCHIVE_ROOT)/confd/templates/peerings.ps1.template \
$(WINDOWS_ARCHIVE_ROOT)/cni/calico.exe \
$(WINDOWS_ARCHIVE_ROOT)/cni/calico-ipam.exe \
$(WINDOWS_ARCHIVE_ROOT)/libs/hns/hns.psm1 \
$(WINDOWS_ARCHIVE_ROOT)/libs/hns/License.txt \
$(WINDOWS_ARCHIVE_ROOT)/libs/calico/calico.psm1
MICROSOFT_SDN_VERSION := 0d7593e5c8d4c2347079a7a6dbd9eb034ae19a44
MICROSOFT_SDN_GITHUB_RAW_URL := https://raw.githubusercontent.com/microsoft/SDN/$(MICROSOFT_SDN_VERSION)
# Variables used by the tests
LOCAL_IP_ENV?=$(shell ip route get 8.8.8.8 | head -1 | awk '{print $$7}')
ST_TO_RUN?=tests/st/
K8ST_TO_RUN?=tests/
# Can exclude the slower tests with "-a '!slow'"
ST_OPTIONS?=
# Variables for building the local binaries that go into the image
MAKE_SURE_BIN_EXIST := $(shell mkdir -p dist $(NODE_CONTAINER_BIN_DIR))
NODE_CONTAINER_FILES=$(shell find ./filesystem -type f)
# Calculate a timestamp for any build artefacts.
DATE:=$(shell date -u +'%FT%T%z')
LDFLAGS=-ldflags "\
-X $(PACKAGE_NAME)/pkg/lifecycle/startup.VERSION=$(GIT_VERSION) \
-X $(PACKAGE_NAME)/buildinfo.GitVersion=$(GIT_DESCRIPTION) \
-X $(PACKAGE_NAME)/buildinfo.BuildDate=$(DATE) \
-X $(PACKAGE_NAME)/buildinfo.GitRevision=$(GIT_COMMIT)"
SRC_FILES=$(shell find ./pkg -name '*.go')
BINDIR?=bin
## Clean enough that a new release build will be clean
clean:
find . -name '*.created' -exec rm -f {} +
find . -name '*.pyc' -exec rm -f {} +
rm -rf .go-pkg-cache
rm -rf certs *.tar $(NODE_CONTAINER_BIN_DIR)
rm -f $(WINDOWS_ARCHIVE_BINARY) $(WINDOWS_BINARY)
rm -f $(WINDOWS_ARCHIVE_ROOT)/libs/hns/hns.psm1
rm -f $(WINDOWS_ARCHIVE_ROOT)/libs/hns/License.txt
rm -f $(WINDOWS_ARCHIVE_ROOT)/cni/*.exe
rm -rf filesystem/included-source
rm -rf dist
rm -rf filesystem/etc/calico/confd/conf.d filesystem/etc/calico/confd/config filesystem/etc/calico/confd/templates
rm -rf config/
rm -rf vendor
rm -rf bin
rm Makefile.common*
# Delete images that we built in this repo
docker rmi $(NODE_IMAGE):latest-$(ARCH) || true
docker rmi $(TEST_CONTAINER_NAME) || true
###############################################################################
# Updating pins
###############################################################################
update-pins: update-api-pin update-libcalico-pin update-felix-pin update-confd-pin update-cni-plugin-pin
###############################################################################
# Building the binary
###############################################################################
build: $(NODE_CONTAINER_BINARY)
remote-deps: mod-download
# Recreate the directory so that we are sure to clean up any old files.
rm -rf filesystem/etc/calico/confd
mkdir -p filesystem/etc/calico/confd
rm -rf config
rm -rf bin/bpf
mkdir -p bin/bpf
rm -rf bin/third-party
rm -rf filesystem/usr/lib/calico/bpf/
mkdir -p filesystem/usr/lib/calico/bpf/
$(DOCKER_RUN) $(CALICO_BUILD) sh -ec ' \
$(GIT_CONFIG_SSH) \
cp -r `go list -mod=mod -m -f "{{.Dir}}" github.com/kelseyhightower/confd`/etc/calico/confd/conf.d filesystem/etc/calico/confd/conf.d; \
cp -r `go list -mod=mod -m -f "{{.Dir}}" github.com/kelseyhightower/confd`/etc/calico/confd/config filesystem/etc/calico/confd/config; \
cp -r `go list -mod=mod -m -f "{{.Dir}}" github.com/kelseyhightower/confd`/etc/calico/confd/templates filesystem/etc/calico/confd/templates; \
cp -r `go list -mod=mod -m -f "{{.Dir}}" github.com/projectcalico/libcalico-go`/config config; \
cp -r `go list -mod=mod -m -f "{{.Dir}}" github.com/projectcalico/felix`/bpf-gpl bin/bpf; \
cp -r `go list -mod=mod -m -f "{{.Dir}}" github.com/projectcalico/felix`/bpf-apache bin/bpf; \
chmod -R +w bin/bpf; \
chmod +x bin/bpf/bpf-gpl/list-* bin/bpf/bpf-gpl/calculate-*; \
make -j 16 -C ./bin/bpf/bpf-apache/ all; \
make -j 16 -C ./bin/bpf/bpf-gpl/ all; \
cp bin/bpf/bpf-gpl/bin/* filesystem/usr/lib/calico/bpf/; \
cp bin/bpf/bpf-apache/bin/* filesystem/usr/lib/calico/bpf/; \
chmod -R +w filesystem/etc/calico/confd/ config/ filesystem/usr/lib/calico/bpf/'
$(LIBBPF_PATH)/libbpf.a: go.mod
$(MAKE) mod-download
mkdir -p bin/third-party
$(DOCKER_RUN) $(CALICO_BUILD) sh -ec ' \
$(GIT_CONFIG_SSH) \
cp -r `go list -mod=mod -m -f "{{.Dir}}" github.com/projectcalico/felix`/bpf-gpl/include/libbpf bin/third-party; \
chmod -R +w bin/third-party; \
make -j 16 -C $(LIBBPF_PATH) BUILD_STATIC_ONLY=1'
# We need CGO when compiling in Felix for BPF support. However, the cross-compile doesn't support CGO yet.
# Currently CGO can be enbaled in ARM64 and AMD64 builds.
ifeq ($(ARCH), $(filter $(ARCH),amd64 arm64))
CGO_ENABLED=1
CGO_LDFLAGS="-L$(LIBBPF_DOCKER_PATH) -lbpf -lelf -lz"
CGO_CFLAGS="-I$(LIBBPF_DOCKER_PATH)"
else
CGO_ENABLED=0
CGO_LDFLAGS=""
CGO_CFLAGS=""
endif
DOCKER_GO_BUILD_CGO=$(DOCKER_RUN) -e CGO_ENABLED=$(CGO_ENABLED) -e CGO_LDFLAGS=$(CGO_LDFLAGS) -e CGO_CFLAGS=$(CGO_CFLAGS) $(CALICO_BUILD)
DOCKER_GO_BUILD_CGO_WINDOWS=$(DOCKER_RUN) -e CGO_ENABLED=$(CGO_ENABLED) $(CALICO_BUILD)
$(NODE_CONTAINER_BINARY): $(LIBBPF_PATH)/libbpf.a $(LOCAL_BUILD_DEP) $(SRC_FILES) go.mod
$(DOCKER_GO_BUILD_CGO) sh -c '$(GIT_CONFIG_SSH) go build -v -o $@ $(BUILD_FLAGS) $(LDFLAGS) ./cmd/calico-node/main.go'
$(WINDOWS_BINARY):
$(DOCKER_RUN) \
-e GOOS=windows \
$(LOCAL_BUILD_MOUNTS) \
$(CALICO_BUILD) sh -c '$(GIT_CONFIG_SSH) \
go build -v -o $@ $(LDFLAGS) ./cmd/calico-node/main.go'
$(WINDOWS_ARCHIVE_ROOT)/cni/calico.exe:
$(DOCKER_RUN) \
-e GOOS=windows \
$(LOCAL_BUILD_MOUNTS) \
$(CALICO_BUILD) sh -c '$(GIT_CONFIG_SSH) \
go build -v -o $@ $(LDFLAGS) ./cmd/calico'
$(WINDOWS_ARCHIVE_ROOT)/cni/calico-ipam.exe:
$(DOCKER_RUN) \
-e GOOS=windows \
$(LOCAL_BUILD_MOUNTS) \
$(CALICO_BUILD) sh -c '$(GIT_CONFIG_SSH) \
go build -v -o $@ $(LDFLAGS) ./cmd/calico-ipam'
###############################################################################
# Building the image
###############################################################################
## Create the image for the current ARCH
image: remote-deps $(NODE_IMAGE)
## Create the images for all supported ARCHes
image-all: $(addprefix sub-image-,$(VALIDARCHES))
sub-image-%:
$(MAKE) image ARCH=$*
ifeq ($(TEST_IMAGE_BUILD),true)
# If testing image builds, clean sub-image afterwards to free disk space (for Semaphore CI)
$(MAKE) clean-sub-image-$*
endif
## Remove images for all supported ARCHes
clean-image-all: $(addprefix clean-sub-image-,$(VALIDARCHES))
## Remove sub-image from docker and delete $(NODE_CONTAINER_CREATED) file
clean-sub-image-%:
rm -f .calico_node.created-$*
docker rmi $(NODE_IMAGE):latest-$* || true
$(NODE_IMAGE): $(NODE_CONTAINER_CREATED)
$(NODE_CONTAINER_CREATED): register ./Dockerfile.$(ARCH) $(NODE_CONTAINER_FILES) $(NODE_CONTAINER_BINARY) $(INCLUDED_SOURCE) remote-deps
ifeq ($(LOCAL_BUILD),true)
# If doing a local build, copy in local confd templates in case there are changes.
rm -rf filesystem/etc/calico/confd/templates
cp -r ../confd/etc/calico/confd/templates filesystem/etc/calico/confd/templates
endif
# Check versions of the binaries that we're going to use to build the image.
# Since the binaries are built for Linux, run them in a container to allow the
# make target to be run on different platforms (e.g. MacOS).
docker run --rm -v $(CURDIR)/dist/bin:/go/bin:rw $(CALICO_BUILD) /bin/sh -c "\
echo; echo calico-node-$(ARCH) -v; /go/bin/calico-node-$(ARCH) -v; \
"
## TARGET_PLATFORM fixes an issue where `FROM SCRATCH` in the Dockerfile share the same architecture as the host.
docker build --pull -t $(NODE_IMAGE):latest-$(ARCH) $(TARGET_PLATFORM) . --build-arg BIRD_IMAGE=$(BIRD_IMAGE) --build-arg QEMU_IMAGE=$(CALICO_BUILD) --build-arg GIT_VERSION=$(GIT_VERSION) -f ./Dockerfile.$(ARCH)
touch $@
# download BIRD source to include in image.
$(BIRD_SOURCE): go.mod
mkdir -p filesystem/included-source/
wget -O $@ https://github.com/projectcalico/bird/tarball/$(BIRD_VERSION)
# download any GPL felix code to include in the image.
$(FELIX_GPL_SOURCE): go.mod
mkdir -p filesystem/included-source/
$(DOCKER_RUN) $(CALICO_BUILD) sh -c ' \
tar cf $@ `go list -m -f "{{.Dir}}" github.com/projectcalico/felix`/bpf-gpl;'
###############################################################################
# FV Tests
###############################################################################
## Run the ginkgo FVs
fv: run-k8s-apiserver
docker run --rm \
-v $(CURDIR):/go/src/$(PACKAGE_NAME):rw \
-e LOCAL_USER_ID=$(LOCAL_USER_ID) \
-e ETCD_ENDPOINTS=http://$(LOCAL_IP_ENV):2379 \
-e GO111MODULE=on \
--net=host \
-w /go/src/$(PACKAGE_NAME) \
$(CALICO_BUILD) ginkgo -cover -r -skipPackage vendor pkg/lifecycle/startup pkg/allocateip $(GINKGO_ARGS)
## Create a local kind dual stack cluster.
KUBECONFIG?=kubeconfig.yaml
cluster-create: $(BINDIR)/kubectl $(BINDIR)/kind
# First make sure any previous cluster is deleted
make cluster-destroy
# Create a kind cluster.
$(BINDIR)/kind create cluster \
--config ./tests/kind-config.yaml \
--kubeconfig $(KUBECONFIG) \
--image kindest/node:$(K8S_VERSION)
# Deploy resources needed in test env.
$(MAKE) deploy-test-resources
# Wait for controller manager to be running and healthy.
while ! KUBECONFIG=$(KUBECONFIG) $(BINDIR)/kubectl get serviceaccount default; do echo "Waiting for default serviceaccount to be created..."; sleep 2; done
## Deploy resources on the kind cluster that are needed for tests
deploy-test-resources: $(BINDIR)/kubectl calico-node.tar
KUBECONFIG=$(KUBECONFIG) ./tests/k8st/deploy_resources_on_kind_cluster.sh
## Destroy local kind cluster
cluster-destroy: $(BINDIR)/kubectl $(BINDIR)/kind
-$(BINDIR)/kubectl --kubeconfig=$(KUBECONFIG) drain kind-control-plane kind-worker kind-worker2 kind-worker3 --ignore-daemonsets --force
-$(BINDIR)/kind delete cluster
rm -f ./tests/k8st/infra/calico.yaml.tmp
rm -f $(KUBECONFIG)
$(BINDIR)/kind:
$(DOCKER_GO_BUILD) sh -c "GOBIN=/go/src/$(PACKAGE_NAME)/$(BINDIR) go install sigs.k8s.io/kind"
$(BINDIR)/kubectl:
mkdir -p $(BINDIR)
curl -L https://storage.googleapis.com/kubernetes-release/release/v1.22.0/bin/linux/$(ARCH)/kubectl -o $@
chmod +x $(BINDIR)/kubectl
# etcd is used by the STs
.PHONY: run-etcd
run-etcd:
@-docker rm -f calico-etcd
docker run --detach \
--net=host \
--name calico-etcd $(ETCD_IMAGE) \
etcd \
--advertise-client-urls "http://$(LOCAL_IP_ENV):2379,http://127.0.0.1:2379" \
--listen-client-urls "http://0.0.0.0:2379"
# Kubernetes apiserver used for tests
run-k8s-apiserver: remote-deps stop-k8s-apiserver run-etcd
docker run \
--net=host --name st-apiserver \
-v $(CURDIR):/manifests \
-v $(CURDIR):/go/src/$(PACKAGE_NAME):rw \
--detach \
${HYPERKUBE_IMAGE} kube-apiserver \
--bind-address=0.0.0.0 \
--insecure-bind-address=0.0.0.0 \
--etcd-servers=http://127.0.0.1:2379 \
--admission-control=NamespaceLifecycle,LimitRanger,DefaultStorageClass,ResourceQuota \
--authorization-mode=RBAC \
--service-cluster-ip-range=10.101.0.0/16 \
--v=10 \
--logtostderr=true
# Wait until we can configure a cluster role binding which allows anonymous auth.
while ! docker exec st-apiserver kubectl create \
clusterrolebinding anonymous-admin \
--clusterrole=cluster-admin \
--user=system:anonymous 2>/dev/null ; \
do echo "Waiting for st-apiserver to come up"; \
sleep 1; \
done
# ClusterRoleBinding created
# Create CustomResourceDefinition (CRD) for Calico resources
while ! docker exec st-apiserver kubectl \
apply -f /manifests/config/crd/; \
do echo "Trying to create CRDs"; \
sleep 1; \
done
# Stop Kubernetes apiserver
stop-k8s-apiserver:
@-docker rm -f st-apiserver
ut:
@echo "No UTs available"
###############################################################################
# System tests
# - Support for running etcd (both securely and insecurely)
###############################################################################
# Pull calicoctl and CNI plugin binaries with versions as per XXX_VER
# variables. These are used for the STs.
dist/calicoctl:
-docker rm -f calicoctl
docker pull $(CTL_CONTAINER_NAME)
docker create --name calicoctl $(CTL_CONTAINER_NAME)
docker cp calicoctl:calicoctl dist/calicoctl && \
test -e dist/calicoctl && \
touch dist/calicoctl
-docker rm -f calicoctl
dist/calico dist/calico-ipam:
-docker rm -f calico-cni
docker pull calico/cni:$(CNI_VER)
docker create --name calico-cni calico/cni:$(CNI_VER)
docker cp calico-cni:/opt/cni/bin/install dist/calico && \
test -e dist/calico && \
touch dist/calico
docker cp calico-cni:/opt/cni/bin/install dist/calico-ipam && \
test -e dist/calico-ipam && \
touch dist/calico-ipam
-docker rm -f calico-cni
# Create images for containers used in the tests
busybox.tar:
docker pull $(ARCH)/busybox:latest
docker save --output busybox.tar $(ARCH)/busybox:latest
workload.tar:
cd workload && docker build -t workload --build-arg QEMU_IMAGE=$(CALICO_BUILD) -f Dockerfile.$(ARCH) .
docker save --output workload.tar workload
stop-etcd:
@-docker rm -f calico-etcd
IPT_ALLOW_ETCD:=-A INPUT -i docker0 -p tcp --dport 2379 -m comment --comment "calico-st-allow-etcd" -j ACCEPT
# Create the calico/test image
test_image: calico_test.created
calico_test.created: $(TEST_CONTAINER_FILES)
cd calico_test && docker build --build-arg QEMU_IMAGE=$(CALICO_BUILD) -f Dockerfile.$(ARCH).calico_test -t $(TEST_CONTAINER_NAME) .
touch calico_test.created
calico-node.tar: $(NODE_CONTAINER_CREATED)
# Check versions of the Calico binaries that will be in calico-node.tar.
# Since the binaries are built for Linux, run them in a container to allow the
# make target to be run on different platforms (e.g. MacOS).
docker run --rm $(NODE_IMAGE):latest-$(ARCH) /bin/sh -c "\
echo bird --version; /bin/bird --version; \
"
docker save --output $@ $(NODE_IMAGE):latest-$(ARCH)
.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)
.PHONY: k8s-test
## Run the k8s tests
k8s-test:
$(MAKE) kind-k8st-setup
$(MAKE) kind-k8st-run-test
$(MAKE) kind-k8st-cleanup
.PHONY: kind-k8st-setup
kind-k8st-setup: calico-node.tar cluster-create
.PHONY: kind-k8st-run-test
kind-k8st-run-test: calico_test.created $(KUBECONFIG)
docker run -t --rm \
-v $(CURDIR):/code \
-v /var/run/docker.sock:/var/run/docker.sock \
-v $(CURDIR)/$(KUBECONFIG):/root/.kube/config \
-v $(CURDIR)/$(BINDIR)/kubectl:/bin/kubectl \
-e ROUTER_IMAGE=$(BIRD_IMAGE) \
--privileged \
--net host \
${TEST_CONTAINER_NAME} \
sh -c 'echo "container started.." && \
cd /code/tests/k8st && nosetests $(K8ST_TO_RUN) -v --with-xunit --xunit-file="/code/report/k8s-tests.xml" --with-timer'
.PHONY: kind-k8st-cleanup
kind-k8st-cleanup: cluster-destroy
# Needed for Semaphore CI (where disk space is a real issue during k8s-test)
.PHONY: remove-go-build-image
remove-go-build-image:
@echo "Removing $(CALICO_BUILD) image to save space needed for testing ..."
@-docker rmi $(CALICO_BUILD)
.PHONY: st
## Run the system tests
st: image remote-deps dist/calicoctl busybox.tar calico-node.tar workload.tar run-etcd calico_test.created dist/calico dist/calico-ipam
# Check versions of Calico binaries that ST execution will use.
docker run --rm -v $(CURDIR)/dist:/go/bin:rw $(CALICO_BUILD) /bin/sh -c "\
echo; echo calicoctl version; /go/bin/calicoctl version; \
echo; echo calico -v; /go/bin/calico -v; \
echo; echo calico-ipam -v; /go/bin/calico-ipam -v; echo; \
"
# 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 \
-v $(CURDIR):/code \
-e HOST_CHECKOUT_DIR=$(CURDIR) \
-e DEBUG_FAILURES=$(DEBUG_FAILURES) \
-e MY_IP=$(LOCAL_IP_ENV) \
-e NODE_CONTAINER_NAME=$(NODE_IMAGE):latest-$(ARCH) \
--rm -t \
-v /var/run/docker.sock:/var/run/docker.sock \
$(TEST_CONTAINER_NAME) \
sh -c 'nosetests $(ST_TO_RUN) -v --with-xunit --xunit-file="/code/report/nosetests.xml" --with-timer $(ST_OPTIONS)'
$(MAKE) stop-etcd
###############################################################################
# CI/CD
###############################################################################
.PHONY: ci
ci: mod-download static-checks fv image-all build-windows-archive st
## Deploys images to registry
cd: cd-common
check-boring-ssl: $(NODE_CONTAINER_BIN_DIR)/calico-node-amd64
$(DOCKER_RUN) -e CGO_ENABLED=$(CGO_ENABLED) $(CALICO_BUILD) \
go tool nm $(NODE_CONTAINER_BIN_DIR)/calico-node-amd64 > $(NODE_CONTAINER_BIN_DIR)/tags.txt && grep '_Cfunc__goboringcrypto_' $(NODE_CONTAINER_BIN_DIR)/tags.txt 1> /dev/null
-rm -f $(NODE_CONTAINER_BIN_DIR)/tags.txt
###############################################################################
# Release
###############################################################################
PREVIOUS_RELEASE=$(shell git describe --tags --abbrev=0)
## Tags and builds a release from start to finish.
release: release-prereqs
$(MAKE) VERSION=$(VERSION) release-tag
$(MAKE) VERSION=$(VERSION) release-build
$(MAKE) VERSION=$(VERSION) release-verify
@echo ""
@echo "Release build complete. Next, push the produced images."
@echo ""
@echo " make VERSION=$(VERSION) release-publish"
@echo ""
## Produces a git tag for the release.
release-tag: release-prereqs release-notes
git tag $(VERSION) -F release-notes-$(VERSION)
@echo ""
@echo "Now you can build the release:"
@echo ""
@echo " make VERSION=$(VERSION) release-build"
@echo ""
## Produces a clean build of release artifacts at the specified version.
release-build: release-prereqs clean
# Check that the correct code is checked out.
ifneq ($(VERSION), $(GIT_VERSION))
$(error Attempt to build $(VERSION) from $(GIT_VERSION))
endif
$(MAKE) image-all RELEASE=true
$(MAKE) retag-build-images-with-registries RELEASE=true IMAGETAG=$(VERSION)
# Generate the `latest` images.
$(MAKE) retag-build-images-with-registries RELEASE=true IMAGETAG=latest
$(MAKE) release-windows-archive
## Produces the Windows ZIP archive for the release.
release-windows-archive $(WINDOWS_ARCHIVE): release-prereqs
$(MAKE) build-windows-archive WINDOWS_ARCHIVE_TAG=$(VERSION)
## Verifies the release artifacts produces by `make release-build` are correct.
release-verify: release-prereqs
# Check the reported version is correct for each release artifact.
if ! docker run $(NODE_IMAGE):$(VERSION)-$(ARCH) versions | grep '^$(VERSION)$$'; then echo "Reported version:" `docker run $(NODE_IMAGE):$(VERSION)-$(ARCH) versions` "\nExpected version: $(VERSION)"; false; else echo "\nVersion check passed\n"; fi
## Generates release notes based on commits in this version.
release-notes: release-prereqs
mkdir -p dist
echo "# Changelog" > release-notes-$(VERSION)
echo "" > release-notes-$(VERSION)
sh -c "git cherry -v $(PREVIOUS_RELEASE) | cut '-d ' -f 2- | sed 's/^/- /' >> release-notes-$(VERSION)"
## Pushes a github release and release artifacts produced by `make release-build`.
release-publish: release-prereqs
ifeq (, $(shell which ghr))
$(error Unable to find `ghr` in PATH, run this: go get -u github.com/tcnksm/ghr)
endif
# Push the git tag.
git push origin $(VERSION)
# Push images.
$(MAKE) push-images-to-registries push-manifests IMAGETAG=$(VERSION) RELEASE=true CONFIRM=true
# Push Windows artifacts to GitHub release.
# Requires ghr: https://github.com/tcnksm/ghr
# Requires GITHUB_TOKEN environment variable set.
ghr -u projectcalico -r node \
-n $(VERSION) \
$(VERSION) $(WINDOWS_ARCHIVE)
@echo "Finalize the GitHub release based on the pushed tag."
@echo ""
@echo " https://$(PACKAGE_NAME)/releases/tag/$(VERSION)"
@echo ""
@echo "If this is the latest stable release, then run the following to push 'latest' images."
@echo ""
@echo " make VERSION=$(VERSION) release-publish-latest"
@echo ""
# WARNING: Only run this target if this release is the latest stable release. Do NOT
# run this target for alpha / beta / release candidate builds, or patches to earlier Calico versions.
## Pushes `latest` release images. WARNING: Only run this for latest stable releases.
release-publish-latest: release-verify
$(MAKE) push-images-to-registries push-manifests IMAGETAG=latest RELEASE=true CONFIRM=true
.PHONY: node-test-at
# Run docker-image acceptance tests
node-test-at: release-prereqs
docker run -v $(PWD)/tests/at/calico_node_goss.yaml:/tmp/goss.yaml \
$(NODE_IMAGE):$(VERSION) /bin/sh -c ' \
apk --no-cache add wget ca-certificates && \
wget -q -O /tmp/goss https://github.com/aelsabbahy/goss/releases/download/v0.3.4/goss-linux-amd64 && \
chmod +rx /tmp/goss && \
/tmp/goss --gossfile /tmp/goss.yaml validate'
# release-prereqs checks that the environment is configured properly to create a release.
release-prereqs:
ifndef VERSION
$(error VERSION is undefined - run using make release VERSION=vX.Y.Z)
endif
ifdef LOCAL_BUILD
$(error LOCAL_BUILD must not be set for a release)
endif
###############################################################################
# Windows packaging
###############################################################################
# Pull the BGP configuration scripts and templates from the confd repo.
$(WINDOWS_MOD_CACHED_FILES): mod-download
$(WINDOWS_ARCHIVE_ROOT)/confd/config-bgp%: windows-packaging/config-bgp%
$(DOCKER_RUN) $(CALICO_BUILD) sh -ec ' \
$(GIT_CONFIG_SSH) \
cp -r `go list -mod=mod -m -f "{{.Dir}}" github.com/kelseyhightower/confd`/$< $@'; \
chmod +w $@
$(WINDOWS_ARCHIVE_ROOT)/confd/conf.d/%: windows-packaging/conf.d/%
$(DOCKER_RUN) $(CALICO_BUILD) sh -ec ' \
$(GIT_CONFIG_SSH) \
cp -r `go list -mod=mod -m -f "{{.Dir}}" github.com/kelseyhightower/confd`/$< $@'; \
chmod +w $@
$(WINDOWS_ARCHIVE_ROOT)/confd/templates/%: windows-packaging/templates/%
$(DOCKER_RUN) $(CALICO_BUILD) sh -ec ' \
$(GIT_CONFIG_SSH) \
cp -r `go list -mod=mod -m -f "{{.Dir}}" github.com/kelseyhightower/confd`/$< $@'; \
chmod +w $@
$(WINDOWS_ARCHIVE_ROOT)/libs/hns/hns.psm1:
wget -P $(WINDOWS_ARCHIVE_ROOT)/libs/hns/ $(MICROSOFT_SDN_GITHUB_RAW_URL)/Kubernetes/windows/hns.psm1
$(WINDOWS_ARCHIVE_ROOT)/libs/hns/License.txt:
wget -P $(WINDOWS_ARCHIVE_ROOT)/libs/hns/ $(MICROSOFT_SDN_GITHUB_RAW_URL)/License.txt
## Download NSSM.
windows-packaging/nssm-$(WINDOWS_NSSM_VERSION).zip:
wget -O windows-packaging/nssm-$(WINDOWS_NSSM_VERSION).zip https://nssm.cc/release/nssm-$(WINDOWS_NSSM_VERSION).zip
build-windows-archive: $(WINDOWS_ARCHIVE_FILES) windows-packaging/nssm-$(WINDOWS_NSSM_VERSION).zip
# To be as atomic as possible, we re-do work like unpacking NSSM here.
-rm -f "$(WINDOWS_ARCHIVE)"
-rm -rf $(WINDOWS_ARCHIVE_ROOT)/nssm-$(WINDOWS_NSSM_VERSION)
mkdir -p dist
cd windows-packaging && \
sha256sum --check nssm.sha256sum && \
cd CalicoWindows && \
unzip ../nssm-$(WINDOWS_NSSM_VERSION).zip \
-x 'nssm-$(WINDOWS_NSSM_VERSION)/src/*' && \
cd .. && \
zip -r "../$(WINDOWS_ARCHIVE)" CalicoWindows -x '*.git*'
@echo
@echo "Windows archive built at $(WINDOWS_ARCHIVE)"
$(WINDOWS_ARCHIVE_BINARY): $(WINDOWS_BINARY)
cp $< $@
###############################################################################
# Utilities
###############################################################################
$(info "Build dependency versions")
$(info $(shell printf "%-21s = %-10s\n" "BIRD_VERSION" $(BIRD_VERSION)))
$(info "Test dependency versions")
$(info $(shell printf "%-21s = %-10s\n" "CNI_VER" $(CNI_VER)))
$(info "Calico git version")
$(info $(shell printf "%-21s = %-10s\n" "GIT_VERSION" $(GIT_VERSION)))