Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

backend/extension: Introduce new extension backend #701

Merged
merged 1 commit into from
May 17, 2017

Conversation

tomdee
Copy link
Contributor

@tomdee tomdee commented May 2, 2017

The extension backend provides an easy way for prototyping new backend types for flannel.

It is not recommended for production use, for example it doesn't have a built in retry mechanism.

This backend has the following configuration

  • Type (string): extension
  • PreStartupCommand (string): Command to run before allocating a network to this host
    • The stdout of the process is captured and passed to the stdin of the SubnetAdd/Remove commands.
  • PostStartupCommand (string): Command to run before allocating a network to this host
    • The following environment variable is set
      * SUBNET - The subnet on the remote host that was added.
  • SubnetAddCommand (string): Command to run when a subnet is added
    • stdin - The output from PreStartupCommand is passed in.
    • The following environment variables are set
      • SUBNET - The subnet on the remote host that was added.
      • PUBLIC_IP - The public IP of the remote host.
  • SubnetRemoveCommand(string): Command to run when a subnet is removed
    • stdin - The output from PreStartupCommand is passed in.
      • The following environment variables are set
        • SUBNET - The subnet on the remote host that was removed.
        • PUBLIC_IP - The public IP of the remote host.

All commands are run through the sh shell and are run with the same permissions as the flannel daemon.

Simple example (host-gw)

To replicate the functionality of the host-gw plugin, there's no need for a startup command.

The backend just needs to manage the route to subnets when they are added or removed.

An example

{
  "Network": "10.0.0.0/16",
  "Backend": {
    "Type": "extension",
    "SubnetAddCommand": "ip route add $SUBNET via $PUBLIC_IP",
    "SubnetRemoveCommand": "ip route del $SUBNET via $PUBLIC_IP"
  }
}

Complex example (vxlan)

VXLAN is more complex. It needs to store the MAC address of the vxlan device when it's created and to make it available to the flannel daemon running on other hosts.
The address of the vxlan device also needs to be set after the subnet has been allocated.

An example

{
  "Network": "10.50.0.0/16",
  "Backend": {
    "Type": "extension",
    "PreStartupCommand": "export VNI=1; export IF_NAME=flannel-vxlan; ip link del $IF_NAME 2>/dev/null; ip link add $IF_NAME type vxlan id $VNI dstport 8472 && cat /sys/class/net/$IF_NAME/address",
    "PostStartupCommand": "export IF_NAME=flannel-vxlan; export SUBNET_IP=`echo $SUBNET | cut -d'/' -f 1`; ip addr add $SUBNET_IP/32 dev $IF_NAME && ip link set $IF_NAME up",
    "SubnetAddCommand": "export SUBNET_IP=`echo $SUBNET | cut -d'/' -f 1`; export IF_NAME=flannel-vxlan; read VTEP; ip route add $SUBNET nexthop via $SUBNET_IP dev $IF_NAME onlink && arp -s $SUBNET_IP $VTEP dev $IF_NAME && bridge fdb add $VTEP dev $IF_NAME self dst $PUBLIC_IP"
  }
}

@philips
Copy link
Contributor

philips commented May 16, 2017

Pretty neat. Cool :)

Copy link
Contributor

@gunjan5 gunjan5 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a few changes

* `Type` (string): `extension`
* `PreStartupCommand` (string): Command to run before allocating a network to this host
* The stdout of the process is captured and passed to the stdin of the SubnetAdd/Remove commands.
* `PostStartupCommand` (string): Command to run before allocating a network to this host
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

before -> after

* `SubnetAddCommand` (string): Command to run when a subnet is added
* stdin - The output from `PreStartupCommand` is passed in.
* The following environment variables are set
* SUBNET - The subnet on the remote host that was added.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do you mean subnet of instead of subnet on?

* `SubnetRemoveCommand`(string): Command to run when a subnet is removed
* stdin - The output from `PreStartupCommand` is passed in.
* The following environment variables are set
* SUBNET - The subnet on the remote host that was removed.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

on -> of?

@@ -0,0 +1,150 @@
// Copyright 2015 flannel authors
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't the license headers be 2017?

log.Infof("Ran command: %s\n Output: %s", n.postStartupCommand, cmd_output)
}
} else {
log.Infof("No pre startup command configured - skipping")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should be post startup, not pre

Copy link
Contributor

@gunjan5 gunjan5 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@tomdee tomdee merged commit bcf3ff4 into flannel-io:master May 17, 2017
@tomdee tomdee deleted the alloc-extension branch May 17, 2017 18:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants