Fix bundle removal with the reappearance of state dir
Bundle removal now requires removing both workdir and path locations on delete in shim. Signed-off-by: Phil Estes <estesp@linux.vnet.ibm.com>
This commit is contained in:
		| @@ -14,13 +14,15 @@ import ( | ||||
| 	client "github.com/containerd/containerd/linux/shim" | ||||
| 	"github.com/containerd/containerd/runtime" | ||||
| 	"github.com/containerd/containerd/typeurl" | ||||
| 	"github.com/pkg/errors" | ||||
| ) | ||||
|  | ||||
| func loadBundle(path, namespace string, events *events.Exchange) *bundle { | ||||
| func loadBundle(path, workdir, namespace string, events *events.Exchange) *bundle { | ||||
| 	return &bundle{ | ||||
| 		path:      path, | ||||
| 		namespace: namespace, | ||||
| 		events:    events, | ||||
| 		workDir:   workdir, | ||||
| 	} | ||||
| } | ||||
|  | ||||
| @@ -112,7 +114,16 @@ func (b *bundle) Connect(ctx context.Context, remote bool) (*client.Client, erro | ||||
|  | ||||
| // Delete deletes the bundle from disk | ||||
| func (b *bundle) Delete() error { | ||||
| 	return os.RemoveAll(b.path) | ||||
| 	err := os.RemoveAll(b.path) | ||||
| 	if err == nil { | ||||
| 		return os.RemoveAll(b.workDir) | ||||
| 	} | ||||
| 	// error removing the bundle path; still attempt removing work dir | ||||
| 	err2 := os.RemoveAll(b.workDir) | ||||
| 	if err2 == nil { | ||||
| 		return err | ||||
| 	} | ||||
| 	return errors.Wrapf(err, "Failed to remove both bundle and workdir locations: %v", err2) | ||||
| } | ||||
|  | ||||
| func (b *bundle) shimAddress() string { | ||||
|   | ||||
| @@ -211,7 +211,7 @@ func (r *Runtime) Delete(ctx context.Context, c runtime.Task) (*runtime.Exit, er | ||||
| 	} | ||||
| 	r.tasks.Delete(ctx, lc) | ||||
|  | ||||
| 	bundle := loadBundle(filepath.Join(r.state, namespace, lc.id), namespace, r.events) | ||||
| 	bundle := loadBundle(filepath.Join(r.state, namespace, lc.id), filepath.Join(r.root, namespace, lc.id), namespace, r.events) | ||||
| 	if err := bundle.Delete(); err != nil { | ||||
| 		return nil, err | ||||
| 	} | ||||
| @@ -262,7 +262,7 @@ func (r *Runtime) loadTasks(ctx context.Context, ns string) ([]*Task, error) { | ||||
| 			continue | ||||
| 		} | ||||
| 		id := path.Name() | ||||
| 		bundle := loadBundle(filepath.Join(r.state, ns, id), ns, r.events) | ||||
| 		bundle := loadBundle(filepath.Join(r.state, ns, id), filepath.Join(r.root, ns, id), ns, r.events) | ||||
|  | ||||
| 		s, err := bundle.Connect(ctx, r.remote) | ||||
| 		if err != nil { | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Phil Estes
					Phil Estes