@@ -11,6 +11,7 @@ import (
1111
1212 "github.com/containerd/containerd"
1313 "github.com/containerd/containerd/defaults"
14+ "github.com/containerd/containerd/pkg/dialer"
1415 "github.com/containerd/containerd/services/server/config"
1516 "github.com/containerd/log"
1617 "github.com/docker/docker/pkg/pidfile"
@@ -29,7 +30,6 @@ const (
2930 shutdownTimeout = 15 * time .Second
3031 startupTimeout = 15 * time .Second
3132 configFile = "containerd.toml"
32- binaryName = "containerd"
3333 pidFile = "containerd.pid"
3434)
3535
@@ -40,9 +40,13 @@ type remote struct {
4040 // file is saved.
4141 configFile string
4242
43- daemonPid int
44- pidFile string
45- logger * log.Entry
43+ // daemonPath is the binary to execute, and can be either a basename (to use
44+ // a binary installed in the system's $PATH), or the full path to the binary
45+ // to use.
46+ daemonPath string
47+ daemonPid int
48+ pidFile string
49+ logger * log.Entry
4650
4751 daemonWaitCh chan struct {}
4852 daemonStartCh chan error
@@ -75,6 +79,7 @@ func Start(ctx context.Context, rootDir, stateDir string, opts ...DaemonOpt) (Da
7579 },
7680 },
7781 configFile : filepath .Join (stateDir , configFile ),
82+ daemonPath : binaryName ,
7883 daemonPid : - 1 ,
7984 pidFile : filepath .Join (stateDir , pidFile ),
8085 logger : log .G (ctx ).WithField ("module" , "libcontainerd" ),
@@ -156,7 +161,8 @@ func (r *remote) startContainerd() error {
156161 return err
157162 }
158163
159- cmd := exec .Command (binaryName , "--config" , cfgFile )
164+ r .logger .WithField ("binary" , r .daemonPath ).Debug ("starting containerd binary" )
165+ cmd := exec .Command (r .daemonPath , "--config" , cfgFile )
160166 // redirect containerd logs to docker logs
161167 cmd .Stdout = os .Stdout
162168 cmd .Stderr = os .Stderr
@@ -262,7 +268,9 @@ func (r *remote) monitorDaemon(ctx context.Context) {
262268 }
263269 }
264270
265- os .RemoveAll (r .GRPC .Address )
271+ if err := os .RemoveAll (r .GRPC .Address ); err != nil {
272+ r .logger .WithError (err ).Error ("failed to remove old gRPC address" )
273+ }
266274 if err := r .startContainerd (); err != nil {
267275 if ! started {
268276 r .daemonStartCh <- err
@@ -273,16 +281,19 @@ func (r *remote) monitorDaemon(ctx context.Context) {
273281 continue
274282 }
275283
284+ gopts := []grpc.DialOption {
285+ grpc .WithTransportCredentials (insecure .NewCredentials ()),
286+ grpc .WithContextDialer (dialer .ContextDialer ),
287+ grpc .WithDefaultCallOptions (grpc .MaxCallRecvMsgSize (defaults .DefaultMaxRecvMsgSize )),
288+ grpc .WithDefaultCallOptions (grpc .MaxCallSendMsgSize (defaults .DefaultMaxSendMsgSize )),
289+ grpc .WithUnaryInterceptor (grpcerrors .UnaryClientInterceptor ),
290+ grpc .WithStreamInterceptor (grpcerrors .StreamClientInterceptor ),
291+ }
292+
276293 client , err = containerd .New (
277294 r .GRPC .Address ,
278295 containerd .WithTimeout (60 * time .Second ),
279- containerd .WithDialOpts ([]grpc.DialOption {
280- grpc .WithUnaryInterceptor (grpcerrors .UnaryClientInterceptor ),
281- grpc .WithStreamInterceptor (grpcerrors .StreamClientInterceptor ),
282- grpc .WithTransportCredentials (insecure .NewCredentials ()),
283- grpc .WithDefaultCallOptions (grpc .MaxCallRecvMsgSize (defaults .DefaultMaxRecvMsgSize )),
284- grpc .WithDefaultCallOptions (grpc .MaxCallSendMsgSize (defaults .DefaultMaxSendMsgSize )),
285- }),
296+ containerd .WithDialOpts (gopts ),
286297 )
287298 if err != nil {
288299 r .logger .WithError (err ).Error ("failed connecting to containerd" )
0 commit comments