summaryrefslogtreecommitdiff
path: root/plugin/executor
diff options
context:
space:
mode:
authorCory Snider <csnider@mirantis.com>2022-05-05 13:00:45 -0400
committerCory Snider <csnider@mirantis.com>2022-08-24 14:59:08 -0400
commit6a2f385aea283aee4cce84c01308f5e7906a1564 (patch)
tree4f9ea8548b2a89fc030d7b9c973fa19aa1f01829 /plugin/executor
parent4bafaa00aa810dd17fde13e563def08f96fffc31 (diff)
downloaddocker-6a2f385aea283aee4cce84c01308f5e7906a1564.tar.gz
Share logic to create-or-replace a container
The existing logic to handle container ID conflicts when attempting to create a plugin container is not nearly as robust as the implementation in daemon for user containers. Extract and refine the logic from daemon and use it in the plugin executor. Signed-off-by: Cory Snider <csnider@mirantis.com>
Diffstat (limited to 'plugin/executor')
-rw-r--r--plugin/executor/containerd/containerd.go34
1 files changed, 2 insertions, 32 deletions
diff --git a/plugin/executor/containerd/containerd.go b/plugin/executor/containerd/containerd.go
index 2d3b99fe4c..0327e65dc4 100644
--- a/plugin/executor/containerd/containerd.go
+++ b/plugin/executor/containerd/containerd.go
@@ -75,39 +75,9 @@ func (p c8dPlugin) deleteTaskAndContainer(ctx context.Context) {
func (e *Executor) Create(id string, spec specs.Spec, stdout, stderr io.WriteCloser) error {
ctx := context.Background()
log := logrus.WithField("plugin", id)
- ctr, err := e.client.NewContainer(ctx, id, &spec, e.runtime.Shim.Binary, e.runtime.Shim.Opts)
+ ctr, err := libcontainerd.ReplaceContainer(ctx, e.client, id, &spec, e.runtime.Shim.Binary, e.runtime.Shim.Opts)
if err != nil {
- ctr2, err2 := e.client.LoadContainer(ctx, id)
- if err2 != nil {
- if !errdefs.IsNotFound(err2) {
- log.WithError(err2).Warn("Received an error while attempting to load containerd container for plugin")
- }
- } else {
- status := containerd.Unknown
- t, err2 := ctr2.Task(ctx)
- if err2 != nil {
- if !errdefs.IsNotFound(err2) {
- log.WithError(err2).Warn("Received an error while attempting to load containerd task for plugin")
- }
- } else {
- s, err2 := t.Status(ctx)
- if err2 != nil {
- log.WithError(err2).Warn("Received an error while attempting to read plugin status")
- } else {
- status = s.Status
- }
- }
- if status != containerd.Running && status != containerd.Unknown {
- if err2 := ctr2.Delete(ctx); err2 != nil && !errdefs.IsNotFound(err2) {
- log.WithError(err2).Error("Error cleaning up containerd container")
- }
- ctr, err = e.client.NewContainer(ctx, id, &spec, e.runtime.Shim.Binary, e.runtime.Shim.Opts)
- }
- }
-
- if err != nil {
- return errors.Wrap(err, "error creating containerd container")
- }
+ return errors.Wrap(err, "error creating containerd container for plugin")
}
p := c8dPlugin{log: log, ctr: ctr}