Skip to content

Commit abc704a

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). I've replaced the Go reference from 48049d2 (Clarify the semantics of hook elements, 2015-11-25, #255) with POSIX references (following the new process docs) to address pushback against referencing Go [1,2] in favor of POSIX links [3]. Rob Dolin had suggested "platform-appropriate" wording [4], but it seems like Visual Studio 2015 supports execv [5], and providing an explicit "platform-appropriate" wiggle seems like it's adding useless complication. [1]: #427 (comment) [2]: http://ircbot.wl.linuxfoundation.org/meetings/opencontainers/2016/opencontainers.2016-05-18-17.01.log.html#l-46 [3]: http://ircbot.wl.linuxfoundation.org/meetings/opencontainers/2016/opencontainers.2016-05-18-17.01.log.html#l-52 [4]: http://ircbot.wl.linuxfoundation.org/meetings/opencontainers/2016/opencontainers.2016-05-18-17.01.log.html#l-54 [5]: https://msdn.microsoft.com/en-us/library/886kc0as.aspx Signed-off-by: W. Trevor King <[email protected]>
1 parent 55cebc8 commit abc704a

File tree

3 files changed

+15
-15
lines changed

3 files changed

+15
-15
lines changed

config.md

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -250,17 +250,23 @@ _Note: For Solaris, uid and gid specify the uid and gid of the process inside th
250250

251251
**`hooks`** (object, optional) configures callbacks for container lifecycle events.
252252
Lifecycle hooks allow custom events for different points in a container's runtime.
253-
Presently there are `Prestart`, `Poststart` and `Poststop`.
254253

255-
* [`Prestart`](#prestart) is a list of hooks to be run before the container process is executed
256-
* [`Poststart`](#poststart) is a list of hooks to be run immediately after the container process is started
257-
* [`Poststop`](#poststop) is a list of hooks to be run after the container process exits
254+
* **`hooks`** (object, optional) MAY contain any of the following properties:
255+
* **`prestart`** (array, optional) is an array of [pre-start hooks](#prestart).
256+
Entries in the array contain the following properties:
257+
* **`path`** (string, required) with similar semantics to [IEEE Std 1003.1-2001 `execv`'s *path*][ieee-1003.1-2001-xsh-exec].
258+
This specification extends the IEEE standard in that **`path`** MUST be absolute.
259+
* **`args`** (array of strings, required) with the same semantics as [IEEE Std 1003.1-2001 `execv`'s *argv*][ieee-1003.1-2001-xsh-exec].
260+
* **`env`** (array of strings, optional) with the same semantics as [IEEE Std 1003.1-2001's `environ`][ieee-1003.1-2001-xbd-c8.1].
261+
* **`timeout`** (int, optional) is the number of seconds before aborting the hook.
262+
* **`poststart`** (array, optional) is an array of [post-start hooks](#poststart).
263+
Entries in the array have the same schema as pre-start entries.
264+
* **`poststop`** (array, optional) is an array of [post-stop hooks](#poststop).
265+
Entries in the array have the same schema as pre-start entries.
258266

259267
Hooks allow one to run code before/after various lifecycle events of the container.
260268
Hooks MUST be called in the listed order.
261-
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.
262-
263-
Hook paths are absolute and are executed from the host's filesystem in the [runtime namespace][runtime-namespace].
269+
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.
264270

265271
### Prestart
266272

@@ -312,11 +318,6 @@ If a hook returns a non-zero exit code, then an error is logged and the remainin
312318
}
313319
```
314320

315-
`path` is required for a hook.
316-
`args` and `env` are optional.
317-
`timeout` is the number of seconds before aborting the hook.
318-
The semantics are the same as `Path`, `Args` and `Env` in [golang Cmd](https://golang.org/pkg/os/exec/#Cmd).
319-
320321
## Annotations
321322

322323
**`annotations`** (object, optional) contains arbitrary metadata for the container.

schema/config-schema.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,6 @@
168168
"platform",
169169
"process",
170170
"root",
171-
"mounts",
172-
"hooks"
171+
"mounts"
173172
]
174173
}

specs-go/config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ type Spec struct {
1717
// Mounts configures additional mounts (on top of Root).
1818
Mounts []Mount `json:"mounts,omitempty"`
1919
// Hooks configures callbacks for container lifecycle events.
20-
Hooks Hooks `json:"hooks"`
20+
Hooks Hooks `json:"hooks,omitempty"`
2121
// Annotations contains arbitrary metadata for the container.
2222
Annotations map[string]string `json:"annotations,omitempty"`
2323

0 commit comments

Comments
 (0)