Skip to content

Commit bc9dade

Browse files
Merge pull request #181 from caseydavenport/merge-master
Pull in changes from master
2 parents f6ddbe0 + 30b2451 commit bc9dade

File tree

7 files changed

+120
-44
lines changed

7 files changed

+120
-44
lines changed

Dockerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
FROM alpine
22
MAINTAINER Tom Denham <[email protected]>
3-
ADD dist/libnetwork-plugin /libnetwork-plugin
3+
ADD dist/amd64/libnetwork-plugin /libnetwork-plugin
44
ENTRYPOINT ["/libnetwork-plugin"]
55

Dockerfile-ppc64le

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
FROM ppc64le/alpine
2+
MAINTAINER Tom Denham <[email protected]>
3+
ADD dist/ppc64le/libnetwork-plugin /libnetwork-plugin
4+
ENTRYPOINT ["/libnetwork-plugin"]

Makefile

+63-34
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,38 @@
1+
##############################################################################
2+
# The build architecture is select by setting the ARCH variable.
3+
# For example: When building on ppc64le you could use ARCH=ppc64le make <....>.
4+
# When ARCH is undefined it defaults to amd64.
5+
ARCH?=amd64
6+
ifeq ($(ARCH),amd64)
7+
ARCHTAG:=
8+
GO_BUILD_VER?=v0.12
9+
BUSYBOX_IMAGE?=busybox:latest
10+
DIND_IMAGE?=docker:17.12.0-dind
11+
endif
12+
13+
ifeq ($(ARCH),ppc64le)
14+
ARCHTAG:=-ppc64le
15+
GO_BUILD_VER?=latest
16+
BUSYBOX_IMAGE?=ppc64le/busybox:latest
17+
DIND_IMAGE?=ppc64le/docker:dind
18+
endif
19+
120
# Disable make's implicit rules, which are not useful for golang, and slow down the build
221
# considerably.
322
.SUFFIXES:
423

5-
GO_BUILD_VER?=v0.9
6-
724
SRC_FILES=$(shell find . -type f -name '*.go')
825

926
# These variables can be overridden by setting an environment variable.
1027
LOCAL_IP_ENV?=$(shell ip route get 8.8.8.8 | head -1 | awk '{print $$7}')
1128

1229
# Can choose different docker versions see list here - https://hub.docker.com/_/docker/
13-
DOCKER_VERSION?=17.12.0-dind
1430
HOST_CHECKOUT_DIR?=$(CURDIR)
15-
CONTAINER_NAME?=calico/libnetwork-plugin
16-
GO_BUILD_CONTAINER?=calico/go-build:$(GO_BUILD_VER)
17-
PLUGIN_LOCATION?=$(CURDIR)/dist/libnetwork-plugin
18-
DOCKER_BINARY_CONTAINER?=docker-binary-container
31+
CONTAINER_NAME?=calico/libnetwork-plugin$(ARCHTAG)
32+
GO_BUILD_CONTAINER?=calico/go-build$(ARCHTAG):$(GO_BUILD_VER)
33+
DIST=dist/$(ARCH)
34+
PLUGIN_LOCATION?=$(CURDIR)/$(DIST)/libnetwork-plugin
35+
DOCKER_BINARY_CONTAINER?=docker-binary-container$(ARCHTAG)
1936

2037
# To run with non-native docker (e.g. on Windows or OSX) you might need to overide this variable
2138
LOCAL_USER_ID?=$(shell id -u $$USER)
@@ -39,39 +56,41 @@ install:
3956
CGO_ENABLED=0 go install github.com/projectcalico/libnetwork-plugin
4057

