Skip to content

Commit

Permalink
coordinator: Detect gateway in pod's netns without in hostNs
Browse files Browse the repository at this point in the history
  • Loading branch information
cyclinder committed Dec 7, 2023
1 parent 0cc27a6 commit 7defbbf
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions cmd/coordinator/cmd/command_add.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@ package cmd
import (
"context"
"fmt"
"time"

"github.com/containernetworking/cni/pkg/skel"
"github.com/containernetworking/cni/pkg/types"
current "github.com/containernetworking/cni/pkg/types/100"
"github.com/containernetworking/plugins/pkg/ns"
"github.com/vishvananda/netlink"
"go.uber.org/zap"
"golang.org/x/sync/errgroup"
"time"

"github.com/spidernet-io/spiderpool/api/v1/agent/client/daemonset"
"github.com/spidernet-io/spiderpool/api/v1/agent/models"
Expand Down Expand Up @@ -162,21 +163,20 @@ func CmdAdd(args *skel.CmdArgs) (err error) {
logger.Error("failed to GetDefaultGatewayByName", zap.Error(err))
return fmt.Errorf("failed to GetDefaultGatewayByName: %v", err)
}

logger.Debug("Get GetDefaultGatewayByName", zap.Strings("Gws", gws))
for _, gw := range gws {
p, err := gwconnection.NewPinger(conf.DetectOptions.Retry, conf.DetectOptions.Interval, conf.DetectOptions.TimeOut, gw, logger)
if err != nil {
return fmt.Errorf("failed to run NewPinger: %v", err)
}
errg.Go(p.DetectGateway)
}
return nil
})
if err != nil {
return err
}

logger.Debug("Get GetDefaultGatewayByName", zap.Strings("Gws", gws))

for _, gw := range gws {
p, err := gwconnection.NewPinger(conf.DetectOptions.Retry, conf.DetectOptions.Interval, conf.DetectOptions.TimeOut, gw, logger)
if err != nil {
return fmt.Errorf("failed to run NewPinger: %v", err)
}
errg.Go(p.DetectGateway)
}
} else {
logger.Debug("disable detect gateway")
}
Expand All @@ -194,7 +194,7 @@ func CmdAdd(args *skel.CmdArgs) (err error) {

if err = errg.Wait(); err != nil {
logger.Error("failed to ip checking", zap.Error(err))
return fmt.Errorf("failed to ip checking: %w", err)
return err
}

// overwrite mac address
Expand Down

0 comments on commit 7defbbf

Please sign in to comment.