Add isContainerdRunning() and getContainerdVersion().

This commit is contained in:
Shishir Mahajan 2020-05-11 12:36:21 -07:00
parent fee9df03f4
commit 883b5f0397
No known key found for this signature in database
GPG Key ID: D41782E7688DEC4A
2 changed files with 8 additions and 7 deletions

View File

@ -4,10 +4,10 @@ import (
"github.com/containerd/containerd" "github.com/containerd/containerd"
) )
func isContainerdRunning(c *containerd.Client) (bool, error) { func (d *Driver) isContainerdRunning() (bool, error) {
return true, nil return d.client.IsServing(d.ctxContainerd)
} }
func getContainerdVersion(c *containerd.Client) (string, error) { func (d *Driver) getContainerdVersion() (containerd.Version, error) {
return "1.3.3", nil return d.client.Version(d.ctxContainerd)
} }

View File

@ -259,7 +259,7 @@ func (d *Driver) buildFingerprint() *drivers.Fingerprint {
HealthDescription: drivers.DriverHealthy, HealthDescription: drivers.DriverHealthy,
} }
isRunning, err := isContainerdRunning(d.client) isRunning, err := d.isContainerdRunning()
if err != nil { if err != nil {
d.logger.Error("Error in buildFingerprint(): failed to get containerd status: %v", err) d.logger.Error("Error in buildFingerprint(): failed to get containerd status: %v", err)
fp.Health = drivers.HealthStateUndetected fp.Health = drivers.HealthStateUndetected
@ -274,13 +274,14 @@ func (d *Driver) buildFingerprint() *drivers.Fingerprint {
} }
// Get containerd version // Get containerd version
version, err := getContainerdVersion(d.client) version, err := d.getContainerdVersion()
if err != nil { if err != nil {
d.logger.Warn("Error in buildFingerprint(): failed to get containerd version: %v", err) d.logger.Warn("Error in buildFingerprint(): failed to get containerd version: %v", err)
return fp return fp
} }
fp.Attributes["driver.containerd.containerd_version"] = structs.NewStringAttribute(version) fp.Attributes["driver.containerd.containerd_version"] = structs.NewStringAttribute(version.Version)
fp.Attributes["driver.containerd.containerd_revision"] = structs.NewStringAttribute(version.Revision)
return fp return fp
} }