Skip to content

Commit

Permalink
Remove the experimental support for multiple networks.
Browse files Browse the repository at this point in the history
It is not widely used and it makes the code complicated.
  • Loading branch information
tomdee committed Apr 19, 2017
1 parent 75c840f commit 915f291
Show file tree
Hide file tree
Showing 32 changed files with 709 additions and 1,368 deletions.
2 changes: 1 addition & 1 deletion Dockerfile.amd64
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ COPY dist/flanneld-$FLANNEL_ARCH /opt/bin/flanneld
COPY dist/iptables-$FLANNEL_ARCH /usr/local/bin/iptables
COPY dist/mk-docker-opts.sh /opt/bin/

CMD ["/opt/bin/flanneld"]
ENTRYPOINT ["/opt/bin/flanneld"]

2 changes: 1 addition & 1 deletion Dockerfile.arm
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ COPY dist/ld64.so.1-$FLANNEL_ARCH /lib/ld64.so.1
COPY dist/libc.so.6-$FLANNEL_ARCH /lib/libc.so.6


CMD ["/opt/bin/flanneld"]
ENTRYPOINT ["/opt/bin/flanneld"]
2 changes: 2 additions & 0 deletions Dockerfile.arm64
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,5 @@ COPY dist/mk-docker-opts.sh /opt/bin/
COPY dist/libpthread.so.0-$FLANNEL_ARCH /lib/libpthread.so.0
COPY dist/ld64.so.1-$FLANNEL_ARCH /lib/ld64.so.1
COPY dist/libc.so.6-$FLANNEL_ARCH /lib/libc.so.6

ENTRYPOINT ["/opt/bin/flanneld"]
2 changes: 2 additions & 0 deletions Dockerfile.ppc64le
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,5 @@ COPY dist/mk-docker-opts.sh /opt/bin/
COPY dist/libpthread.so.0-$FLANNEL_ARCH /lib/libpthread.so.0
COPY dist/ld64.so.1-$FLANNEL_ARCH /lib/ld64.so.1
COPY dist/libc.so.6-$FLANNEL_ARCH /lib/libc.so.6

ENTRYPOINT ["/opt/bin/flanneld"]
2 changes: 1 addition & 1 deletion Dockerfile.s390x
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ COPY dist/libpthread.so.0-$FLANNEL_ARCH /lib/libpthread.so.0
COPY dist/ld64.so.1-$FLANNEL_ARCH /lib/ld64.so.1
COPY dist/libc.so.6-$FLANNEL_ARCH /lib/libc.so.6

CMD ["/opt/bin/flanneld"]
ENTRYPOINT ["/opt/bin/flanneld"]
91 changes: 91 additions & 0 deletions Documentation/minikube.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
# This manifest is intended for dev work, so there are some differences from the "normal" manifest
# - No namespace (make kubectl simler)
# - special image name (flannel-minikube)
# - Never pull the image
# - host-gw backend (since vxlan doesn't work in minikube)
---
apiVersion: v1
kind: ServiceAccount
metadata:
name: flannel
---
kind: ConfigMap
apiVersion: v1
metadata:
name: kube-flannel-cfg
labels:
tier: node
app: flannel
data:
cni-conf.json: |
{
"name": "cbr0",
"type": "flannel",
"delegate": {
"isDefaultGateway": true
}
}
net-conf.json: |
{
"Network": "10.33.0.0/16",
"Backend": {
"Type": "host-gw"
}
}
---
apiVersion: extensions/v1beta1
kind: DaemonSet
metadata:
name: kube-flannel-ds
labels:
tier: node
app: flannel
spec:
template:
metadata:
labels:
tier: node
app: flannel
spec:
hostNetwork: true
serviceAccountName: flannel
containers:
- name: kube-flannel
image: flannel/minikube
imagePullPolicy: Never
command: [ "/opt/bin/flanneld", "--ip-masq", "--kube-subnet-mgr" ]
securityContext:
privileged: true
env:
- name: POD_NAME
valueFrom:
fieldRef:
fieldPath: metadata.name
- name: POD_NAMESPACE
valueFrom:
fieldRef:
fieldPath: metadata.namespace
volumeMounts:
- name: run
mountPath: /run
- name: flannel-cfg
mountPath: /etc/kube-flannel/
- name: install-cni
image: flannel/minikube
imagePullPolicy: Never
command: [ "/bin/sh", "-c", "set -e -x; cat /etc/kube-flannel/cni-conf.json; cp -f /etc/kube-flannel/cni-conf.json /etc/cni/net.d/10-flannel.conf; while true; do sleep 3600; done" ]
volumeMounts:
- name: cni
mountPath: /etc/cni/net.d
- name: flannel-cfg
mountPath: /etc/kube-flannel/
volumes:
- name: run
hostPath:
path: /run
- name: cni
hostPath:
path: /etc/cni/net.d
- name: flannel-cfg
configMap:
name: kube-flannel-cfg
9 changes: 9 additions & 0 deletions Documentation/running.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,15 @@ Additionally it will monitor etcd for new members of the network and adjust the

