From f6184c3a9ae8474a7cb594c5bba630fabeec9d1e Mon Sep 17 00:00:00 2001 From: Shishir Mahajan Date: Fri, 8 May 2020 15:08:39 -0700 Subject: [PATCH] Add containerd client. --- containerd/containerd.go | 5 +++++ containerd/driver.go | 19 ++++++++++++++++++- 2 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 containerd/containerd.go diff --git a/containerd/containerd.go b/containerd/containerd.go new file mode 100644 index 0000000..4cbf8ef --- /dev/null +++ b/containerd/containerd.go @@ -0,0 +1,5 @@ +package containerd + +func isContainerdActive() bool { + return true +} diff --git a/containerd/driver.go b/containerd/driver.go index 36c4d86..2908e79 100644 --- a/containerd/driver.go +++ b/containerd/driver.go @@ -10,6 +10,7 @@ import ( "time" "github.com/containerd/containerd" + "github.com/containerd/containerd/namespaces" "github.com/hashicorp/consul-template/signals" "github.com/hashicorp/go-hclog" log "github.com/hashicorp/go-hclog" @@ -138,6 +139,12 @@ type Driver struct { // logger will log to the Nomad agent logger log.Logger + + // context for containerd + ctxContainerd context.Context + + // containerd client + client *containerd.Client } // NewPlugin returns a new containerd driver plugin @@ -145,18 +152,28 @@ func NewPlugin(logger log.Logger) drivers.DriverPlugin { ctx, cancel := context.WithCancel(context.Background()) logger = logger.Named(pluginName) + // This will create a new containerd client which will talk to + // default containerd socket path. client, err := containerd.New("/run/containerd/containerd.sock") if err != nil { - logger.Warn(err.Error()) + logger.Error("Error in creating containerd client", "err", err) + return nil } defer client.Close() + // Calls to containerd API are namespaced. + // "nomad" is the namespace that will be used for all nomad-driver-containerd + // related containerd API calls. + ctxContainerd := namespaces.WithNamespace(context.Background(), "nomad") + return &Driver{ eventer: eventer.NewEventer(ctx, logger), config: &Config{}, tasks: newTaskStore(), ctx: ctx, + ctxContainerd: ctxContainerd, + client: client, signalShutdown: cancel, logger: logger, }