Skip to content

Commit 4db38e4

Browse files
committed
oci: kill process before delete
the OCI specs state that it is valid to delete a container only when it is in the "stopped" state. Signed-off-by: Giuseppe Scrivano <[email protected]>
1 parent 1c40e59 commit 4db38e4

File tree

4 files changed

+18
-2
lines changed

4 files changed

+18
-2
lines changed

validation/pidfile/pidfile.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"os/exec"
88
"path/filepath"
99
"strconv"
10+
"time"
1011

1112
tap "github.com/mndrix/tap-go"
1213
"github.com/opencontainers/runtime-tools/validation/util"
@@ -31,7 +32,7 @@ func main() {
3132
g.SetProcessArgs([]string{"true"})
3233
config := util.LifecycleConfig{
3334
Config: g,
34-
Actions: util.LifecycleActionCreate | util.LifecycleActionDelete,
35+
Actions: util.LifecycleActionCreate | util.LifecycleActionStart | util.LifecycleActionDelete,
3536
PreCreate: func(r *util.Runtime) error {
3637
r.SetID(uuid.NewV4().String())
3738
r.PidFile = tempPidFile
@@ -55,6 +56,13 @@ func main() {
5556
}
5657
return nil
5758
},
59+
PreDelete: func(r *util.Runtime) error {
60+
util.WaitingForStatus(*r, util.LifecycleStatusRunning, time.Second*10, time.Second*1)
61+
err = r.Kill("KILL")
62+
// wait before the container been deleted
63+
util.WaitingForStatus(*r, util.LifecycleStatusStopped, time.Second*10, time.Second*1)
64+
return err
65+
},
5866
}
5967

6068
err = util.RuntimeLifecycleValidate(config)

validation/state/state.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package main
33
import (
44
"fmt"
55
"os/exec"
6+
"time"
67

78
"github.com/mndrix/tap-go"
89
rspecs "github.com/opencontainers/runtime-spec/specs-go"
@@ -44,6 +45,8 @@ func main() {
4445
},
4546
PostCreate: func(r *util.Runtime) error {
4647
_, err = r.State()
48+
r.Kill("KILL")
49+
util.WaitingForStatus(*r, util.LifecycleStatusStopped, time.Second*10, time.Second)
4750
return err
4851
},
4952
}

validation/util/container.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"os"
1010
"os/exec"
1111
"path/filepath"
12+
"time"
1213

1314
rspecs "github.com/opencontainers/runtime-spec/specs-go"
1415
"github.com/opencontainers/runtime-tools/generate"
@@ -197,6 +198,9 @@ func (r *Runtime) Delete() (err error) {
197198
// forceRemoveBundle is true, after the deletion attempt regardless of
198199
// whether it was successful or not.
199200
func (r *Runtime) Clean(removeBundle bool, forceRemoveBundle bool) error {
201+
r.Kill("KILL")
202+
WaitingForStatus(*r, LifecycleStatusStopped, time.Second*10, time.Second/10)
203+
200204
err := r.Delete()
201205

202206
if removeBundle && (err == nil || forceRemoveBundle) {

validation/util/test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,8 @@ func RuntimeLifecycleValidate(config LifecycleConfig) error {
350350
if _, err := r.State(); err != nil {
351351
return
352352
}
353-
err := WaitingForStatus(r, LifecycleStatusCreated|LifecycleStatusStopped, time.Second*10, time.Second*1)
353+
r.Kill("KILL")
354+
err := WaitingForStatus(r, LifecycleStatusStopped, time.Second*10, time.Second*1)
354355
if err == nil {
355356
r.Delete()
356357
} else {

0 commit comments

Comments
 (0)