Skip to content

Commit cb4cfd8

Browse files
committed
config: Explicitly list 'hooks' as optional
And make it omitempty, otherwise: $ ocitools generate --template <(echo '{}') $ cat config.json | jq -S . { "hooks": {}, ... } To provide space for the type information and 'optional', I've shuffled the hook docs to follow our usual: * **`{property}`** ({type}, {when-needed}) {notes} format. I've kept the separate event-trigger sections (e.g. "### Prestart") since they go into more detail on the timing, purpose, and exit handling for the different events (and that seemed like too much information to put into the nested lists). Signed-off-by: W. Trevor King <[email protected]>
1 parent 38dd2fd commit cb4cfd8

File tree

2 files changed

+15
-13
lines changed

2 files changed

+15
-13
lines changed

config.md

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -229,17 +229,23 @@ _Note: For Solaris, uid and gid specify the uid and gid of the process inside th
229229
## Hooks
230230

231231
Lifecycle hooks allow custom events for different points in a container's runtime.
232-
Presently there are `Prestart`, `Poststart` and `Poststop`.
233232

234-
* [`Prestart`](#prestart) is a list of hooks to be run before the container process is executed
235-
* [`Poststart`](#poststart) is a list of hooks to be run immediately after the container process is started
236-
* [`Poststop`](#poststop) is a list of hooks to be run after the container process exits
233+
* **`hooks`** (object, optional) MAY contain any of the following properties:
234+
* **`prestart`** (array, optional) is an array of [pre-start hooks](#prestart).
235+
Entries in the array contain the following properties:
236+
* **`path`** (string, required) with the same semantics as Go's [`Cmd.Path`][go-cmd].
237+
Hook paths are absolute and are executed from the host's filesystem in the [runtime namespace][runtime-namespace].
238+
* **`args`** (array of strings, optional) with the same semantics as Go's [`Cmd.Args`][go-cmd].
239+
* **`env`** (array of strings, optional) with the same semantics as Go's [`Cmd.Env`][go-cmd].
240+
* **`timeout`** (int, optional) is the number of seconds before aborting the hook.
241+
* **`poststart`** (array, optional) is an array of [post-start hooks](#poststart).
242+
Entries in the array have the same schema as pre-start entries.
243+
* **`poststop`** (array, optional) is an array of [post-stop hooks](#poststop).
244+
Entries in the array have the same schema as pre-start entries.
237245

238246
Hooks allow one to run code before/after various lifecycle events of the container.
239247
Hooks MUST be called in the listed order.
240-
The state of the container is passed to the hooks over stdin, so the hooks could get the information they need to do their work.
241-
242-
Hook paths are absolute and are executed from the host's filesystem in the [runtime namespace][runtime-namespace].
248+
The [state](runtime.md#state) of the container is passed to the hooks over stdin, so the hooks could get the information they need to do their work.
243249

244250
### Prestart
245251

@@ -291,11 +297,6 @@ If a hook returns a non-zero exit code, then an error is logged and the remainin
291297
}
292298
```
293299

294-
`path` is required for a hook.
295-
`args` and `env` are optional.
296-
`timeout` is the number of seconds before aborting the hook.
297-
The semantics are the same as `Path`, `Args` and `Env` in [golang Cmd](https://golang.org/pkg/os/exec/#Cmd).
298-
299300
## Annotations
300301

301302
This OPTIONAL property contains arbitrary metadata for the container.
@@ -684,3 +685,4 @@ Here is a full example `config.json` for reference.
684685

685686
[runtime-namespace]: glossary.md#runtime-namespace
686687
[uts-namespace]: http://man7.org/linux/man-pages/man7/namespaces.7.html
688+
[go-cmd]: https://golang.org/pkg/os/exec/#Cmd

specs-go/config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ type Spec struct {
1919
// Mounts profile configuration for adding mounts to the container's filesystem.
2020
Mounts []Mount `json:"mounts,omitempty"`
2121
// Hooks are the commands run at various lifecycle events of the container.
22-
Hooks Hooks `json:"hooks"`
22+
Hooks Hooks `json:"hooks,omitempty"`
2323
// Annotations is an unstructured key value map that may be set by external tools to store and retrieve arbitrary metadata.
2424
Annotations map[string]string `json:"annotations,omitempty"`
2525

0 commit comments

Comments
 (0)