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>
This commit is contained in:
parent
4bc5a57652
commit
fec2b144fe
4 changed files with 15 additions and 13 deletions
|
@ -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"
|
||||
}
|
||||
|
||||
|
|
|
@ -60,6 +60,10 @@ type client struct {
|
|||
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()
|
||||
|
|
|
@ -17,6 +17,7 @@ import (
|
|||
|
||||
"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 @@ const (
|
|||
// 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.
|
||||
|
|
|
@ -82,6 +82,8 @@ type Backend interface {
|
|||
|
||||
// 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
|
||||
|
|
Loading…
Reference in a new issue