After flannel has acquired the subnet and configured backend, it will write out an environment variable file (`/run/flannel/subnet.env` by default) with subnet address and MTU that it supports.

## Multiple networks

Flanneld does not support multiple from a single daemon (it did previously as an experimental feature).
However, it does support running multiple daemons on the same host with different configuration. The `-subnet-file` and `-etcd-prefix` options should be used to "namespace" the different daemons.
For example
```
flanneld -subnet-file /vxlan.env -etcd-prefix=/vxlan/network
```

## Zero-downtime restarts

When running with a backend other than `udp`, the kernel is providing the data path with flanneld acting as the control plane.
Expand Down
38 changes: 38 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -194,3 +194,41 @@ flannel-git:
ARCH=arm64 REGISTRY=quay.io/coreos/flannel-git make clean dist/flanneld-$(TAG)-arm64.docker docker-push
ARCH=ppc64le REGISTRY=quay.io/coreos/flannel-git make clean dist/flanneld-$(TAG)-ppc64le.docker docker-push
ARCH=s390x REGISTRY=quay.io/coreos/flannel-git make clean dist/flanneld-$(TAG)-s390x.docker docker-push

install:
# This is intended as just a developer convenience to help speed up non-containerized builds
# It is NOT how you install flannel
CGO_ENABLED=1 go install -v github.com/coreos/flannel

minikube-start:
minikube start --network-plugin cni

minikube-build-image: dist/iptables-amd64 dist/libpthread.so.0-amd64
CGO_ENABLED=1 go build -v -o dist/flanneld-amd64
# Make sure the minikube docker is being used "eval $(minikube docker-env)"
sh -c 'eval $$(minikube docker-env) && docker build -f Dockerfile.amd64 -t flannel/minikube .'

minikube-deploy-flannel:
kubectl apply -f Documentation/minikube.yml

minikube-remove-flannel:
kubectl delete -f Documentation/minikube.yml

minikube-restart-pod:
# Use this to pick up a new image
kubectl delete pods -l app=flannel --grace-period=0

kubernetes-logs:
kubectl logs `kubectl get po -l app=flannel -o=custom-columns=NAME:metadata.name --no-headers=true` -c kube-flannel -f

LOCAL_IP_ENV?=$(shell ip route get 8.8.8.8 | head -1 | awk '{print $$7}')
run-etcd: stop-etcd
docker run --detach \
-p 2379:2379 \
--name flannel-etcd quay.io/coreos/etcd \
etcd \
--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"

stop-etcd:
@-docker rm -f flannel-etcd
4 changes: 2 additions & 2 deletions backend/alivpc/alivpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func (be *AliVpcBackend) Run(ctx context.Context) {
<-ctx.Done()
}

