Use containerd API to get version
The `docker info` code was shelling out to obtain the version of containerd (using the `--version` flag). Parsing the output of this version string is error-prone, and not needed, as the containerd API can return the version. This patch adds a `Version()` method to the containerd Client interface, and uses this to get the containerd version. Signed-off-by: Sebastiaan van Stijn <github@gone.nl> (cherry picked from commit fec2b144feaaa18998ec2ed34c9bc843c4c29abd) Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
package daemon
|
||||
|
||||
import (
|
||||
"context"
|
||||
"os/exec"
|
||||
"strings"
|
||||
|
||||
@@ -48,20 +49,10 @@ func (daemon *Daemon) FillPlatformInfo(v *types.Info, sysInfo *sysinfo.SysInfo)
|
||||
}
|
||||
|
||||
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"
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user