Skip to content

Commit

Permalink
No need to wait down signal after setting no master
Browse files Browse the repository at this point in the history
The network interface will not be down after setting no master from
bridge in the new harvester-os.
  • Loading branch information
yaocw2020 authored and guangbochen committed Nov 25, 2021
1 parent c2e9b61 commit 6debe78
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 38 deletions.
2 changes: 1 addition & 1 deletion pkg/controller/agent/nodenetwork/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ func (h Handler) getNetworkInterfaces() ([]networkv1.NetworkInterface, error) {
if err == nil {
vlanNiIndex = v.NIC().Index()
} else {
klog.Errorf("Can not get VLAN, error: %v", err)
klog.Infof("couldn't get VLAN, reason: %v", err)
}

networkInterfaces := make([]networkv1.NetworkInterface, 0)
Expand Down
37 changes: 0 additions & 37 deletions pkg/network/iface/link.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
package iface

import (
"context"
"errors"
"fmt"
"sort"
"strings"
"syscall"
"time"

"github.com/coreos/go-iptables/iptables"
"github.com/vishvananda/netlink"
Expand Down Expand Up @@ -149,14 +147,6 @@ func (l *Link) SetNoMaster() error {
return nil
}

ctx, cancel := context.WithCancel(context.TODO())
defer cancel()
var isUp bool
if l.LinkAttrs().OperState == netlink.OperUp {
isUp = true
go l.reportDown(ctx, cancel)
}

klog.Infof("%s set no master", l.Name())
masterLink, err := GetLinkByIndex(l.LinkAttrs().MasterIndex)
if err != nil {
Expand All @@ -169,36 +159,9 @@ func (l *Link) SetNoMaster() error {
return err
}

// The link will down after a while. We catch the down signal and set the link up.
if isUp {
select {
case <-ctx.Done():
return netlink.LinkSetUp(l.link)
case <-time.After(time.Minute):
klog.Infof("Waiting for link down event timeout")
}
}

return nil
}

func (l *Link) reportDown(ctx context.Context, cancel context.CancelFunc) {
linkCh := make(chan netlink.LinkUpdate)

if err := netlink.LinkSubscribe(linkCh, ctx.Done()); err != nil {
klog.Errorf("subscribe link failed, error: %s", err.Error())
return
}

for update := range linkCh {
if int(update.Index) == l.Index() && update.Link.Attrs().OperState == netlink.OperDown {
klog.Infof("%+v/n%+v", update, update.Link)
cancel()
return
}
}
}

// allow to receive DHCP packages after attaching with bridge
func (l *Link) setRules4DHCP() error {
executor := exec.New()
Expand Down

0 comments on commit 6debe78

Please sign in to comment.