Makefile 11 KB

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