File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 44 "bytes"
55 "encoding/json"
66 "os/exec"
7+
8+ "github.com/opencontainers/specs"
79)
810
911type Rlimit struct {
@@ -180,30 +182,23 @@ type Hooks struct {
180182 Poststop []Hook
181183}
182184
183- // HookState is the payload provided to a hook on execution.
184- type HookState struct {
185- ID string `json:"id"`
186- Pid int `json:"pid"`
187- Root string `json:"root"`
188- }
189-
190185type Hook interface {
191186 // Run executes the hook with the provided state.
192- Run (HookState ) error
187+ Run (specs. State ) error
193188}
194189
195190// NewFunctionHooks will call the provided function when the hook is run.
196- func NewFunctionHook (f func (HookState ) error ) FuncHook {
191+ func NewFunctionHook (f func (specs. State ) error ) FuncHook {
197192 return FuncHook {
198193 run : f ,
199194 }
200195}
201196
202197type FuncHook struct {
203- run func (HookState ) error
198+ run func (specs. State ) error
204199}
205200
206- func (f FuncHook ) Run (s HookState ) error {
201+ func (f FuncHook ) Run (s specs. State ) error {
207202 return f .run (s )
208203}
209204
@@ -225,7 +220,7 @@ type CommandHook struct {
225220 Command
226221}
227222
228- func (c Command ) Run (s HookState ) error {
223+ func (c Command ) Run (s specs. State ) error {
229224 b , err := json .Marshal (s )
230225 if err != nil {
231226 return err
Original file line number Diff line number Diff line change @@ -18,6 +18,7 @@ import (
1818 "github.com/opencontainers/runc/libcontainer/cgroups"
1919 "github.com/opencontainers/runc/libcontainer/configs"
2020 "github.com/opencontainers/runc/libcontainer/criurpc"
21+ "github.com/opencontainers/specs"
2122)
2223
2324const stdioFdCount = 3
@@ -249,9 +250,10 @@ func (c *linuxContainer) Destroy() error {
249250 }
250251 c .initProcess = nil
251252 if c .config .Hooks != nil {
252- s := configs.HookState {
253- ID : c .id ,
254- Root : c .config .Rootfs ,
253+ s := specs.State {
254+ Version : specs .Version ,
255+ ID : c .id ,
256+ Root : c .config .Rootfs ,
255257 }
256258 for _ , hook := range c .config .Hooks .Poststop {
257259 if err := hook .Run (s ); err != nil {
Original file line number Diff line number Diff line change @@ -13,6 +13,7 @@ import (
1313 "github.com/opencontainers/runc/libcontainer"
1414 "github.com/opencontainers/runc/libcontainer/cgroups/systemd"
1515 "github.com/opencontainers/runc/libcontainer/configs"
16+ "github.com/opencontainers/specs"
1617)
1718
1819func TestExecPS (t * testing.T ) {
@@ -948,7 +949,7 @@ func TestHook(t *testing.T) {
948949 config := newTemplateConfig (rootfs )
949950 config .Hooks = & configs.Hooks {
950951 Prestart : []configs.Hook {
951- configs .NewFunctionHook (func (s configs. HookState ) error {
952+ configs .NewFunctionHook (func (s specs. State ) error {
952953 f , err := os .Create (filepath .Join (s .Root , "test" ))
953954 if err != nil {
954955 return err
@@ -957,7 +958,7 @@ func TestHook(t *testing.T) {
957958 }),
958959 },
959960 Poststop : []configs.Hook {
960- configs .NewFunctionHook (func (s configs. HookState ) error {
961+ configs .NewFunctionHook (func (s specs. State ) error {
961962 return os .RemoveAll (filepath .Join (s .Root , "test" ))
962963 }),
963964 },
Original file line number Diff line number Diff line change @@ -13,8 +13,8 @@ import (
1313 "syscall"
1414
1515 "github.com/opencontainers/runc/libcontainer/cgroups"
16- "github.com/opencontainers/runc/libcontainer/configs"
1716 "github.com/opencontainers/runc/libcontainer/system"
17+ "github.com/opencontainers/specs"
1818)
1919
2020type parentProcess interface {
@@ -202,10 +202,11 @@ func (p *initProcess) start() (err error) {
202202 }
203203 }()
204204 if p .config .Config .Hooks != nil {
205- s := configs.HookState {
206- ID : p .container .id ,
207- Pid : p .pid (),
208- Root : p .config .Config .Rootfs ,
205+ s := specs.State {
206+ Version : specs .Version ,
207+ ID : p .container .id ,
208+ Pid : p .pid (),
209+ Root : p .config .Config .Rootfs ,
209210 }
210211 for _ , hook := range p .config .Config .Hooks .Prestart {
211212 if err := hook .Run (s ); err != nil {
You can’t perform that action at this time.
0 commit comments