Makefile 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284
  1. .PHONY: test e2e-test cover gofmt gofmt-fix header-check clean tar.gz docker-push release docker-push-all flannel-git docker-manifest-amend docker-manifest-push
  2. # Registry used for publishing images
  3. REGISTRY?=quay.io/coreos/flannel
  4. QEMU_VERSION=v3.0.0
  5. # Default tag and architecture. Can be overridden
  6. TAG?=$(shell git describe --tags --dirty --always)
  7. ARCH?=amd64
  8. # Only enable CGO (and build the UDP backend) on AMD64
  9. ifeq ($(ARCH),amd64)
  10. CGO_ENABLED=1
  11. else
  12. CGO_ENABLED=0
  13. endif
  14. # Go version to use for builds
  15. GO_VERSION=1.15.5
  16. # K8s version used for Makefile helpers
  17. K8S_VERSION=v1.6.6
  18. GOARM=7
  19. # These variables can be overridden by setting an environment variable.
  20. TEST_PACKAGES?=pkg/ip subnet subnet/etcdv2 network backend
  21. TEST_PACKAGES_EXPANDED=$(TEST_PACKAGES:%=github.com/flannel-io/flannel/%)
  22. PACKAGES?=$(TEST_PACKAGES) network
  23. PACKAGES_EXPANDED=$(PACKAGES:%=github.com/flannel-io/flannel/%)
  24. ### BUILDING
  25. clean:
  26. rm -f dist/flanneld*
  27. rm -f dist/*.aci
  28. rm -f dist/*.docker
  29. rm -f dist/*.tar.gz
  30. rm -f dist/qemu-*
  31. dist/flanneld: $(shell find . -type f -name '*.go')
  32. go build -o dist/flanneld \
  33. -ldflags '-s -w -X github.com/flannel-io/flannel/version.Version=$(TAG) -extldflags "-static"'
  34. dist/flanneld.exe: $(shell find . -type f -name '*.go')
  35. CXX=x86_64-w64-mingw32-g++ CC=x86_64-w64-mingw32-gcc CGO_ENABLED=1 GOOS=windows go build -o dist/flanneld.exe \
  36. -ldflags '-s -w -X github.com/flannel-io/flannel/version.Version=$(TAG) -extldflags "-static"'
  37. # This will build flannel natively using golang image
  38. dist/flanneld-$(ARCH): dist/qemu-$(ARCH)-static
  39. # valid values for ARCH are [amd64 arm arm64 ppc64le s390x]
  40. docker run -e CGO_ENABLED=$(CGO_ENABLED) -e GOARCH=$(ARCH) -e GOCACHE=/go \
  41. -u $(shell id -u):$(shell id -g) \
  42. -v $(CURDIR)/dist/qemu-$(ARCH)-static:/usr/bin/qemu-$(ARCH)-static \
  43. -v $(CURDIR):/go/src/github.com/flannel-io/flannel:ro \
  44. -v $(CURDIR)/dist:/go/src/github.com/flannel-io/flannel/dist \
  45. golang:$(GO_VERSION) /bin/bash -c '\
  46. cd /go/src/github.com/flannel-io/flannel && \
  47. make -e dist/flanneld && \
  48. mv dist/flanneld dist/flanneld-$(ARCH)'
  49. ## Create a docker image on disk for a specific arch and tag
  50. image: dist/flanneld-$(TAG)-$(ARCH).docker
  51. dist/flanneld-$(TAG)-$(ARCH).docker: dist/flanneld-$(ARCH)
  52. docker build -f Dockerfile.$(ARCH) -t $(REGISTRY):$(TAG)-$(ARCH) .
  53. docker save -o dist/flanneld-$(TAG)-$(ARCH).docker $(REGISTRY):$(TAG)-$(ARCH)
  54. # amd64 gets an image with the suffix too (i.e. it's the default)
  55. ifeq ($(ARCH),amd64)
  56. docker build -f Dockerfile.$(ARCH) -t $(REGISTRY):$(TAG) .
  57. endif
  58. ### TESTING
  59. test: header-check gofmt verify-modules
  60. # Run the unit tests
  61. # NET_ADMIN capacity is required to do some network operation
  62. # SYS_ADMIN capacity is required to create network namespace
  63. docker run --cap-add=NET_ADMIN --cap-add=SYS_ADMIN --rm -v $(shell pwd):/go/src/github.com/flannel-io/flannel golang:$(GO_VERSION) go test -v -cover $(TEST_PACKAGES_EXPANDED)
  64. # Test the docker-opts script
  65. cd dist; ./mk-docker-opts_tests.sh
  66. # Run the functional tests
  67. make e2e-test
  68. e2e-test: bash_unit dist/flanneld-e2e-$(TAG)-$(ARCH).docker
  69. $(MAKE) -C images/iperf3 ARCH=$(ARCH)
  70. FLANNEL_DOCKER_IMAGE=$(REGISTRY):$(TAG)-$(ARCH) ./bash_unit dist/functional-test.sh
  71. FLANNEL_DOCKER_IMAGE=$(REGISTRY):$(TAG)-$(ARCH) ./bash_unit dist/functional-test-k8s.sh
  72. cover:
  73. # A single package must be given - e.g. 'PACKAGES=pkg/ip make cover'
  74. go test -coverprofile cover.out $(PACKAGES_EXPANDED)
  75. go tool cover -html=cover.out
  76. header-check:
  77. ./header-check.sh
  78. # Throw an error if gofmt finds problems.
  79. # "read" will return a failure return code if there is no output. This is inverted wth the "!"
  80. gofmt:
  81. docker run -e CGO_ENABLED=$(CGO_ENABLED) -e GOARCH=$(ARCH) \
  82. -u $(shell id -u):$(shell id -g) \
  83. -v $(CURDIR):/go/src/github.com/flannel-io/flannel \
  84. -v $(CURDIR)/dist:/go/src/github.com/flannel-io/flannel/dist \
  85. golang:$(GO_VERSION) /bin/bash -c '\
  86. cd /go/src/github.com/flannel-io/flannel && \
  87. ! gofmt -d $(PACKAGES) 2>&1 | read'
  88. verify-modules:
  89. $(if $(shell which go),,$(error "go not found in PATH"))
  90. go mod tidy
  91. go vet
  92. gofmt-fix:
  93. docker run -e CGO_ENABLED=$(CGO_ENABLED) -e GOARCH=$(ARCH) \
  94. -u $(shell id -u):$(shell id -g) \
  95. -v $(CURDIR):/go/src/github.com/flannel-io/flannel \
  96. -v $(CURDIR)/dist:/go/src/github.com/flannel-io/flannel/dist \
  97. golang:$(GO_VERSION) /bin/bash -c '\
  98. cd /go/src/github.com/flannel-io/flannel && \
  99. gofmt -w $(PACKAGES)'
  100. bash_unit:
  101. wget https://raw.githubusercontent.com/pgrange/bash_unit/v1.6.0/bash_unit
  102. chmod +x bash_unit
  103. # This will build flannel natively using golang image
  104. dist/flanneld-e2e-$(TAG)-$(ARCH).docker:
  105. ifneq ($(ARCH),amd64)
  106. $(MAKE) dist/qemu-$(ARCH)-static
  107. endif
  108. # valid values for ARCH are [amd64 arm arm64 ppc64le s390x]
  109. docker run -e GOARM=$(GOARM) -e GOCACHE=/go \
  110. -u $(shell id -u):$(shell id -g) \
  111. -v $(CURDIR):/go/src/github.com/flannel-io/flannel:ro \
  112. -v $(CURDIR)/dist:/go/src/github.com/flannel-io/flannel/dist \
  113. golang:$(GO_VERSION) /bin/bash -c '\
  114. cd /go/src/github.com/flannel-io/flannel && \
  115. CGO_ENABLED=1 make -e dist/flanneld && \
  116. mv dist/flanneld dist/flanneld-$(ARCH)'
  117. docker build -f Dockerfile.$(ARCH) -t $(REGISTRY):$(TAG)-$(ARCH) .
  118. # Make a release after creating a tag
  119. # To build cross platform Docker images, the qemu-static binaries are needed. On ubuntu "apt-get install qemu-user-static"
  120. release: tar.gz dist/qemu-s390x-static dist/qemu-ppc64le-static dist/qemu-aarch64-static dist/qemu-arm-static #release-tests
  121. ARCH=amd64 make dist/flanneld-$(TAG)-amd64.docker
  122. ARCH=arm make dist/flanneld-$(TAG)-arm.docker
  123. ARCH=arm64 make dist/flanneld-$(TAG)-arm64.docker
  124. ARCH=ppc64le make dist/flanneld-$(TAG)-ppc64le.docker
  125. ARCH=s390x make dist/flanneld-$(TAG)-s390x.docker
  126. @echo "Everything should be built for $(TAG)"
  127. @echo "Add all flanneld-* and *.tar.gz files from dist/ to the Github release"
  128. @echo "Use make docker-push-all to push the images to a registry"
  129. dist/qemu-%-static:
  130. if [ "$(@F)" = "qemu-amd64-static" ]; then \
  131. wget -O dist/qemu-amd64-static https://github.com/multiarch/qemu-user-static/releases/download/$(QEMU_VERSION)/qemu-x86_64-static; \
  132. elif [ "$(@F)" = "qemu-arm64-static" ]; then \
  133. wget -O dist/qemu-arm64-static https://github.com/multiarch/qemu-user-static/releases/download/$(QEMU_VERSION)/qemu-aarch64-static; \
  134. else \
  135. wget -O dist/$(@F) https://github.com/multiarch/qemu-user-static/releases/download/$(QEMU_VERSION)/$(@F); \
  136. fi
  137. ## Build a .tar.gz for the amd64 ppc64le arm arm64 flanneld binary
  138. tar.gz:
  139. ARCH=amd64 make dist/flanneld-amd64
  140. tar --transform='flags=r;s|-amd64||' -zcvf dist/flannel-$(TAG)-linux-amd64.tar.gz -C dist flanneld-amd64 mk-docker-opts.sh ../README.md
  141. tar -tvf dist/flannel-$(TAG)-linux-amd64.tar.gz
  142. ARCH=amd64 make dist/flanneld.exe
  143. tar --transform='flags=r;s|-amd64||' -zcvf dist/flannel-$(TAG)-windows-amd64.tar.gz -C dist flanneld.exe mk-docker-opts.sh ../README.md
  144. tar -tvf dist/flannel-$(TAG)-windows-amd64.tar.gz
  145. ARCH=ppc64le make dist/flanneld-ppc64le
  146. tar --transform='flags=r;s|-ppc64le||' -zcvf dist/flannel-$(TAG)-linux-ppc64le.tar.gz -C dist flanneld-ppc64le mk-docker-opts.sh ../README.md
  147. tar -tvf dist/flannel-$(TAG)-linux-ppc64le.tar.gz
  148. ARCH=arm make dist/flanneld-arm
  149. tar --transform='flags=r;s|-arm||' -zcvf dist/flannel-$(TAG)-linux-arm.tar.gz -C dist flanneld-arm mk-docker-opts.sh ../README.md
  150. tar -tvf dist/flannel-$(TAG)-linux-arm.tar.gz
  151. ARCH=arm64 make dist/flanneld-arm64
  152. tar --transform='flags=r;s|-arm64||' -zcvf dist/flannel-$(TAG)-linux-arm64.tar.gz -C dist flanneld-arm64 mk-docker-opts.sh ../README.md
  153. tar -tvf dist/flannel-$(TAG)-linux-arm64.tar.gz
  154. ARCH=s390x make dist/flanneld-s390x
  155. tar --transform='flags=r;s|-s390x||' -zcvf dist/flannel-$(TAG)-linux-s390x.tar.gz -C dist flanneld-s390x mk-docker-opts.sh ../README.md
  156. tar -tvf dist/flannel-$(TAG)-linux-s390x.tar.gz
  157. release-tests: release-etcd-tests release-k8s-tests
  158. release-etcd-tests: bash_unit
  159. # Run the functional tests with different etcd versions.
  160. ETCD_IMG="quay.io/coreos/etcd:latest" ./bash_unit dist/functional-test.sh
  161. ETCD_IMG="quay.io/coreos/etcd:v3.2.7" ./bash_unit dist/functional-test.sh
  162. # Etcd v2 docker image format is different. Override the etcd binary location so it works.
  163. ETCD_IMG="quay.io/coreos/etcd:v2.3.8" ETCD_LOCATION=" " ./bash_unit dist/functional-test.sh
  164. release-k8s-tests: bash_unit
  165. # Run the functional tests with different k8s versions. Currently these are the latest point releases.
  166. # This list should be updated during the release process.
  167. K8S_VERSION="1.17.3" HYPERKUBE_CMD=" " HYPERKUBE_APISERVER_CMD="kube-apiserver" ./bash_unit dist/functional-test-k8s.sh
  168. K8S_VERSION="1.16.7" HYPERKUBE_CMD=" " HYPERKUBE_APISERVER_CMD="kube-apiserver" ./bash_unit dist/functional-test-k8s.sh
  169. K8S_VERSION="1.15.10" HYPERKUBE_CMD=" " HYPERKUBE_APISERVER_CMD="kube-apiserver" ./bash_unit dist/functional-test-k8s.sh
  170. # K8S_VERSION="1.7.6" ./bash_unit dist/functional-test-k8s.sh
  171. # K8S_VERSION="1.6.10" ./bash_unit dist/functional-test-k8s.sh
  172. # K8S_VERSION="1.5.7" ./bash_unit dist/functional-test-k8s.sh #kube-flannel.yml is incompatible
  173. # K8S_VERSION="1.4.12" ./bash_unit dist/functional-test-k8s.sh #kube-flannel.yml is incompatible
  174. # K8S_VERSION="1.3.10" ./bash_unit dist/functional-test-k8s.sh #kube-flannel.yml is incompatible
  175. docker-push: dist/flanneld-$(TAG)-$(ARCH).docker
  176. docker push $(REGISTRY):$(TAG)-$(ARCH)
  177. docker-manifest-amend:
  178. DOCKER_CLI_EXPERIMENTAL=enabled docker manifest create --amend $(REGISTRY):$(TAG) $(REGISTRY):$(TAG)-$(ARCH)
  179. docker-manifest-push:
  180. DOCKER_CLI_EXPERIMENTAL=enabled docker manifest push --purge $(REGISTRY):$(TAG)
  181. docker-push-all:
  182. ARCH=amd64 make docker-push docker-manifest-amend
  183. ARCH=arm make docker-push docker-manifest-amend
  184. ARCH=arm64 make docker-push docker-manifest-amend
  185. ARCH=ppc64le make docker-push docker-manifest-amend
  186. ARCH=s390x make docker-push docker-manifest-amend
  187. make docker-manifest-push
  188. flannel-git:
  189. ARCH=amd64 REGISTRY=quay.io/coreos/flannel-git make clean dist/flanneld-$(TAG)-amd64.docker docker-push docker-manifest-amend
  190. ARCH=arm REGISTRY=quay.io/coreos/flannel-git make clean dist/flanneld-$(TAG)-arm.docker docker-push docker-manifest-amend
  191. ARCH=arm64 REGISTRY=quay.io/coreos/flannel-git make clean dist/flanneld-$(TAG)-arm64.docker docker-push docker-manifest-amend
  192. ARCH=ppc64le REGISTRY=quay.io/coreos/flannel-git make clean dist/flanneld-$(TAG)-ppc64le.docker docker-push docker-manifest-amend
  193. ARCH=s390x REGISTRY=quay.io/coreos/flannel-git make clean dist/flanneld-$(TAG)-s390x.docker docker-push docker-manifest-amend
  194. REGISTRY=quay.io/coreos/flannel-git make docker-manifest-push
  195. install:
  196. # This is intended as just a developer convenience to help speed up non-containerized builds
  197. # It is NOT how you install flannel
  198. CGO_ENABLED=1 go install -v github.com/flannel-io/flannel
  199. minikube-start:
  200. minikube start --network-plugin cni
  201. minikube-build-image:
  202. CGO_ENABLED=1 go build -v -o dist/flanneld-amd64
  203. # Make sure the minikube docker is being used "eval $(minikube docker-env)"
  204. sh -c 'eval $$(minikube docker-env) && docker build -f Dockerfile.amd64 -t flannel/minikube .'
  205. minikube-deploy-flannel:
  206. kubectl apply -f Documentation/minikube.yml
  207. minikube-remove-flannel:
  208. kubectl delete -f Documentation/minikube.yml
  209. minikube-restart-pod:
  210. # Use this to pick up a new image
  211. kubectl delete pods -l app=flannel --grace-period=0
  212. kubernetes-logs:
  213. kubectl logs `kubectl get po -l app=flannel -o=custom-columns=NAME:metadata.name --no-headers=true` -c kube-flannel -f
  214. LOCAL_IP_ENV?=$(shell ip route get 8.8.8.8 | head -1 | awk '{print $$7}')
  215. run-etcd: stop-etcd
  216. docker run --detach \
  217. -p 2379:2379 \
  218. --name flannel-etcd quay.io/coreos/etcd \
  219. etcd \
  220. --advertise-client-urls "http://$(LOCAL_IP_ENV):2379,http://127.0.0.1:2379,http://$(LOCAL_IP_ENV):4001,http://127.0.0.1:4001" \
  221. --listen-client-urls "http://0.0.0.0:2379,http://0.0.0.0:4001"
  222. stop-etcd:
  223. @-docker rm -f flannel-etcd
  224. run-k8s-apiserver: stop-k8s-apiserver
  225. docker run --detach --net=host \
  226. --name calico-k8s-apiserver \
  227. gcr.io/google_containers/hyperkube-amd64:$(K8S_VERSION) \
  228. /hyperkube apiserver --etcd-servers=http://$(LOCAL_IP_ENV):2379 \
  229. --service-cluster-ip-range=10.101.0.0/16
  230. stop-k8s-apiserver:
  231. @-docker rm -f calico-k8s-apiserver
  232. run-local-kube-flannel-with-prereqs: run-etcd run-k8s-apiserver dist/flanneld
  233. while ! kubectl apply -f dist/fake-node.yaml; do sleep 1; done
  234. $(MAKE) run-local-kube-flannel
  235. run-local-kube-flannel:
  236. # Currently this requires the netconf to be in /etc/kube-flannel/net-conf.json
  237. sudo NODE_NAME=test dist/flanneld --kube-subnet-mgr --kube-api-url http://127.0.0.1:8080