Skip to content

Commit

Permalink
xc cleanup for debug exits
Browse files Browse the repository at this point in the history
Signed-off-by: Kyle Quest <kcq.public@gmail.com>
  • Loading branch information
kcq committed Mar 17, 2024
1 parent 682b015 commit ac68899
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
13 changes: 13 additions & 0 deletions pkg/app/master/command/debug/handle_containerd_runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -332,15 +332,28 @@ func HandleContainerdRuntime(
logger.WithError(err).Error("api.NewContainer")
xc.FailOn(err)
}

defer debugContainer.Delete(ctx, containerd.WithSnapshotCleanup)

xc.AddCleanupHandler(func() {
logger.Trace("xc.cleanup")
if err := debugContainer.Delete(ctx, containerd.WithSnapshotCleanup); err != nil {
logger.Debugf("failed to delete container: %v", err)
}
})

ioc, con, err := prepareTaskIO(ctx, doTTY, true, debugContainer)
if err != nil {
logger.WithError(err).Error("prepareTaskIO")
xc.FailOn(err)
}
if con != nil {
defer con.Reset()

xc.AddCleanupHandler(func() {
logger.Trace("xc.cleanup")
con.Reset()
})
}

task, err := debugContainer.NewTask(ctx, ioc)
Expand Down
11 changes: 11 additions & 0 deletions pkg/app/master/command/debug/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,17 @@ func OnCommand(
cmdReport := report.NewDebugCommand(gparams.ReportLocation, gparams.InContainer)
cmdReport.State = cmd.StateStarted

cmdReportOnExit := func() {
cmdReport.State = cmd.StateError
if cmdReport.Save() {
xc.Out.Info("report",
ovars{
"file": cmdReport.ReportLocation(),
})
}
}
xc.AddCleanupHandler(cmdReportOnExit)

xc.Out.State("started")
paramVars := ovars{
"runtime": commandParams.Runtime,
Expand Down

0 comments on commit ac68899

Please sign in to comment.