Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add logic to cleanup the oci bundle root dir on container delete #1597

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions internal/guest/runtime/hcsv2/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,9 @@ type Container struct {
id string
vsock transport.Transport

spec *oci.Spec
isSandbox bool
spec *oci.Spec
ociBundlePath string
isSandbox bool

container runtime.Container
initProcess *containerProcess
Expand Down Expand Up @@ -211,6 +212,14 @@ func (c *Container) Delete(ctx context.Context) error {
}
}

if err := os.RemoveAll(c.ociBundlePath); err != nil {
if retErr != nil {
retErr = fmt.Errorf("errors deleting container oci bundle dir, %s & %s", retErr, err)
} else {
retErr = err
}
}

return retErr
}

Expand Down
7 changes: 4 additions & 3 deletions internal/guest/runtime/hcsv2/uvm.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@ func (h *Host) CreateContainer(ctx context.Context, id string, settings *prot.VM
id: id,
vsock: h.vsock,
spec: settings.OCISpecification,
ociBundlePath: settings.OCIBundlePath,
isSandbox: criType == "sandbox",
exitType: prot.NtUnexpectedExit,
processes: make(map[uint32]*containerProcess),
Expand Down Expand Up @@ -267,7 +268,7 @@ func (h *Host) CreateContainer(ctx context.Context, id string, settings *prot.VM
}
defer func() {
if err != nil {
_ = os.RemoveAll(spec.SandboxRootDir(id))
_ = os.RemoveAll(settings.OCIBundlePath)
}
}()

Expand All @@ -293,7 +294,7 @@ func (h *Host) CreateContainer(ctx context.Context, id string, settings *prot.VM
}
defer func() {
if err != nil {
_ = os.RemoveAll(getWorkloadRootDir(id))
_ = os.RemoveAll(settings.OCIBundlePath)
}
}()
if err := policy.ExtendPolicyWithNetworkingMounts(sandboxID, h.securityPolicyEnforcer, settings.OCISpecification); err != nil {
Expand All @@ -310,7 +311,7 @@ func (h *Host) CreateContainer(ctx context.Context, id string, settings *prot.VM
}
defer func() {
if err != nil {
_ = os.RemoveAll(getStandaloneRootDir(id))
_ = os.RemoveAll(settings.OCIBundlePath)
}
}()
}
Expand Down
4 changes: 0 additions & 4 deletions internal/guest/runtime/hcsv2/workload_container.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,6 @@ import (
"github.com/Microsoft/hcsshim/pkg/annotations"
)

func getWorkloadRootDir(id string) string {
return filepath.Join(guestpath.LCOWRootPrefixInUVM, id)
}

// os.MkdirAll combines the given permissions with the running process's
// umask. By default this causes 0777 to become 0755.
// Temporarily set the umask of this process to 0 so that we can actually
Expand Down