Merge pull request #35389 from thaJeztah/improve-containerd-version-parsing

Use containerd API to get version
diff --git a/daemon/info_unix.go b/daemon/info_unix.go
index fd2bbb4..9433434 100644
--- a/daemon/info_unix.go
+++ b/daemon/info_unix.go
@@ -3,6 +3,7 @@
 package daemon
 
 import (
+	"context"
 	"os/exec"
 	"strings"
 
@@ -48,20 +49,10 @@
 	}
 
 	v.ContainerdCommit.Expected = dockerversion.ContainerdCommitID
-	if rv, err := exec.Command("docker-containerd", "--version").Output(); err == nil {
-		parts := strings.Split(strings.TrimSpace(string(rv)), " ")
-		if len(parts) == 3 {
-			v.ContainerdCommit.ID = parts[2]
-		}
-		switch {
-		case v.ContainerdCommit.ID == "":
-			logrus.Warnf("failed to retrieve docker-containerd version: unknown format", string(rv))
-			v.ContainerdCommit.ID = "N/A"
-		case strings.HasSuffix(v.ContainerdCommit.ID, "-g"+v.ContainerdCommit.ID[len(v.ContainerdCommit.ID)-7:]):
-			v.ContainerdCommit.ID = v.ContainerdCommit.Expected
-		}
+	if rv, err := daemon.containerd.Version(context.Background()); err == nil {
+		v.ContainerdCommit.ID = rv.Revision
 	} else {
-		logrus.Warnf("failed to retrieve docker-containerd version: %v", err)
+		logrus.Warnf("failed to retrieve containerd version: %v", err)
 		v.ContainerdCommit.ID = "N/A"
 	}
 
diff --git a/libcontainerd/client_daemon.go b/libcontainerd/client_daemon.go
index e651437..b0cdcfc 100644
--- a/libcontainerd/client_daemon.go
+++ b/libcontainerd/client_daemon.go
@@ -60,6 +60,10 @@
 	containers map[string]*container
 }
 
+func (c *client) Version(ctx context.Context) (containerd.Version, error) {
+	return c.remote.Version(ctx)
+}
+
 func (c *client) Restore(ctx context.Context, id string, attachStdio StdioCallback) (alive bool, pid int, err error) {
 	c.Lock()
 	defer c.Unlock()
diff --git a/libcontainerd/client_local_windows.go b/libcontainerd/client_local_windows.go
index c33e346..8ce9dfe 100644
--- a/libcontainerd/client_local_windows.go
+++ b/libcontainerd/client_local_windows.go
@@ -17,6 +17,7 @@
 
 	"github.com/Microsoft/hcsshim"
 	opengcs "github.com/Microsoft/opengcs/client"
+	"github.com/containerd/containerd"
 	"github.com/docker/docker/pkg/sysinfo"
 	"github.com/docker/docker/pkg/system"
 	specs "github.com/opencontainers/runtime-spec/specs-go"
@@ -70,6 +71,10 @@
 // of docker.
 const defaultOwner = "docker"
 
+func (c *client) Version(ctx context.Context) (containerd.Version, error) {
+	return containerd.Version{}, errors.New("not implemented on Windows")
+}
+
 // Create is the entrypoint to create a container from a spec.
 // Table below shows the fields required for HCS JSON calling parameters,
 // where if not populated, is omitted.
diff --git a/libcontainerd/types.go b/libcontainerd/types.go
index 9e05c16..9eede43 100644
--- a/libcontainerd/types.go
+++ b/libcontainerd/types.go
@@ -82,6 +82,8 @@
 
 // Client provides access to containerd features.
 type Client interface {
+	Version(ctx context.Context) (containerd.Version, error)
+
 	Restore(ctx context.Context, containerID string, attachStdio StdioCallback) (alive bool, pid int, err error)
 
 	Create(ctx context.Context, containerID string, spec *specs.Spec, runtimeOptions interface{}) error