Skip to content

Commit

Permalink
Merge pull request #517 from l1b0k/feat/cni
Browse files Browse the repository at this point in the history
cni: add a 10s timeout when connect to terway daemon
  • Loading branch information
BSWANG authored Aug 9, 2023
2 parents 9010489 + c742f76 commit 2137f5b
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions plugin/terway/cni.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"runtime"
"time"

"google.golang.org/grpc/backoff"
"google.golang.org/grpc/credentials/insecure"

"github.com/AliyunContainerService/terway/pkg/link"
Expand All @@ -27,6 +28,7 @@ import (
const (
defaultSocketPath = "/var/run/eni/eni.socket"
defaultVethPrefix = "cali"
defaultDialTimeout = 10 * time.Second
defaultCniTimeout = 120 * time.Second
defaultEventTimeout = 10 * time.Second
delegateIpam = "host-local"
Expand Down Expand Up @@ -213,15 +215,26 @@ func cmdCheck(args *skel.CmdArgs) error {
}

func getNetworkClient(ctx context.Context) (rpc.TerwayBackendClient, *grpc.ClientConn, error) {
ctx, parent := context.WithTimeout(ctx, defaultDialTimeout)
defer parent()
conn, err := grpc.DialContext(ctx, defaultSocketPath, grpc.WithTransportCredentials(insecure.NewCredentials()), grpc.WithContextDialer(
func(ctx context.Context, s string) (net.Conn, error) {
unixAddr, err := net.ResolveUnixAddr("unix", defaultSocketPath)
unixAddr, err := net.ResolveUnixAddr("unix", s)
if err != nil {
return nil, err
}
d := net.Dialer{}
return d.DialContext(ctx, "unix", unixAddr.String())
}))
}),
grpc.WithBlock(),
grpc.WithConnectParams(grpc.ConnectParams{
Backoff: backoff.Config{
BaseDelay: time.Second,
Multiplier: 1,
MaxDelay: time.Second,
},
}),
)

if err != nil {
return nil, nil, cniTypes.NewError(cniTypes.ErrTryAgainLater, "failed connect to daemon", err.Error())
Expand Down

0 comments on commit 2137f5b

Please sign in to comment.