From 7eac54ccb9a6e04ba1dcc31d603bff26464495af Mon Sep 17 00:00:00 2001 From: Kohei Tokunaga Date: Tue, 19 Jul 2022 10:50:20 +0900 Subject: [PATCH] containerd worker: Add fallback when buildkitd cannot access to containerd Signed-off-by: Kohei Tokunaga --- cmd/buildkitd/main_containerd_worker.go | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/cmd/buildkitd/main_containerd_worker.go b/cmd/buildkitd/main_containerd_worker.go index 00079676b1bb..fe917422e86f 100644 --- a/cmd/buildkitd/main_containerd_worker.go +++ b/cmd/buildkitd/main_containerd_worker.go @@ -228,7 +228,7 @@ func containerdWorkerInitializer(c *cli.Context, common workerInitializerOpt) ([ cfg := common.config.Workers.Containerd - if (cfg.Enabled == nil && !validContainerdSocket(cfg.Address)) || (cfg.Enabled != nil && !*cfg.Enabled) { + if (cfg.Enabled == nil && !validContainerdSocket(cfg)) || (cfg.Enabled != nil && !*cfg.Enabled) { return nil, nil } @@ -280,7 +280,8 @@ func containerdWorkerInitializer(c *cli.Context, common workerInitializerOpt) ([ return []worker.Worker{w}, nil } -func validContainerdSocket(socket string) bool { +func validContainerdSocket(cfg config.ContainerdConfig) bool { + socket := cfg.Address if strings.HasPrefix(socket, "tcp://") { // FIXME(AkihiroSuda): prohibit tcp? return true @@ -291,6 +292,14 @@ func validContainerdSocket(socket string) bool { logrus.Warnf("skipping containerd worker, as %q does not exist", socketPath) return false } - // TODO: actually dial and call introspection API + c, err := ctd.New(socketPath, ctd.WithDefaultNamespace(cfg.Namespace)) + if err != nil { + logrus.Warnf("skipping containerd worker, as failed to connect client to %q: %v", socketPath, err) + return false + } + if _, err := c.Server(context.Background()); err != nil { + logrus.Warnf("skipping containerd worker, as failed to call introspection API on %q: %v", socketPath, err) + return false + } return true }