Skip to content

Commit 7dce97b

Browse files
author
Mrunal Patel
authored
Merge pull request #427 from wking/optional-hooks
config: Explicitly list 'hooks' as optional
2 parents ced3365 + a78f255 commit 7dce97b

File tree

3 files changed

+20
-22
lines changed

3 files changed

+20
-22
lines changed

config.md

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -125,12 +125,9 @@ See links for details about [mountvol](http://ss64.com/nt/mountvol.html) and [Se
125125
* **`width`** (uint, REQUIRED)
126126
* **`cwd`** (string, REQUIRED) is the working directory that will be set for the executable.
127127
This value MUST be an absolute path.
128-
* **`env`** (array of strings, OPTIONAL) contains a list of variables that will be set in the process's environment prior to execution.
129-
Elements in the array are specified as Strings in the form "KEY=value".
130-
The left hand side MUST consist solely of letters, digits, and underscores `_` as outlined in [IEEE Std 1003.1-2001](http://pubs.opengroup.org/onlinepubs/009695399/basedefs/xbd_chap08.html).
131-
* **`args`** (array of strings, REQUIRED) executable to launch and any flags as an array.
132-
The executable is the first element and MUST be available at the given path inside of the rootfs.
133-
If the executable path is not an absolute path then the search $PATH is interpreted to find the executable.
128+
* **`env`** (array of strings, OPTIONAL) with the same semantics as [IEEE Std 1003.1-2001's `environ`][ieee-1003.1-2001-xbd-c8.1].
129+
* **`args`** (array of strings, REQUIRED) with similar semantics to [IEEE Std 1003.1-2001 `execvp`'s *argv*][ieee-1003.1-2001-xsh-exec].
130+
This specification extends the IEEE standard in that at least one entry is REQUIRED, and that entry is used with the same semantics as `execvp`'s *file*.
134131

135132
For Linux-based systems the process structure supports the following process specific fields:
136133

@@ -313,19 +310,24 @@ For Windows based systems the user structure has the following fields:
313310

314311
## Hooks
315312

316-
**`hooks`** (object, OPTIONAL) configures callbacks for container lifecycle events.
317313
Lifecycle hooks allow custom events for different points in a container's runtime.
318-
Presently there are `Prestart`, `Poststart` and `Poststop`.
319314

320-
* [`Prestart`](#prestart) is a list of hooks to be run before the container process is executed
321-
* [`Poststart`](#poststart) is a list of hooks to be run immediately after the container process is started
322-
* [`Poststop`](#poststop) is a list of hooks to be run after the container process exits
315+
* **`hooks`** (object, OPTIONAL) MAY contain any of the following properties:
316+
* **`prestart`** (array, OPTIONAL) is an array of [pre-start hooks](#prestart).
317+
Entries in the array contain the following properties:
318+
* **`path`** (string, REQUIRED) with similar semantics to [IEEE Std 1003.1-2001 `execv`'s *path*][ieee-1003.1-2001-xsh-exec].
319+
This specification extends the IEEE standard in that **`path`** MUST be absolute.
320+
* **`args`** (array of strings, REQUIRED) with the same semantics as [IEEE Std 1003.1-2001 `execv`'s *argv*][ieee-1003.1-2001-xsh-exec].
321+
* **`env`** (array of strings, OPTIONAL) with the same semantics as [IEEE Std 1003.1-2001's `environ`][ieee-1003.1-2001-xbd-c8.1].
322+
* **`timeout`** (int, OPTIONAL) is the number of seconds before aborting the hook.
323+
* **`poststart`** (array, OPTIONAL) is an array of [post-start hooks](#poststart).
324+
Entries in the array have the same schema as pre-start entries.
325+
* **`poststop`** (array, OPTIONAL) is an array of [post-stop hooks](#poststop).
326+
Entries in the array have the same schema as pre-start entries.
323327

324328
Hooks allow one to run programs before/after various lifecycle events of the container.
325329
Hooks MUST be called in the listed order.
326-
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.
327-
328-
Hook paths are absolute and are executed from the host's filesystem in the [runtime namespace][runtime-namespace].
330+
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.
329331

330332
### Prestart
331333

@@ -377,11 +379,6 @@ If a hook returns a non-zero exit code, then an error is logged and the remainin
377379
}
378380
```
379381

380-
`path` is REQUIRED for a hook.
381-
`args` and `env` are OPTIONAL.
382-
`timeout` is the number of seconds before aborting the hook.
383-
The semantics are the same as `Path`, `Args` and `Env` in [golang Cmd](https://golang.org/pkg/os/exec/#Cmd).
384-
385382
## Annotations
386383

387384
**`annotations`** (object, OPTIONAL) contains arbitrary metadata for the container.
@@ -762,6 +759,8 @@ Here is a full example `config.json` for reference.
762759

763760
[container-namespace]: glossary.md#container-namespace
764761
[go-environment]: https://golang.org/doc/install/source#environment
762+
[ieee-1003.1-2001-xbd-c8.1]: http://pubs.opengroup.org/onlinepubs/009695399/basedefs/xbd_chap08.html#tag_08_01
763+
[ieee-1003.1-2001-xsh-exec]: http://pubs.opengroup.org/onlinepubs/009695399/functions/exec.html
765764
[runtime-namespace]: glossary.md#runtime-namespace
766765
[uts-namespace]: http://man7.org/linux/man-pages/man7/namespaces.7.html
767766
[mount.8-filesystem-independent]: http://man7.org/linux/man-pages/man8/mount.8.html#FILESYSTEM-INDEPENDENT_MOUNT%20OPTIONS

schema/config-schema.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,6 @@
171171
"platform",
172172
"process",
173173
"root",
174-
"mounts",
175-
"hooks"
174+
"mounts"
176175
]
177176
}

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)