Makefile 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  1. .PHONY: test e2e-test cover gofmt gofmt-fix license-check clean tar.gz docker-push release docker-push-all flannel-git
  2. # Registry used for publishing images
  3. REGISTRY?=quay.io/coreos/flannel
  4. # Default tag and architecture. Can be overridden
  5. TAG?=$(shell git describe --tags --dirty)
  6. ARCH?=amd64
  7. # These variables can be overridden by setting an environment variable.
  8. TEST_PACKAGES?=pkg/ip subnet subnet/etcdv2 network
  9. TEST_PACKAGES_EXPANDED=$(TEST_PACKAGES:%=github.com/coreos/flannel/%)
  10. PACKAGES?=$(TEST_PACKAGES) network
  11. PACKAGES_EXPANDED=$(PACKAGES:%=github.com/coreos/flannel/%)
  12. # Set the (cross) compiler to use for different architectures
  13. ifeq ($(ARCH),amd64)
  14. CC=gcc
  15. endif
  16. ifeq ($(ARCH),arm)
  17. CC=arm-linux-gnueabihf-gcc
  18. endif
  19. ifeq ($(ARCH),arm64)
  20. CC=aarch64-linux-gnu-gcc
  21. endif
  22. ifeq ($(ARCH),ppc64le)
  23. CC=powerpc64le-linux-gnu-gcc
  24. endif
  25. ifeq ($(ARCH),s390x)
  26. CC=s390x-linux-gnu-gcc
  27. endif
  28. GOARM=7
  29. # List images with gcloud alpha container images list-tags gcr.io/google_containers/kube-cross
  30. KUBE_CROSS_TAG=v1.8.3-1
  31. IPTABLES_VERSION=1.4.21
  32. dist/flanneld: $(shell find . -type f -name '*.go')
  33. go build -o dist/flanneld \
  34. -ldflags "-s -w -X github.com/coreos/flannel/version.Version=$(TAG)"
  35. test: license-check gofmt
  36. # Run the unit tests
  37. go test -cover $(TEST_PACKAGES_EXPANDED)
  38. # Test the docker-opts script
  39. cd dist; ./mk-docker-opts_tests.sh
  40. # Run the functional tests
  41. make e2e-test
  42. e2e-test: bash_unit dist/flanneld-e2e-$(TAG)-$(ARCH).docker
  43. $(MAKE) -C images/iperf3 ARCH=$(ARCH)
  44. FLANNEL_DOCKER_IMAGE=$(REGISTRY):$(TAG)-$(ARCH) ./bash_unit dist/functional-test.sh
  45. FLANNEL_DOCKER_IMAGE=$(REGISTRY):$(TAG)-$(ARCH) ./bash_unit dist/functional-test-k8s.sh
  46. cover:
  47. # A single package must be given - e.g. 'PACKAGES=pkg/ip make cover'
  48. go test -coverprofile cover.out $(PACKAGES_EXPANDED)
  49. go tool cover -html=cover.out
  50. # Throw an error if gofmt finds problems.
  51. # "read" will return a failure return code if there is no output. This is inverted wth the "!"
  52. gofmt:
  53. bash -c '! gofmt -d $(PACKAGES) 2>&1 | read'
  54. gofmt-fix:
  55. gofmt -w $(PACKAGES)
  56. license-check:
  57. ./license-check.sh
  58. update-glide:
  59. # go get -d -u github.com/Masterminds/glide
  60. glide update --strip-vendor
  61. # go get -d -u github.com/sgotti/glide-vc
  62. glide vc --only-code --no-tests
  63. bash_unit:
  64. wget https://raw.githubusercontent.com/pgrange/bash_unit/v1.6.0/bash_unit
  65. chmod +x bash_unit
  66. clean:
  67. rm -f dist/flanneld*
  68. rm -f dist/*.aci
  69. rm -f dist/*.docker
  70. rm -f dist/*.tar.gz
  71. ## Create a docker image on disk for a specific arch and tag
  72. dist/flanneld-$(TAG)-$(ARCH).docker: dist/flanneld-$(ARCH) dist/iptables-$(ARCH)
  73. docker build -f Dockerfile.$(ARCH) -t $(REGISTRY):$(TAG)-$(ARCH) .
  74. docker save -o dist/flanneld-$(TAG)-$(ARCH).docker $(REGISTRY):$(TAG)-$(ARCH)
  75. # amd64 gets an image with the suffix too (i.e. it's the default)
  76. ifeq ($(ARCH),amd64)
  77. docker build -f Dockerfile.$(ARCH) -t $(REGISTRY):$(TAG) .
  78. endif
  79. # This will build flannel natively using golang image
  80. dist/flanneld-e2e-$(TAG)-$(ARCH).docker:
  81. # valid values for ARCH are [amd64 arm arm64 ppc64le s390x]
  82. docker run -e GOARM=$(GOARM) \
  83. -u $(shell id -u):$(shell id -g) \
  84. -v $(CURDIR):/go/src/github.com/coreos/flannel:ro \
  85. -v $(CURDIR)/dist:/go/src/github.com/coreos/flannel/dist \
  86. golang:1.8.3 /bin/bash -c '\
  87. cd /go/src/github.com/coreos/flannel && \
  88. CGO_ENABLED=1 make -e dist/flanneld && \
  89. mv dist/flanneld dist/flanneld-$(ARCH)'
  90. docker build -f Dockerfile.$(ARCH) -t $(REGISTRY):$(TAG)-$(ARCH) .
  91. ## Create an ACI on disk for a specific arch and tag
  92. dist/flanneld-$(TAG)-$(ARCH).aci: dist/flanneld-$(TAG)-$(ARCH).docker
  93. docker2aci dist/flanneld-$(TAG)-$(ARCH).docker
  94. mv quay.io-coreos-flannel-$(TAG)-$(ARCH).aci dist/flanneld-$(TAG)-$(ARCH).aci
  95. actool patch-manifest --replace --capability=CAP_NET_ADMIN \
  96. --mounts=run-flannel,path=/run/flannel,readOnly=false:etc-ssl-etcd,path=/etc/ssl/etcd,readOnly=true:dev-net,path=/dev/net,readOnly=false \
  97. dist/flanneld-$(TAG)-$(ARCH).aci
  98. docker-push: dist/flanneld-$(TAG)-$(ARCH).docker
  99. docker push $(REGISTRY):$(TAG)-$(ARCH)
  100. # amd64 gets an image with the suffix too (i.e. it's the default)
  101. ifeq ($(ARCH),amd64)
  102. docker push $(REGISTRY):$(TAG)
  103. endif
  104. ## Build an architecture specific flanneld binary
  105. dist/flanneld-$(ARCH):
  106. # Build for other platforms with 'ARCH=$$ARCH make dist/flanneld-$$ARCH'
  107. # valid values for $$ARCH are [amd64 arm arm64 ppc64le s390x]
  108. docker run -e CC=$(CC) -e GOARM=$(GOARM) -e GOARCH=$(ARCH) \
  109. -u $(shell id -u):$(shell id -g) \
  110. -v $(CURDIR):/go/src/github.com/coreos/flannel:ro \
  111. -v $(CURDIR)/dist:/go/src/github.com/coreos/flannel/dist \
  112. gcr.io/google_containers/kube-cross:$(KUBE_CROSS_TAG) /bin/bash -c '\
  113. cd /go/src/github.com/coreos/flannel && \
  114. CGO_ENABLED=1 make -e dist/flanneld && \
  115. mv dist/flanneld dist/flanneld-$(ARCH) && \
  116. file dist/flanneld-$(ARCH)'
  117. ## Build an architecture specific iptables binary
  118. dist/iptables-$(ARCH):
  119. docker run -e CC=$(CC) -e GOARM=$(GOARM) -e GOARCH=$(ARCH) \
  120. -u $(shell id -u):$(shell id -g) \
  121. -v $(CURDIR):/go/src/github.com/coreos/flannel:ro \
  122. -v $(CURDIR)/dist:/go/src/github.com/coreos/flannel/dist \
  123. gcr.io/google_containers/kube-cross:$(KUBE_CROSS_TAG) /bin/bash -c '\
  124. curl -sSL http://www.netfilter.org/projects/iptables/files/iptables-$(IPTABLES_VERSION).tar.bz2 | tar -jxv && \
  125. cd iptables-$(IPTABLES_VERSION) && \
  126. ./configure \
  127. --prefix=/usr \
  128. --mandir=/usr/man \
  129. --disable-shared \
  130. --disable-devel \
  131. --disable-nftables \
  132. --enable-static \
  133. --host=amd64 && \
  134. make && \
  135. cp iptables/xtables-multi /go/src/github.com/coreos/flannel/dist/iptables-$(ARCH) && \
  136. cd /go/src/github.com/coreos/flannel && \
  137. file dist/iptables-$(ARCH)'
  138. ## Build a .tar.gz for the amd64 ppc64le arm arm64 flanneld binary
  139. tar.gz:
  140. ARCH=amd64 make dist/flanneld-amd64
  141. tar --transform='flags=r;s|-amd64||' -zcvf dist/flannel-$(TAG)-linux-amd64.tar.gz -C dist flanneld-amd64 mk-docker-opts.sh ../README.md
  142. tar -tvf dist/flannel-$(TAG)-linux-amd64.tar.gz
  143. ARCH=ppc64le make dist/flanneld-ppc64le
  144. tar --transform='flags=r;s|-ppc64le||' -zcvf dist/flannel-$(TAG)-linux-ppc64le.tar.gz -C dist flanneld-ppc64le mk-docker-opts.sh ../README.md
  145. tar -tvf dist/flannel-$(TAG)-linux-ppc64le.tar.gz
  146. ARCH=arm make dist/flanneld-arm
  147. tar --transform='flags=r;s|-arm||' -zcvf dist/flannel-$(TAG)-linux-arm.tar.gz -C dist flanneld-arm mk-docker-opts.sh ../README.md
  148. tar -tvf dist/flannel-$(TAG)-linux-arm.tar.gz
  149. ARCH=arm64 make dist/flanneld-arm64
  150. tar --transform='flags=r;s|-arm64||' -zcvf dist/flannel-$(TAG)-linux-arm64.tar.gz -C dist flanneld-arm64 mk-docker-opts.sh ../README.md
  151. tar -tvf dist/flannel-$(TAG)-linux-arm64.tar.gz
  152. ARCH=s390x make dist/flanneld-s390x
  153. tar --transform='flags=r;s|-s390x||' -zcvf dist/flannel-$(TAG)-linux-s390x.tar.gz -C dist flanneld-s390x mk-docker-opts.sh ../README.md
  154. tar -tvf dist/flannel-$(TAG)-linux-s390x.tar.gz
  155. ## Make a release after creating a tag
  156. release: tar.gz release-tests
  157. ARCH=amd64 make dist/flanneld-$(TAG)-amd64.aci
  158. ARCH=arm make dist/flanneld-$(TAG)-arm.aci
  159. ARCH=arm64 make dist/flanneld-$(TAG)-arm64.aci
  160. ARCH=ppc64le make dist/flanneld-$(TAG)-ppc64le.aci
  161. ARCH=s390x make dist/flanneld-$(TAG)-s390x.aci
  162. @echo "Everything should be built for $(TAG)"
  163. @echo "Add all *.aci, flanneld-* and *.tar.gz files from dist/ to the Github release"
  164. @echo "Use make docker-push-all to push the images to a registry"
  165. release-tests: bash_unit
  166. # Run the functional tests with different etcd versions.
  167. ETCD_IMG="quay.io/coreos/etcd:latest" ./bash_unit dist/functional-test.sh
  168. ETCD_IMG="quay.io/coreos/etcd:v3.2.7" ./bash_unit dist/functional-test.sh
  169. ETCD_IMG="quay.io/coreos/etcd:v3.1.10" ./bash_unit dist/functional-test.sh
  170. ETCD_IMG="quay.io/coreos/etcd:v3.0.17" ./bash_unit dist/functional-test.sh
  171. # Etcd v2 docker image format is different. Override the etcd binary location so it works.
  172. ETCD_IMG="quay.io/coreos/etcd:v2.3.8" ETCD_LOCATION=" " ./bash_unit dist/functional-test.sh
  173. # Run the functional tests with different k8s versions. Currently these are the latest point releases.
  174. # This list should be updated during the release process.
  175. K8S_VERSION="1.7.6" ./bash_unit dist/functional-test-k8s.sh
  176. K8S_VERSION="1.6.10" ./bash_unit dist/functional-test-k8s.sh
  177. # K8S_VERSION="1.5.7" ./bash_unit dist/functional-test-k8s.sh #kube-flannel.yml is incompatible
  178. # K8S_VERSION="1.4.12" ./bash_unit dist/functional-test-k8s.sh #kube-flannel.yml is incompatible
  179. # K8S_VERSION="1.3.10" ./bash_unit dist/functional-test-k8s.sh #kube-flannel.yml is incompatible
  180. docker-push-all:
  181. ARCH=amd64 make docker-push
  182. ARCH=arm make docker-push
  183. ARCH=arm64 make docker-push
  184. ARCH=ppc64le make docker-push
  185. ARCH=s390x make docker-push
  186. flannel-git:
  187. ARCH=amd64 REGISTRY=quay.io/coreos/flannel-git make clean dist/flanneld-$(TAG)-amd64.docker docker-push
  188. docker build -f Dockerfile.amd64 -t quay.io/coreos/flannel-git .
  189. docker push quay.io/coreos/flannel-git
  190. ARCH=arm REGISTRY=quay.io/coreos/flannel-git make clean dist/flanneld-$(TAG)-arm.docker docker-push
  191. ARCH=arm64 REGISTRY=quay.io/coreos/flannel-git make clean dist/flanneld-$(TAG)-arm64.docker docker-push
  192. ARCH=ppc64le REGISTRY=quay.io/coreos/flannel-git make clean dist/flanneld-$(TAG)-ppc64le.docker docker-push
  193. ARCH=s390x REGISTRY=quay.io/coreos/flannel-git make clean dist/flanneld-$(TAG)-s390x.docker docker-push
  194. install:
  195. # This is intended as just a developer convenience to help speed up non-containerized builds
  196. # It is NOT how you install flannel
  197. CGO_ENABLED=1 go install -v github.com/coreos/flannel
  198. minikube-start:
  199. minikube start --network-plugin cni
  200. minikube-build-image: dist/iptables-amd64
  201. CGO_ENABLED=1 go build -v -o dist/flanneld-amd64
  202. # Make sure the minikube docker is being used "eval $(minikube docker-env)"
  203. sh -c 'eval $$(minikube docker-env) && docker build -f Dockerfile.amd64 -t flannel/minikube .'
  204. minikube-deploy-flannel:
  205. kubectl apply -f Documentation/minikube.yml
  206. minikube-remove-flannel:
  207. kubectl delete -f Documentation/minikube.yml
  208. minikube-restart-pod:
  209. # Use this to pick up a new image
  210. kubectl delete pods -l app=flannel --grace-period=0
  211. kubernetes-logs:
  212. kubectl logs `kubectl get po -l app=flannel -o=custom-columns=NAME:metadata.name --no-headers=true` -c kube-flannel -f
  213. LOCAL_IP_ENV?=$(shell ip route get 8.8.8.8 | head -1 | awk '{print $$7}')
  214. run-etcd: stop-etcd
  215. docker run --detach \
  216. -p 2379:2379 \
  217. --name flannel-etcd quay.io/coreos/etcd \
  218. etcd \
  219. --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" \
  220. --listen-client-urls "http://0.0.0.0:2379,http://0.0.0.0:4001"
  221. stop-etcd:
  222. @-docker rm -f flannel-etcd
  223. K8S_VERSION=v1.6.6
  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