Skip to content

Commit

Permalink
Merge pull request #2968 from ktock/rootless-containerd-fix
Browse files Browse the repository at this point in the history
rootless: containerd worker: Add fallback when buildkitd cannot access to conainerd
  • Loading branch information
AkihiroSuda committed Jul 19, 2022
2 parents 874eef9 + 5fd418b commit 4b32e0b
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions cmd/buildkitd/main_containerd_worker.go
Expand Up @@ -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
}

Expand Down Expand Up @@ -281,7 +281,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
Expand All @@ -292,6 +293,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
}

0 comments on commit 4b32e0b

Please sign in to comment.