Skip to content

Commit

Permalink
feat: get prestart hooks working better
Browse files Browse the repository at this point in the history
  • Loading branch information
nixpig committed Oct 25, 2024
1 parent d54f4fa commit 8cb4384
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 12 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,8 @@ My goal is for `brownie` to (eventually) pass all test suites in the [opencontai
- [x] kill_no_effect
- [x] linux_mount_label
- [x] linux_sysctl
- [x] prestart
- [x] prestart_fail
- [x] process
- [x] process_capabilities
- [x] start
Expand Down Expand Up @@ -206,8 +208,6 @@ My goal is for `brownie` to (eventually) pass all test suites in the [opencontai
- [ ] poststart_fail
- [ ] poststop
- [ ] poststop_fail
- [ ] prestart
- [ ] prestart_fail
- [ ] process_capabilities_fail
- [ ] process_oom_score_adj
- [ ] process_rlimits
Expand Down
1 change: 1 addition & 0 deletions internal/commands/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ func Delete(opts *DeleteOpts, log *zerolog.Logger, db *sql.DB) error {
return errors.New("didn't delete container for whatever reason")
}

log.Info().Msg("execing poststop hooks")
if err := cntr.ExecHooks("poststop"); err != nil {
log.Warn().Err(err).Msg("failed to execute poststop hooks")
}
Expand Down
20 changes: 16 additions & 4 deletions internal/commands/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,22 @@ func Start(opts *StartOpts, log *zerolog.Logger, db *sql.DB) error {
return fmt.Errorf("dial socket: %w", err)
}

if err := cntr.ExecHooks("prestart"); err != nil {
log.Error().Err(err).Msg("failed to execute prestart hooks")
cntr.State.Status = specs.StateStopped
cntr.Save()
log.Info().Msg("BEFORE FAIL DELETE")

// TODO: run DELETE tasks here, then...

log.Info().Msg("execing poststop hooks")
if err := cntr.ExecHooks("poststop"); err != nil {
log.Warn().Err(err).Msg("failed to execute poststop hooks")
}

return errors.New("failed to run prestart hooks")
}

if _, err := conn.Write([]byte("start")); err != nil {
log.Error().Err(err).Msg("failed to send start message")
return fmt.Errorf("send start over ipc: %w", err)
Expand All @@ -59,10 +75,6 @@ func Start(opts *StartOpts, log *zerolog.Logger, db *sql.DB) error {

// FIXME: ?? when process starts, the PID in state should be updated to the process IN the container??

if err := cntr.ExecHooks("poststart"); err != nil {
log.Warn().Err(err).Msg("failed to execute poststart hooks")
}

// cntr.State.Status = specs.StateStopped
// if err := cntr.Save(); err != nil {
// log.Error().Err(err).Msg("save state after stopped")
Expand Down
15 changes: 9 additions & 6 deletions internal/container/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -360,12 +360,7 @@ func (c *Container) Fork(opts *ForkOpts, log *zerolog.Logger, db *sql.DB) error

c.initIPC.ch <- []byte("ready")

return ipc.WaitForMsg(listCh, "start", func() error {
if err := c.ExecHooks("prestart"); err != nil {
log.Error().Err(err).Msg("failed to execute prestart hooks")
return fmt.Errorf("execute prestart hooks: %w", err)
}

startErr := ipc.WaitForMsg(listCh, "start", func() error {
if err := filesystem.PivotRoot(c.State.Bundle); err != nil {
log.Error().Err(err).Msg("failed to pivot root")
return err
Expand Down Expand Up @@ -454,8 +449,15 @@ func (c *Container) Fork(opts *ForkOpts, log *zerolog.Logger, db *sql.DB) error
}
log.Info().Msg("UPDATED STATE FILE")

// if err := c.ExecHooks("poststart"); err != nil {
// log.Warn().Err(err).Msg("failed to execute poststart hooks")
// // TODO: how to handle this (log a warning) from start command??
// }

return nil
})

return startErr
}

func Load(id string, log *zerolog.Logger, db *sql.DB) (*Container, error) {
Expand Down Expand Up @@ -562,6 +564,7 @@ func (c *Container) ExecHooks(hook string) error {
var specHooks []specs.Hook
switch hook {
case "prestart":
//lint:ignore SA1019 marked as deprecated, but still required by OCI Runtime integration tests
specHooks = c.Spec.Hooks.Prestart
case "createRuntime":
specHooks = c.Spec.Hooks.CreateRuntime
Expand Down
1 change: 1 addition & 0 deletions oci.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ RUNTIME=${RUNTIME:-./brownie}
./validation/linux_sysctl/linux_sysctl.t 2>&1 | tee -a results.tap
# ./validation/pidfile/pidfile.t 2>&1 | tee -a results.tap
./validation/prestart/prestart.t 2>&1 | tee -a results.tap
./validation/prestart_fail/prestart_fail.t 2>&1 | tee -a results.tap
./validation/process/process.t 2>&1 | tee -a results.tap
./validation/process_capabilities/process_capabilities.t 2>&1 | tee -a results.tap
./validation/start/start.t 2>&1 | tee -a results.tap
Expand Down

0 comments on commit 8cb4384

Please sign in to comment.