Skip to content
This repository has been archived by the owner on Jul 1, 2023. It is now read-only.

Commit

Permalink
Update fork with upstream fixes/changes (#11)
Browse files Browse the repository at this point in the history
* vxlan: Generate MAC address before creating a link

systemd 242+ assigns MAC addresses for all virtual devices which don't
have the address assigned already. That resulted in systemd overriding
MAC addresses of flannel.* interfaces. The fix which prevents systemd
from setting the address is to define the concrete MAC address when
creating the link.

Fixes: flannel-io#1155
Ref: k3s-io/k3s#4188
Signed-off-by: Michal Rostecki <mrostecki@opensuse.org>
(cherry picked from commit 0198d5d)

* Concern only about flannel ip addresses

Currently flannel interface ip addresses are checked on startup when
using vxlan and ipip backends. If multiple addresses are found, startup
fails fatally. If only one address is found and is not the currently
leased one, it will be assumed that it comes from a previous lease and
be removed.

This criteria seems arbitrary both in how it is done and in its timing.
It may cause failures in situations where it might not be strictly
necessary like for example if the node is running a dhcp client that is
assigning link local addresses to all interfaces. It also might fail at
flannel unexpected restarts which are completly unrelated to
the external event that caused the unexpected modification in the
flannel interface.

This patch proposes to concern and check only ip address within the
flannel network and takes the simple approach to ignore any other ip
addresses assuming these would pose no problem on flannel operation.

A discarded but more agressive alternative would be to remove all
addresses that are not the currently leased one.

Fixes flannel-io#1060

Signed-off-by: Jaime Caamaño Ruiz <jcaamano@suse.com>
(cherry picked from commit 33a2fac)

* Fix flannel hang if lease expired

(cherry picked from commit 78035d0)

* subnets: move forward the cursor to skip illegal subnet

This PR fixs an issue when flannel gets illegal subnet event in
watching leases, it doesn't move forward the etcd cursor and
will stuck in the same invalid event forever.

(cherry picked from commit 1a1b6f1)

* fix cherry-pick glitches and test failures

* disable udp backend tests since we don't actually have the udp backend in our fork

Co-authored-by: Michal Rostecki <mrostecki@opensuse.org>
Co-authored-by: Jaime Caamaño Ruiz <jcaamano@suse.com>
Co-authored-by: Chun Chen <ramichen@tencent.com>
Co-authored-by: huangxuesen <hxs625job@outlook.com>
  • Loading branch information
5 people committed Jan 25, 2022
1 parent c570cc6 commit 8b92dc7
Show file tree
Hide file tree
Showing 36 changed files with 199 additions and 83 deletions.
1 change: 1 addition & 0 deletions backend/alivpc/alivpc.go
Expand Up @@ -11,6 +11,7 @@
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//go:build !windows
// +build !windows

package alivpc
Expand Down
1 change: 1 addition & 0 deletions backend/awsvpc/awsvpc.go
Expand Up @@ -11,6 +11,7 @@
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//go:build !windows
// +build !windows

package awsvpc
Expand Down
1 change: 1 addition & 0 deletions backend/awsvpc/filter.go
Expand Up @@ -11,6 +11,7 @@
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//go:build !windows
// +build !windows

package awsvpc
Expand Down
9 changes: 5 additions & 4 deletions backend/extension/extension_network.go
Expand Up @@ -61,11 +61,12 @@ func (n *network) Run(ctx context.Context) {

for {
select {
case evtBatch := <-evts:
case evtBatch, ok := <-evts:
if !ok {
log.Infof("evts chan closed")
return
}
n.handleSubnetEvents(evtBatch)

case <-ctx.Done():
return
}
}
}
Expand Down
1 change: 1 addition & 0 deletions backend/gce/api.go
Expand Up @@ -13,6 +13,7 @@
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//go:build !windows
// +build !windows

package gce
Expand Down
1 change: 1 addition & 0 deletions backend/gce/gce.go
Expand Up @@ -36,6 +36,7 @@
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
//go:build !windows
// +build !windows

package gce
Expand Down
1 change: 1 addition & 0 deletions backend/gce/metadata.go
Expand Up @@ -13,6 +13,7 @@
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//go:build !windows
// +build !windows

package gce
Expand Down
4 changes: 2 additions & 2 deletions backend/hostgw/hostgw.go
@@ -1,4 +1,5 @@
// +build !windows
//go:build !windows && !windows
// +build !windows,!windows

// Copyright 2015 flannel authors
//
Expand All @@ -13,7 +14,6 @@
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// +build !windows

package hostgw

Expand Down
4 changes: 2 additions & 2 deletions backend/hostgw/hostgw_windows.go
@@ -1,4 +1,5 @@
// +build windows
//go:build windows && windows
// +build windows,windows

// Copyright 2015 flannel authors
//
Expand All @@ -13,7 +14,6 @@
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// +build windows

package hostgw

Expand Down
7 changes: 4 additions & 3 deletions backend/ipip/ipip.go
@@ -1,3 +1,4 @@
//go:build !windows
// +build !windows

// Copyright 2017 flannel authors
Expand Down Expand Up @@ -89,7 +90,7 @@ func (be *IPIPBackend) RegisterNetwork(ctx context.Context, wg *sync.WaitGroup,
return nil, fmt.Errorf("failed to acquire lease: %v", err)
}

link, err := be.configureIPIPDevice(n.SubnetLease)
link, err := be.configureIPIPDevice(n.SubnetLease, config.Network)

if err != nil {
return nil, err
Expand Down Expand Up @@ -124,7 +125,7 @@ func (be *IPIPBackend) RegisterNetwork(ctx context.Context, wg *sync.WaitGroup,
return n, nil
}

func (be *IPIPBackend) configureIPIPDevice(lease *subnet.Lease) (*netlink.Iptun, error) {
func (be *IPIPBackend) configureIPIPDevice(lease *subnet.Lease, flannelnet ip.IP4Net) (*netlink.Iptun, error) {
// When modprobe ipip module, a tunl0 ipip device is created automatically per network namespace by ipip kernel module.
// It is the namespace default IPIP device with attributes local=any and remote=any.
// When receiving IPIP protocol packets, kernel will forward them to tunl0 as a fallback device
Expand Down Expand Up @@ -196,7 +197,7 @@ func (be *IPIPBackend) configureIPIPDevice(lease *subnet.Lease) (*netlink.Iptun,
// Ensure that the device has a /32 address so that no broadcast routes are created.
// This IP is just used as a source address for host to workload traffic (so
// the return path for the traffic has an address on the flannel network to use as the destination)
if err := ip.EnsureV4AddressOnLink(ip.IP4Net{IP: lease.Subnet.IP, PrefixLen: 32}, link); err != nil {
if err := ip.EnsureV4AddressOnLink(ip.IP4Net{IP: lease.Subnet.IP, PrefixLen: 32}, flannelnet, link); err != nil {
return nil, fmt.Errorf("failed to ensure address of interface %s: %s", link.Attrs().Name, err)
}

Expand Down
1 change: 1 addition & 0 deletions backend/ipip/ipip_windows.go
Expand Up @@ -11,6 +11,7 @@
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//go:build windows
// +build windows

package ipip
Expand Down
1 change: 1 addition & 0 deletions backend/ipsec/handle_charon.go
Expand Up @@ -11,6 +11,7 @@
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//go:build !windows
// +build !windows

package ipsec
Expand Down
1 change: 1 addition & 0 deletions backend/ipsec/handle_xfrm.go
Expand Up @@ -11,6 +11,7 @@
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//go:build !windows
// +build !windows

package ipsec
Expand Down
1 change: 1 addition & 0 deletions backend/ipsec/ipsec.go
Expand Up @@ -11,6 +11,7 @@
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//go:build !windows
// +build !windows

package ipsec
Expand Down
10 changes: 6 additions & 4 deletions backend/ipsec/ipsec_network.go
Expand Up @@ -11,6 +11,7 @@
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//go:build !windows
// +build !windows

package ipsec
Expand Down Expand Up @@ -95,12 +96,13 @@ func (n *network) Run(ctx context.Context) {

for {
select {
case evtsBatch := <-evts:
case evtsBatch, ok := <-evts:
if !ok {
log.Infof("evts chan closed")
return
}
log.Info("Handling event")
n.handleSubnetEvents(evtsBatch)
case <-ctx.Done():
log.Info("Received DONE")
return
}
}
}
Expand Down
10 changes: 6 additions & 4 deletions backend/route_network.go
@@ -1,3 +1,4 @@
//go:build !windows
// +build !windows

// Copyright 2017 flannel authors
Expand Down Expand Up @@ -69,11 +70,12 @@ func (n *RouteNetwork) Run(ctx context.Context) {

for {
select {
case evtBatch := <-evts:
case evtBatch, ok := <-evts:
if !ok {
log.Infof("evts chan closed")
return
}
n.handleSubnetEvents(evtBatch)

case <-ctx.Done():
return
}
}
}
Expand Down
1 change: 1 addition & 0 deletions backend/route_network_test.go
Expand Up @@ -11,6 +11,7 @@
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//go:build !windows
// +build !windows

package backend
Expand Down
22 changes: 14 additions & 8 deletions backend/vxlan/device.go
@@ -1,3 +1,4 @@
//go:build !windows
// +build !windows

// Copyright 2015 flannel authors
Expand All @@ -13,7 +14,6 @@
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// +build !windows

package vxlan

Expand All @@ -22,11 +22,11 @@ import (
"net"
"syscall"

log "github.com/golang/glog"
"github.com/vishvananda/netlink"

"github.com/containernetworking/plugins/pkg/utils/sysctl"
"github.com/coreos/flannel/pkg/ip"
"github.com/coreos/flannel/pkg/mac"
log "github.com/golang/glog"
"github.com/vishvananda/netlink"
)

type vxlanDeviceAttrs struct {
Expand All @@ -44,9 +44,15 @@ type vxlanDevice struct {
}

func newVXLANDevice(devAttrs *vxlanDeviceAttrs) (*vxlanDevice, error) {
hardwareAddr, err := mac.NewHardwareAddr()
if err != nil {
return nil, err
}

link := &netlink.Vxlan{
LinkAttrs: netlink.LinkAttrs{
Name: devAttrs.name,
Name: devAttrs.name,
HardwareAddr: hardwareAddr,
},
VxlanId: int(devAttrs.vni),
VtepDevIndex: devAttrs.vtepIndex,
Expand All @@ -56,7 +62,7 @@ func newVXLANDevice(devAttrs *vxlanDeviceAttrs) (*vxlanDevice, error) {
GBP: devAttrs.gbp,
}

link, err := ensureLink(link)
link, err = ensureLink(link)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -112,8 +118,8 @@ func ensureLink(vxlan *netlink.Vxlan) (*netlink.Vxlan, error) {
return vxlan, nil
}

func (dev *vxlanDevice) Configure(ipn ip.IP4Net) error {
if err := ip.EnsureV4AddressOnLink(ipn, dev.link); err != nil {
func (dev *vxlanDevice) Configure(ipa ip.IP4Net, flannelnet ip.IP4Net) error {
if err := ip.EnsureV4AddressOnLink(ipa, flannelnet, dev.link); err != nil {
return fmt.Errorf("failed to ensure address of interface %s: %s", dev.link.Attrs().Name, err)
}

Expand Down
3 changes: 2 additions & 1 deletion backend/vxlan/vxlan.go
Expand Up @@ -11,6 +11,7 @@
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//go:build !windows
// +build !windows

package vxlan
Expand Down Expand Up @@ -152,7 +153,7 @@ func (be *VXLANBackend) RegisterNetwork(ctx context.Context, wg *sync.WaitGroup,
// Ensure that the device has a /32 address so that no broadcast routes are created.
// This IP is just used as a source address for host to workload traffic (so
// the return path for the traffic has an address on the flannel network to use as the destination)
if err := dev.Configure(ip.IP4Net{IP: lease.Subnet.IP, PrefixLen: 32}); err != nil {
if err := dev.Configure(ip.IP4Net{IP: lease.Subnet.IP, PrefixLen: 32}, config.Network); err != nil {
return nil, fmt.Errorf("failed to configure interface %s: %s", dev.link.Attrs().Name, err)
}

Expand Down
10 changes: 6 additions & 4 deletions backend/vxlan/vxlan_network.go
Expand Up @@ -11,6 +11,7 @@
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//go:build !windows
// +build !windows

package vxlan
Expand Down Expand Up @@ -70,11 +71,12 @@ func (nw *network) Run(ctx context.Context) {

for {
select {
case evtBatch := <-events:
case evtBatch, ok := <-events:
if !ok {
log.Infof("evts chan closed")
return
}
nw.handleSubnetEvents(evtBatch)

case <-ctx.Done():
return
}
}
}
Expand Down
1 change: 1 addition & 0 deletions backend/vxlan/vxlan_windows.go
Expand Up @@ -11,6 +11,7 @@
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//go:build windows
// +build windows

package vxlan
Expand Down
14 changes: 7 additions & 7 deletions dist/functional-test-k8s.sh
Expand Up @@ -107,13 +107,13 @@ test_vxlan() {
pings
}

if [[ ${ARCH} == "amd64" ]]; then
test_udp() {
start_flannel udp
create_ping_dest # creates ping_dest1 and ping_dest2 variables
pings
}
fi
#if [[ ${ARCH} == "amd64" ]]; then
#test_udp() {
# start_flannel udp
# create_ping_dest # creates ping_dest1 and ping_dest2 variables
# pings
#}
#fi

test_host-gw() {
start_flannel host-gw
Expand Down
28 changes: 14 additions & 14 deletions dist/functional-test.sh
Expand Up @@ -90,13 +90,13 @@ test_vxlan_ping() {
pings
}

if [[ ${ARCH} == "amd64" ]]; then
test_udp_ping() {
write_config_etcd udp
create_ping_dest # creates ping_dest1 and ping_dest2 variables
pings
}
fi
#if [[ ${ARCH} == "amd64" ]]; then
#test_udp_ping() {
# write_config_etcd udp
# create_ping_dest # creates ping_dest1 and ping_dest2 variables
# pings
#}
#fi

test_hostgw_ping() {
write_config_etcd host-gw
Expand Down Expand Up @@ -135,13 +135,13 @@ test_vxlan_perf() {
perf
}

if [[ ${ARCH} == "amd64" ]]; then
test_udp_perf() {
write_config_etcd udp
create_ping_dest
perf
}
fi
#if [[ ${ARCH} == "amd64" ]]; then
#test_udp_perf() {
# write_config_etcd udp
# create_ping_dest
# perf
#}
#fi

test_ipip_perf() {
write_config_etcd ipip
Expand Down

0 comments on commit 8b92dc7

Please sign in to comment.