4158
# Run the build in a container. Useful for CI
42-
dist/libnetwork-plugin: vendor
43-
-mkdir -p dist
59+
$(DIST)/libnetwork-plugin: vendor
60+
-mkdir -p $(DIST)
4461
-mkdir -p .go-pkg-cache
4562
docker run --rm \
4663
-v $(CURDIR):/go/src/github.com/projectcalico/libnetwork-plugin:ro \
47-
-v $(CURDIR)/dist:/go/src/github.com/projectcalico/libnetwork-plugin/dist \
64+
-v $(CURDIR)/$(DIST):/go/src/github.com/projectcalico/libnetwork-plugin/$(DIST) \
4865
-v $(CURDIR)/.go-pkg-cache:/go/pkg/:rw \
4966
-e LOCAL_USER_ID=$(LOCAL_USER_ID) \
67+
-e ARCH=$(ARCH) \
5068
$(GO_BUILD_CONTAINER) sh -c '\
5169
cd /go/src/github.com/projectcalico/libnetwork-plugin && \
5270
make build'
5371

5472
build: $(SRC_FILES) vendor
55-
CGO_ENABLED=0 go build -v -i -o dist/libnetwork-plugin -ldflags "-X main.VERSION=$(shell git describe --tags --dirty) -s -w" main.go
73+
CGO_ENABLED=0 go build -v -i -o $(DIST)/libnetwork-plugin -ldflags "-X main.VERSION=$(shell git describe --tags --dirty) -s -w" main.go
5674

57-
$(CONTAINER_NAME): dist/libnetwork-plugin
58-
docker build -t $(CONTAINER_NAME) .
75+
76+
$(CONTAINER_NAME): $(DIST)/libnetwork-plugin
77+
docker build -t $(CONTAINER_NAME) -f Dockerfile$(ARCHTAG) .
5978

6079
# Perform static checks on the code. The golint checks are allowed to fail, the others must pass.
6180
.PHONY: static-checks
6281
static-checks: vendor
6382
docker run --rm \
6483
-e LOCAL_USER_ID=$(LOCAL_USER_ID) \
6584
-v $(CURDIR):/go/src/github.com/projectcalico/libnetwork-plugin \
66-
calico/go-build sh -c '\
85+
$(GO_BUILD_CONTAINER) sh -c '\
6786
cd /go/src/github.com/projectcalico/libnetwork-plugin && \
6887
gometalinter --deadline=30s --disable-all --enable=goimports --enable=vet --enable=errcheck --enable=varcheck --enable=unused --enable=dupl $$(glide nv)'
6988

7089
run-etcd:
7190
@-docker rm -f calico-etcd
7291
docker run --detach \
7392
--net=host \
74-
--name calico-etcd quay.io/coreos/etcd \
93+
--name calico-etcd quay.io/coreos/etcd:v3.2.5$(ARCHTAG) \
7594
etcd \
7695
--advertise-client-urls "http://$(LOCAL_IP_ENV):2379,http://127.0.0.1:2379" \
7796
--listen-client-urls "http://0.0.0.0:2379"
@@ -85,28 +104,28 @@ endif
85104
# Check that the version output appears on a line of its own (the -x option to grep).
86105
# Tests that the "git tag" makes it into the binary. Main point is to catch "-dirty" builds
87106
@echo "Checking if the tag made it into the binary"
88-
docker run --rm calico/libnetwork-plugin -v | grep -x $(VERSION) || (echo "Reported version:" `docker run --rm calico/libnetwork-plugin -v` "\nExpected version: $(VERSION)" && exit 1)
89-
docker tag calico/libnetwork-plugin calico/libnetwork-plugin:$(VERSION)
90-
docker tag calico/libnetwork-plugin quay.io/calico/libnetwork-plugin:$(VERSION)
91-
docker tag calico/libnetwork-plugin quay.io/calico/libnetwork-plugin:latest
107+
docker run --rm calico/libnetwork-plugin$(ARCHTAG) -v | grep -x $(VERSION) || (echo "Reported version:" `docker run --rm calico/libnetwork-plugin$(ARCHTAG) -v` "\nExpected version: $(VERSION)" && exit 1)
108+
docker tag calico/libnetwork-plugin$(ARCHTAG) calico/libnetwork-plugin$(ARCHTAG):$(VERSION)
109+
docker tag calico/libnetwork-plugin$(ARCHTAG) quay.io/calico/libnetwork-plugin$(ARCHTAG):$(VERSION)
110+
docker tag calico/libnetwork-plugin$(ARCHTAG) quay.io/calico/libnetwork-plugin$(ARCHTAG):latest
92111

