Skip to content

Commit dcafe48

Browse files
committed
Add version to HookState to make it json-compatible with spec State
Signed-off-by: Mrunal Patel <mrunalp@gmail.com>
1 parent 9964fcd commit dcafe48

4 files changed

Lines changed: 15 additions & 8 deletions

File tree

libcontainer/configs/config.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,9 @@ type Config struct {
173173
// Hooks are a collection of actions to perform at various container lifecycle events.
174174
// Hooks are not able to be marshaled to json but they are also not needed to.
175175
Hooks *Hooks `json:"-"`
176+
177+
// Version is the version of opencontainer specification that is supported.
178+
Version string `json:"version"`
176179
}
177180

178181
type Hooks struct {
@@ -186,9 +189,10 @@ type Hooks struct {
186189

187190
// HookState is the payload provided to a hook on execution.
188191
type HookState struct {
189-
ID string `json:"id"`
190-
Pid int `json:"pid"`
191-
Root string `json:"root"`
192+
Version string `json:"version"`
193+
ID string `json:"id"`
194+
Pid int `json:"pid"`
195+
Root string `json:"root"`
192196
}
193197

194198
type Hook interface {

libcontainer/container_linux.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -250,8 +250,9 @@ func (c *linuxContainer) Destroy() error {
250250
c.initProcess = nil
251251
if c.config.Hooks != nil {
252252
s := configs.HookState{
253-
ID: c.id,
254-
Root: c.config.Rootfs,
253+
Version: c.config.Version,
254+
ID: c.id,
255+
Root: c.config.Rootfs,
255256
}
256257
for _, hook := range c.config.Hooks.Poststop {
257258
if err := hook.Run(s); err != nil {

libcontainer/process_linux.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -203,9 +203,10 @@ func (p *initProcess) start() (err error) {
203203
}()
204204
if p.config.Config.Hooks != nil {
205205
s := configs.HookState{
206-
ID: p.container.id,
207-
Pid: p.pid(),
208-
Root: p.config.Config.Rootfs,
206+
Version: p.container.config.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 {

spec.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,7 @@ func createLibcontainerConfig(cgroupName string, spec *specs.LinuxSpec, rspec *s
392392
config.ProcessLabel = rspec.Linux.SelinuxProcessLabel
393393
config.AppArmorProfile = rspec.Linux.ApparmorProfile
394394
createHooks(rspec, config)
395+
config.Version = specs.Version
395396
return config, nil
396397
}
397398

0 commit comments

Comments
 (0)