-
Notifications
You must be signed in to change notification settings - Fork 160
/
Copy pathMakefile
132 lines (116 loc) · 4.82 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
.PHONY: all test
default: all
all: test
test: ut
K8S_VERSION=v1.7.3
CALICO_BUILD?=calico/go-build
PACKAGE_NAME?=projectcalico/libcalico-go
LOCAL_USER_ID?=$(shell id -u $$USER)
## Use this to populate the vendor directory after checking out the repository.
vendor: glide.yaml
# To update upstream dependencies, delete the glide.lock file first.
# To build without Docker just run "glide install -strip-vendor"
docker run --rm \
-v $(CURDIR):/go/src/github.com/$(PACKAGE_NAME):rw \
-v $(HOME)/.glide:/home/user/.glide:rw \
-e LOCAL_USER_ID=$(LOCAL_USER_ID) \
$(CALICO_BUILD) /bin/sh -c ' \
cd /go/src/github.com/$(PACKAGE_NAME) && \
glide install --strip-vendor'
.PHONY: ut
## Run the UTs locally. This requires a local etcd and local kubernetes master to be running.
ut: vendor
./run-uts
.PHONY: test-containerized
## Run the tests in a container. Useful for CI, Mac dev.
test-containerized: vendor run-etcd run-kubernetes-master
-mkdir -p .go-pkg-cache
docker run --rm --privileged --net=host \
-e LOCAL_USER_ID=$(LOCAL_USER_ID) \
-v $(CURDIR)/.go-pkg-cache:/go/pkg/:rw \
-v $(CURDIR):/go/src/github.com/$(PACKAGE_NAME):rw \
$(CALICO_BUILD) sh -c 'cd /go/src/github.com/$(PACKAGE_NAME) && make WHAT=$(WHAT) SKIP=$(SKIP) ut'
## Run etcd as a container (calico-etcd)
run-etcd: stop-etcd
docker run --detach \
--net=host \
--entrypoint=/usr/local/bin/etcd \
--name calico-etcd quay.io/coreos/etcd:v3.1.7 \
--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" \
--listen-client-urls "http://0.0.0.0:2379,http://0.0.0.0:4001"
## Run a local kubernetes master with API via hyperkube
run-kubernetes-master: stop-kubernetes-master
# Run a Kubernetes apiserver using Docker.
docker run \
--net=host --name st-apiserver \
--detach \
gcr.io/google_containers/hyperkube-amd64:${K8S_VERSION} \
/hyperkube 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; do echo "Trying to create ClusterRoleBinding"; sleep 2; done
# And run the controller manager.
docker run \
--net=host --name st-controller-manager \
--detach \
gcr.io/google_containers/hyperkube-amd64:${K8S_VERSION} \
/hyperkube controller-manager \
--master=127.0.0.1:8080 \
--min-resync-period=3m \
--allocate-node-cidrs=true \
--cluster-cidr=10.10.0.0/16 \
--v=5
# Create CustomResourceDefinition (CRD) for Calico resources
# from the manifest crds.yaml
docker run \
--net=host \
--rm \
-v $(CURDIR):/manifests \
lachlanevenson/k8s-kubectl:${K8S_VERSION} \
--server=http://localhost:8080 \
apply -f manifests/test/crds.yaml
# Create a Node in the API for the tests to use.
docker run \
--net=host \
--rm \
-v $(CURDIR):/manifests \
lachlanevenson/k8s-kubectl:${K8S_VERSION} \
--server=http://localhost:8080 \
apply -f manifests/test/mock-node.yaml
## Stop the local kubernetes master
stop-kubernetes-master:
# Delete the cluster role binding.
-docker exec st-apiserver kubectl delete clusterrolebinding anonymous-admin
# Stop master components.
-docker rm -f st-apiserver st-controller-manager
## Stop the etcd container (calico-etcd)
stop-etcd:
-docker rm -f calico-etcd
.PHONY: clean
## Removes all .coverprofile files, the vendor dir, and .go-pkg-cache
clean:
find . -name '*.coverprofile' -type f -delete
rm -rf vendor .go-pkg-cache
.PHONY: help
## Display this help text
help: # Some kind of magic from https://gist.github.com/rcmachado/af3db315e31383502660
$(info Available targets)
@awk '/^[a-zA-Z\-\_0-9\/]+:/ { \
nb = sub( /^## /, "", helpMsg ); \
if(nb == 0) { \
helpMsg = $$0; \
nb = sub( /^[^:]*:.* ## /, "", helpMsg ); \
} \
if (nb) \
printf "\033[1;31m%-" width "s\033[0m %s\n", $$1, helpMsg; \
} \
{ helpMsg = $$0 }' \
width=23 \
$(MAKEFILE_LIST)