func (be *AliVpcBackend) RegisterNetwork(ctx context.Context, network string, config *subnet.Config) (backend.Network, error) {
func (be *AliVpcBackend) RegisterNetwork(ctx context.Context, config *subnet.Config) (backend.Network, error) {
// 1. Parse our configuration
cfg := struct {
AccessKeyID string
Expand All @@ -70,7 +70,7 @@ func (be *AliVpcBackend) RegisterNetwork(ctx context.Context, network string, co
PublicIP: ip.FromIP(be.extIface.ExtAddr),
}

l, err := be.sm.AcquireLease(ctx, network, &attrs)
l, err := be.sm.AcquireLease(ctx, &attrs)
switch err {
case nil:

Expand Down
4 changes: 2 additions & 2 deletions backend/alloc/alloc.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,12 @@ func (_ *AllocBackend) Run(ctx context.Context) {
<-ctx.Done()
}

func (be *AllocBackend) RegisterNetwork(ctx context.Context, network string, config *subnet.Config) (backend.Network, error) {
func (be *AllocBackend) RegisterNetwork(ctx context.Context, config *subnet.Config) (backend.Network, error) {
attrs := subnet.LeaseAttrs{
PublicIP: ip.FromIP(be.extIface.ExtAddr),
}

l, err := be.sm.AcquireLease(ctx, network, &attrs)
l, err := be.sm.AcquireLease(ctx, &attrs)
switch err {
case nil:
return &backend.SimpleNetwork{
Expand Down
6 changes: 3 additions & 3 deletions backend/awsvpc/awsvpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func (be *AwsVpcBackend) Run(ctx context.Context) {
<-ctx.Done()
}

func (be *AwsVpcBackend) RegisterNetwork(ctx context.Context, network string, config *subnet.Config) (backend.Network, error) {
func (be *AwsVpcBackend) RegisterNetwork(ctx context.Context, config *subnet.Config) (backend.Network, error) {
// Parse our configuration
cfg := struct {
RouteTableID string
Expand All @@ -70,7 +70,7 @@ func (be *AwsVpcBackend) RegisterNetwork(ctx context.Context, network string, co
PublicIP: ip.FromIP(be.extIface.ExtAddr),
}

l, err := be.sm.AcquireLease(ctx, network, &attrs)
l, err := be.sm.AcquireLease(ctx, &attrs)
switch err {
case nil:

Expand Down Expand Up @@ -115,7 +115,7 @@ func (be *AwsVpcBackend) RegisterNetwork(ctx context.Context, network string, co
log.Infof("Found route table %s.\n", cfg.RouteTableID)
}

networkConfig, err := be.sm.GetNetworkConfig(ctx, network)
networkConfig, err := be.sm.GetNetworkConfig(ctx)
if err != nil {
log.Errorf("Error fetching network config: %v", err)
}
Expand Down
2 changes: 1 addition & 1 deletion backend/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ type Backend interface {
// Called first to start the necessary event loops and such
Run(ctx context.Context)
// Called when the backend should create or begin managing a new network
RegisterNetwork(ctx context.Context, network string, config *subnet.Config) (Network, error)
RegisterNetwork(ctx context.Context, config *subnet.Config) (Network, error)
}

type Network interface {
Expand Down
4 changes: 2 additions & 2 deletions backend/gce/gce.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,12 @@ func (g *GCEBackend) Run(ctx context.Context) {
<-ctx.Done()
}

func (g *GCEBackend) RegisterNetwork(ctx context.Context, network string, config *subnet.Config) (backend.Network, error) {
func (g *GCEBackend) RegisterNetwork(ctx context.Context, config *subnet.Config) (backend.Network, error) {
attrs := subnet.LeaseAttrs{
PublicIP: ip.FromIP(g.extIface.ExtAddr),
}

l, err := g.sm.AcquireLease(ctx, network, &attrs)
l, err := g.sm.AcquireLease(ctx, &attrs)
switch err {
case nil:

Expand Down
7 changes: 2 additions & 5 deletions backend/hostgw/hostgw.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,8 @@ func (_ *HostgwBackend) Run(ctx context.Context) {
<-ctx.Done()
}

func (be *HostgwBackend) RegisterNetwork(ctx context.Context, netname string, config *subnet.Config) (backend.Network, error) {
func (be *HostgwBackend) RegisterNetwork(ctx context.Context, config *subnet.Config) (backend.Network, error) {
n := &network{
name: netname,
extIface: be.extIface,
sm: be.sm,
}
Expand All @@ -67,7 +66,7 @@ func (be *HostgwBackend) RegisterNetwork(ctx context.Context, netname string, co
BackendType: "host-gw",
}

l, err := be.sm.AcquireLease(ctx, netname, &attrs)
l, err := be.sm.AcquireLease(ctx, &attrs)
switch err {
case nil:
n.lease = l
Expand All @@ -81,7 +80,5 @@ func (be *HostgwBackend) RegisterNetwork(ctx context.Context, netname string, co

/* NB: docker will create the local route to `sn` */

be.networks[netname] = n

return n, nil
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func (n *network) Run(ctx context.Context) {
evts := make(chan []subnet.Event)
wg.Add(1)
go func() {
subnet.WatchLeases(ctx, n.sm, n.name, n.lease, evts)
subnet.WatchLeases(ctx, n.sm, n.lease, evts)
wg.Done()
}()

Expand Down
6 changes: 3 additions & 3 deletions backend/udp/udp.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func New(sm subnet.Manager, extIface *backend.ExternalInterface) (backend.Backen
return &be, nil
}

func (be *UdpBackend) RegisterNetwork(ctx context.Context, netname string, config *subnet.Config) (backend.Network, error) {
func (be *UdpBackend) RegisterNetwork(ctx context.Context, config *subnet.Config) (backend.Network, error) {
cfg := struct {
Port int
}{
Expand All @@ -65,7 +65,7 @@ func (be *UdpBackend) RegisterNetwork(ctx context.Context, netname string, confi
PublicIP: ip.FromIP(be.extIface.ExtAddr),
}

l, err := be.sm.AcquireLease(ctx, netname, &attrs)
l, err := be.sm.AcquireLease(ctx, &attrs)
switch err {
case nil:

Expand All @@ -83,7 +83,7 @@ func (be *UdpBackend) RegisterNetwork(ctx context.Context, netname string, confi
PrefixLen: config.Network.PrefixLen,
}

return newNetwork(netname, be.sm, be.extIface, cfg.Port, tunNet, l)
return newNetwork(be.sm, be.extIface, cfg.Port, tunNet, l)
}

func (_ *UdpBackend) Run(ctx context.Context) {
Expand Down
5 changes: 2 additions & 3 deletions backend/udp/network.go → backend/udp/udp_network.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,12 @@ type network struct {
sm subnet.Manager
}

func newNetwork(name string, sm subnet.Manager, extIface *backend.ExternalInterface, port int, nw ip.IP4Net, l *subnet.Lease) (*network, error) {
func newNetwork(sm subnet.Manager, extIface *backend.ExternalInterface, port int, nw ip.IP4Net, l *subnet.Lease) (*network, error) {
n := &network{
SimpleNetwork: backend.SimpleNetwork{
SubnetLease: l,
ExtIface: extIface,
},
name: name,
port: port,
sm: sm,
}
Expand Down Expand Up @@ -101,7 +100,7 @@ func (n *network) Run(ctx context.Context) {

wg.Add(1)
go func() {
subnet.WatchLeases(ctx, n.sm, n.name, n.SubnetLease, evts)
subnet.WatchLeases(ctx, n.sm, n.SubnetLease, evts)
wg.Done()
}()

Expand Down
6 changes: 3 additions & 3 deletions backend/vxlan/vxlan.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func (be *VXLANBackend) Run(ctx context.Context) {
<-ctx.Done()
}

func (be *VXLANBackend) RegisterNetwork(ctx context.Context, network string, config *subnet.Config) (backend.Network, error) {
func (be *VXLANBackend) RegisterNetwork(ctx context.Context, config *subnet.Config) (backend.Network, error) {
// Parse our configuration
cfg := struct {
VNI int
Expand Down Expand Up @@ -100,7 +100,7 @@ func (be *VXLANBackend) RegisterNetwork(ctx context.Context, network string, con
return nil, err
}

lease, err := be.subnetMgr.AcquireLease(ctx, network, subnetAttrs)
lease, err := be.subnetMgr.AcquireLease(ctx, subnetAttrs)
switch err {
case nil:

Expand All @@ -121,7 +121,7 @@ func (be *VXLANBackend) RegisterNetwork(ctx context.Context, network string, con
return nil, err
}

return newNetwork(network, be.subnetMgr, be.extIface, dev, vxlanNet, lease)
return newNetwork(be.subnetMgr, be.extIface, dev, vxlanNet, lease)
}

// So we can make it JSON (un)marshalable
Expand Down
Loading

0 comments on commit 915f291

Please sign in to comment.