93-
@echo "Now push the tag and images. Then create a release on Github and attach the dist/libnetwork-plugin binary"
112+
@echo "Now push the tag and images. Then create a release on Github and attach the $(DIST)/libnetwork-plugin binary"
94113
@echo "git push origin $(VERSION)"
95-
@echo "docker push calico/libnetwork-plugin:$(VERSION)"
96-
@echo "docker push quay.io/calico/libnetwork-plugin:$(VERSION)"
97-
@echo "docker push calico/libnetwork-plugin:latest"
98-
@echo "docker push quay.io/calico/libnetwork-plugin:latest"
114+
@echo "docker push calico/libnetwork-plugin$(ARCHTAG):$(VERSION)"
115+
@echo "docker push quay.io/calico/libnetwork-plugin$(ARCHTAG):$(VERSION)"
116+
@echo "docker push calico/libnetwork-plugin$(ARCHTAG):latest"
117+
@echo "docker push quay.io/calico/libnetwork-plugin$(ARCHTAG):latest"
99118

100119
clean:
101-
rm -rf dist *.tar vendor docker .go-pkg-cache
120+
rm -rf $(DIST) bin *.tar vendor .go-pkg-cache
102121

103-
run-plugin: run-etcd dist/libnetwork-plugin
122+
run-plugin: run-etcd $(DIST)/libnetwork-plugin
104123
-docker rm -f dind
105124
docker run -tid -h test --name dind --privileged $(ADDITIONAL_DIND_ARGS) \
106125
-e ETCD_ENDPOINTS=http://$(LOCAL_IP_ENV):2379 \
107126
-p 5375:2375 \
108127
-v $(PLUGIN_LOCATION):/libnetwork-plugin \
109-
docker:$(DOCKER_VERSION) --cluster-store=etcd://$(LOCAL_IP_ENV):2379
128+
$(DIND_IMAGE) --cluster-store=etcd://$(LOCAL_IP_ENV):2379
110129
# View the logs by running 'docker exec dind cat plugin.log'
111130
docker exec -tid --privileged dind sh -c 'sysctl -w net.ipv6.conf.default.disable_ipv6=0'
112131
docker exec -tid --privileged dind sh -c '/libnetwork-plugin 2>>/plugin.log'
@@ -118,18 +137,28 @@ run-plugin: run-etcd dist/libnetwork-plugin
118137
test:
119138
CGO_ENABLED=0 ginkgo -v tests/*
120139

121-
test-containerized: dist/libnetwork-plugin
140+
# Target test-containerized needs the docker binary to be available in the go-build container.
141+
# Obtaining it from the docker:dind images docker should provided the latest version. However,
142+
# this assumes that the go_build container has the required dependencies or that docker is static.
143+
# This may not be the case in all configurations. In this cases you should pre-populate ./bin
144+
# with a docker binary compatible with the go-build image that is used.
145+
bin/docker:
122146
-docker rm -f $(DOCKER_BINARY_CONTAINER) 2>&1
123-
docker create --name $(DOCKER_BINARY_CONTAINER) docker:$(DOCKER_VERSION)
124-
docker cp $(DOCKER_BINARY_CONTAINER):/usr/local/bin/docker .
147+
mkdir -p ./bin
148+
docker create --name $(DOCKER_BINARY_CONTAINER) $(DIND_IMAGE)
149+
docker cp $(DOCKER_BINARY_CONTAINER):/usr/local/bin/docker ./bin/docker
125150
docker rm -f $(DOCKER_BINARY_CONTAINER)
126-
docker run -ti --rm --net=host \
151+
152+
test-containerized: $(DIST)/libnetwork-plugin bin/docker
153+
docker run -t --rm --net=host \
127154
-v $(CURDIR):/go/src/github.com/projectcalico/libnetwork-plugin \
128155
-v /var/run/docker.sock:/var/run/docker.sock \
129-
-v $(CURDIR)/docker:/usr/bin/docker \
130-
-e PLUGIN_LOCATION=$(CURDIR)/dist/libnetwork-plugin \
156+
-v $(CURDIR)/bin/docker:/usr/bin/docker \
157+
-e PLUGIN_LOCATION=$(CURDIR)/$(DIST)/libnetwork-plugin \
131158
-e LOCAL_USER_ID=0 \
132-
calico/go-build sh -c '\
159+
-e ARCH=$(ARCH) \
160+
-e BUSYBOX_IMAGE=$(BUSYBOX_IMAGE) \
161+
$(GO_BUILD_CONTAINER) sh -c '\
133162
cd /go/src/github.com/projectcalico/libnetwork-plugin && \
134163
make test'
135164

driver/ipam_driver.go

+2
Original file line numberDiff line numberDiff line change
@@ -179,9 +179,11 @@ func (i IpamDriver) RequestAddress(request *ipam.RequestAddressRequest) (*ipam.R
179179
version = ipNet.Version()
180180
if version == 4 {
181181
poolV4 = []caliconet.IPNet{caliconet.IPNet{IPNet: pool.Metadata.CIDR.IPNet}}
182+
numIPv4 = 1
182183
log.Debugln("Using specific pool ", poolV4)
183184
} else if version == 6 {
184185
poolV6 = []caliconet.IPNet{caliconet.IPNet{IPNet: pool.Metadata.CIDR.IPNet}}
186+
numIPv6 = 1
185187
log.Debugln("Using specific pool ", poolV6)
186188
}
187189
}

tests/custom_if_prefix/libnetwork_env_var_test.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package custom_if_prefix
33
import (
44
"fmt"
55
"math/rand"
6+
"os"
67

78
. "github.com/onsi/ginkgo"
89
. "github.com/onsi/gomega"
@@ -23,7 +24,7 @@ var _ = Describe("Running plugin with custom ENV", func() {
2324
DockerString(fmt.Sprintf("docker network create %s -d calico --ipam-driver calico-ipam", name))
2425

2526
// Create a container that will just sit in the background
26-
DockerString(fmt.Sprintf("docker run --net %s -tid --name %s busybox", name, name))
27+
DockerString(fmt.Sprintf("docker run --net %s -tid --name %s %s", name, name, os.Getenv("BUSYBOX_IMAGE") ))
2728

2829
// Gather information for assertions
2930
docker_endpoint := GetDockerEndpoint(name, name)

tests/custom_wep_labelling/libnetwork_env_var_test.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"fmt"
55
"math/rand"
66
"time"
7+
"os"
78

89
. "github.com/onsi/ginkgo"
910
. "github.com/onsi/gomega"
@@ -23,7 +24,7 @@ var _ = Describe("Running plugin with custom ENV", func() {
2324
DockerString(fmt.Sprintf("docker network create %s -d calico --ipam-driver calico-ipam", name))
2425

2526
// Create a container that will just sit in the background
26-
DockerString(fmt.Sprintf("docker run --net %s -tid --label not=expected --label org.projectcalico.label.foo=bar --label org.projectcalico.label.baz=quux --name %s busybox", name, name))
27+
DockerString(fmt.Sprintf("docker run --net %s -tid --label not=expected --label org.projectcalico.label.foo=bar --label org.projectcalico.label.baz=quux --name %s %s", name, name, os.Getenv("BUSYBOX_IMAGE") ))
2728

2829
// Gather information for assertions
2930
docker_endpoint := GetDockerEndpoint(name, name)
@@ -67,7 +68,7 @@ var _ = Describe("Running plugin with custom ENV", func() {
6768
DockerString(fmt.Sprintf("docker network create %s -d calico --ipam-driver calico-ipam", name))
6869

6970
// Create a container that will just sit in the background
70-
DockerString(fmt.Sprintf("docker run --net %s -tid --label not=expected --label org.projectcalico.label.foo=bar --label org.projectcalico.label.baz=quux --name %s busybox", name, name))
71+
DockerString(fmt.Sprintf("docker run --net %s -tid --label not=expected --label org.projectcalico.label.foo=bar --label org.projectcalico.label.baz=quux --name %s %s", name, name, os.Getenv("BUSYBOX_IMAGE") ))
7172

7273
// Gather information for assertions
7374
docker_endpoint := GetDockerEndpoint(name, name)

tests/default_environment/libnetwork_test.go

+45-6
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"fmt"
55
"math/rand"
66
"regexp"
7+
"os"
78

89
. "github.com/onsi/ginkgo"
910
. "github.com/onsi/gomega"
@@ -137,7 +138,7 @@ var _ = Describe("Libnetwork Tests", func() {
137138

138139
It("creates a container on a network and checks all assertions", func() {
139140
// Create a container that will just sit in the background
140-
DockerString(fmt.Sprintf("docker run --net %s -tid --name %s busybox", name, name))
141+
DockerString(fmt.Sprintf("docker run --net %s -tid --name %s %s", name, name, os.Getenv("BUSYBOX_IMAGE") ))
141142

142143
// Gather information for assertions
143144
docker_endpoint := GetDockerEndpoint(name, name)
@@ -182,7 +183,7 @@ var _ = Describe("Libnetwork Tests", func() {
182183
It("creates a container with specific MAC", func() {
183184
// Create a container that will just sit in the background
184185
chosen_mac := "00:22:33:44:55:66"
185-
DockerString(fmt.Sprintf("docker run --mac-address %s --net %s -tid --name %s busybox", chosen_mac, name, name))
186+
DockerString(fmt.Sprintf("docker run --mac-address %s --net %s -tid --name %s %s", chosen_mac, name, name, os.Getenv("BUSYBOX_IMAGE") ))
186187

187188
// Gather information for assertions
188189
docker_endpoint := GetDockerEndpoint(name, name)
@@ -219,7 +220,7 @@ var _ = Describe("Libnetwork Tests", func() {
219220

220221
PIt("creates a container with specific link local address", func() { // https://github.com/docker/docker/issues/28606
221222
// Create a container that will just sit in the background
222-
DockerString(fmt.Sprintf("docker run --link-local-ip 169.254.0.50 %s --net %s -tid --name %s busybox", name, name, name))
223+
DockerString(fmt.Sprintf("docker run --link-local-ip 169.254.0.50 %s --net %s -tid --name %s %s", name, name, name, os.Getenv("BUSYBOX_IMAGE") ))
223224

224225
// Delete container
225226
DockerString(fmt.Sprintf("docker rm -f %s", name))
@@ -234,7 +235,7 @@ var _ = Describe("Libnetwork Tests", func() {
234235
DockerString(fmt.Sprintf("docker network create %s --subnet 192.169.0.0/16 -d calico --ipam-driver calico-ipam", name_subnet))
235236
// Create a container that will just sit in the background
236237
chosen_ip := "192.169.50.51"
237-
DockerString(fmt.Sprintf("docker run --ip %s --net %s -tid --name %s busybox", chosen_ip, name_subnet, name_subnet))
238+
DockerString(fmt.Sprintf("docker run --ip %s --net %s -tid --name %s %s", chosen_ip, name_subnet, name_subnet, os.Getenv("BUSYBOX_IMAGE") ))
238239

239240
// Gather information for assertions
240241
docker_endpoint := GetDockerEndpoint(name_subnet, name_subnet)
@@ -269,9 +270,47 @@ var _ = Describe("Libnetwork Tests", func() {
269270
DockerString(fmt.Sprintf("docker network rm %s", name_subnet))
270271
})
271272

273+
It("creates a container in network with a subnet", func() {
274+
name_subnet := fmt.Sprintf("run%d", rand.Uint32())
275+
DockerString(fmt.Sprintf("docker network create %s --subnet 192.169.0.0/16 -d calico --ipam-driver calico-ipam", name_subnet))
276+
DockerString(fmt.Sprintf("docker run --net %s -tid --name %s %s", name_subnet, name_subnet, os.Getenv("BUSYBOX_IMAGE") ))
277+
278+
// Gather information for assertions
279+
docker_endpoint := GetDockerEndpoint(name_subnet, name_subnet)
280+
ip := docker_endpoint.IPAddress
281+
mac := docker_endpoint.MacAddress
282+
endpoint_id := docker_endpoint.EndpointID
283+
interface_name_subnet := "cali" + endpoint_id[:mathutils.MinInt(11, len(endpoint_id))]
284+
285+
Expect(ip).Should(HavePrefix("192.169."))
286+
287+
// Check that the endpoint is created in etcd
288+
etcd_endpoint := GetEtcdString(fmt.Sprintf("/calico/v1/host/test/workload/libnetwork/libnetwork/endpoint/%s", endpoint_id))
289+
Expect(etcd_endpoint).Should(MatchJSON(fmt.Sprintf(
290+
`{"state":"active","name":"%s","active_instance_id":"","mac":"%s","profile_ids":["%s"],"ipv4_nets":["%s/32"],"ipv6_nets":[]}`,
291+
interface_name_subnet, mac, name_subnet, ip)))
292+
293+
// Check the interface exists on the Host - it has an autoassigned
294+
// mac and ip, so don't check anything!
295+
DockerString(fmt.Sprintf("ip addr show %s", interface_name_subnet))
296+
297+
// Make sure the interface in the container exists and has the assigned ip and mac
298+
container_interface_string := DockerString(fmt.Sprintf("docker exec -i %s ip addr", name_subnet))
299+
Expect(container_interface_string).Should(ContainSubstring(ip))
300+
Expect(container_interface_string).Should(ContainSubstring(mac))
301+
302+
// Make sure the container has the routes we expect
303+
routes := DockerString(fmt.Sprintf("docker exec -i %s ip route", name_subnet))
304+
Expect(routes).Should(Equal("default via 169.254.1.1 dev cali0 \n169.254.1.1 dev cali0 scope link"))
305+
306+
// Delete container and network
307+
DockerString(fmt.Sprintf("docker rm -f %s", name_subnet))
308+
DockerString(fmt.Sprintf("docker network rm %s", name_subnet))
309+
})
310+
272311
It("creates a container with labels, but do not expect those in endpoint", func() {
273312
// Create a container that will just sit in the background
274-
DockerString(fmt.Sprintf("docker run --net %s -tid --label org.projectcalico.label.foo=bar --label org.projectcalico.label.baz=quux --name %s busybox", name, name))
313+
DockerString(fmt.Sprintf("docker run --net %s -tid --label org.projectcalico.label.foo=bar --label org.projectcalico.label.baz=quux --name %s %s", name, name, os.Getenv("BUSYBOX_IMAGE") ))
275314

276315
// Gather information for assertions
277316
docker_endpoint := GetDockerEndpoint(name, name)
@@ -304,7 +343,7 @@ var _ = Describe("Libnetwork Tests", func() {
304343

305344
It("creates a container on a network and checks all assertions", func() {
306345
// Create a container that will just sit in the background
307-
DockerString(fmt.Sprintf("docker run --net %s -tid --name %s busybox", name, name))
346+
DockerString(fmt.Sprintf("docker run --net %s -tid --name %s %s", name, name, os.Getenv("BUSYBOX_IMAGE") ))
308347

309348
// Gather information for assertions
310349
docker_endpoint := GetDockerEndpoint(name, name)

0 commit comments

Comments
 (0)