diff --git a/magnum/templates/swarm/fragments/network-config-service.sh b/magnum/templates/swarm/fragments/network-config-service.sh new file mode 100644 index 0000000000..74eeeec11f --- /dev/null +++ b/magnum/templates/swarm/fragments/network-config-service.sh @@ -0,0 +1,63 @@ +#!/bin/sh + +. /etc/sysconfig/heat-params + +if [ "$NETWORK_DRIVER" != "flannel" ]; then + exit 0 +fi + +FLANNELD_CONFIG=/etc/sysconfig/flanneld +FLANNEL_CONFIG_BIN=/usr/local/bin/flannel-config +FLANNEL_CONFIG_SERVICE=/etc/systemd/system/flannel-config.service +FLANNEL_JSON=/etc/sysconfig/flannel-network.json + +sed -i ' +/^FLANNEL_ETCD=/ s|=.*|="http://'"$SWARM_MASTER_IP"':2379"| +' $FLANNELD_CONFIG + +. $FLANNELD_CONFIG + +echo "creating $FLANNEL_CONFIG_BIN" +cat > $FLANNEL_CONFIG_BIN <&2 + exit 1 +fi + +if ! [ "$FLANNEL_ETCD" ] && [ "$FLANNEL_ETCD_KEY" ]; then + echo "ERROR: missing required configuration" >&2 + exit 1 +fi + +echo "creating flanneld config in etcd" +while ! curl -sf -L $FLANNEL_ETCD/v2/keys${FLANNEL_ETCD_KEY}/config \ + -X PUT --data-urlencode value@${FLANNEL_JSON}; do + echo "waiting for etcd" + sleep 1 +done +EOF + +cat > $FLANNEL_CONFIG_SERVICE <> $FLANNEL_DOCKER_BRIDGE_BIN <&2 + exit 1 +fi + +mkdir -p /run/flannel/ +cat > /run/flannel/docker <> $FLANNEL_DOCKER_BRIDGE_SERVICE <> $DOCKER_FLANNEL_CONF <> $FLANNEL_DOCKER_BRIDGE_CONF < $FLANNEL_JSON <> $FLANNEL_JSON <> $FLANNEL_JSON < + if true use the vxlan backend, otherwise use the default + udp backend + default: "false" + constraints: + - allowed_values: ["true", "false"] + resources: cloud_init_wait_handle: @@ -209,6 +233,28 @@ resources: "$USER_TOKEN": {get_param: user_token} "$MAGNUM_URL": {get_param: magnum_url} "$TLS_DISABLED": {get_param: tls_disabled} + "$NETWORK_DRIVER": {get_param: network_driver} + "$FLANNEL_NETWORK_CIDR": {get_param: flannel_network_cidr} + "$FLANNEL_NETWORK_SUBNETLEN": {get_param: flannel_network_subnetlen} + "$FLANNEL_USE_VXLAN": {get_param: flannel_use_vxlan} + + write_network_config: + type: "OS::Heat::SoftwareConfig" + properties: + group: ungrouped + config: {get_file: fragments/write-network-config.sh} + + network_config_service: + type: "OS::Heat::SoftwareConfig" + properties: + group: ungrouped + config: {get_file: fragments/network-config-service.sh} + + network_service: + type: "OS::Heat::SoftwareConfig" + properties: + group: ungrouped + config: {get_file: fragments/network-service.sh} configure_swarm: type: "OS::Heat::SoftwareConfig" @@ -334,6 +380,9 @@ resources: - config: {get_resource: remove_docker_key} - config: {get_resource: write_heat_params} - config: {get_resource: make_cert} + - config: {get_resource: write_network_config} + - config: {get_resource: network_config_service} + - config: {get_resource: network_service} - config: {get_resource: configure_docker_storage} - config: {get_resource: write_swarm_agent_failure_service} - config: {get_resource: write_swarm_manager_failure_service} @@ -415,6 +464,7 @@ resources: user_token: {get_param: user_token} magnum_url: {get_param: magnum_url} tls_disabled: {get_param: tls_disabled} + network_driver: {get_param: network_driver} ###################################################################### # diff --git a/magnum/templates/swarm/swarmnode.yaml b/magnum/templates/swarm/swarmnode.yaml index 98ad55c58d..6f195f4d36 100644 --- a/magnum/templates/swarm/swarmnode.yaml +++ b/magnum/templates/swarm/swarmnode.yaml @@ -40,6 +40,11 @@ parameters: type: string description: Subnet from which to allocate fixed addresses. + network_driver: + type: string + description: network driver to use for instantiating container networks + default: None + discovery_url: type: string description: url provided for node discovery @@ -143,6 +148,7 @@ resources: "$USER_TOKEN": {get_param: user_token} "$MAGNUM_URL": {get_param: magnum_url} "$TLS_DISABLED": {get_param: tls_disabled} + "$NETWORK_DRIVER": {get_param: network_driver} configure_swarm: type: "OS::Heat::SoftwareConfig" @@ -180,6 +186,12 @@ resources: group: ungrouped config: {get_file: fragments/write-docker-socket.yaml} + network_service: + type: "OS::Heat::SoftwareConfig" + properties: + group: ungrouped + config: {get_file: fragments/network-service.sh} + write_swarm_agent_failure_service: type: "OS::Heat::SoftwareConfig" properties: @@ -242,6 +254,7 @@ resources: - config: {get_resource: remove_docker_key} - config: {get_resource: write_heat_params} - config: {get_resource: make_cert} + - config: {get_resource: network_service} - config: {get_resource: configure_docker_storage} - config: {get_resource: write_swarm_agent_failure_service} - config: {get_resource: write_swarm_agent_service}