Skip to content

Commit 7da699d

Browse files
Merge pull request #532 from wking/tk/restore-hook-lifecycle
Restore hook language removed by create/start split
2 parents 41839d7 + f636808 commit 7da699d

File tree

2 files changed

+32
-26
lines changed

2 files changed

+32
-26
lines changed

config.md

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -368,23 +368,18 @@ The [state](runtime.md#state) of the container MUST be passed to hooks over stdi
368368

369369
### <a name="configHooksPrestart" />Prestart
370370

371-
The pre-start hooks MUST be called after the container has been created, but before the user supplied command is executed.
371+
The pre-start hooks MUST be called after the [`start`](runtime.md#start) operation is called but [before the user-specified program command is executed](runtime.md#lifecycle).
372372
On Linux, for example, they are called after the container namespaces are created, so they provide an opportunity to customize the container (e.g. the network namespace could be specified in this hook).
373373

374-
If a hook returns a non-zero exit code, an error including the exit code and the stderr MUST be returned to the caller and the container MUST be destroyed.
375-
376374
### <a name="configHooksPoststart" />Poststart
377375

378-
The post-start hooks MUST be called after the user process is started.
376+
The post-start hooks MUST be called [after the user-specified process is executed](runtime#lifecycle) but before the [`start`](runtime.md#start) operation returns.
379377
For example, this hook can notify the user that the container process is spawned.
380378

381-
If a hook returns a non-zero exit code, then an error MUST be logged and the remaining hooks are executed.
382-
383379
### <a name="configHooksPoststop" />Poststop
384380

385-
The post-stop hooks MUST be called after the container process is stopped.
381+
The post-stop hooks MUST be called [after the container is deleted](runtime#lifecycle) but before the [`delete`](runtime.md#delete) operation returns.
386382
Cleanup or debugging functions are examples of such a hook.
387-
If a hook returns a non-zero exit code, then an error MUST be logged and the remaining hooks are executed.
388383

389384
### Example
390385

runtime.md

Lines changed: 29 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -52,23 +52,34 @@ The lifecycle describes the timeline of events that happen from when a container
5252

5353
1. OCI compliant runtime's [`create`](runtime.md#create) command is invoked with a reference to the location of the bundle and a unique identifier.
5454
2. The container's runtime environment MUST be created according to the configuration in [`config.json`](config.md).
55-
If the runtime is unable to create the environment specified in the [`config.json`](config.md), it MUST generate an error.
55+
If the runtime is unable to create the environment specified in the [`config.json`](config.md), it MUST [generate an error](#errors).
5656
While the resources requested in the [`config.json`](config.md) MUST be created, the user-specified program (from [`process`](config.md#process)) MUST NOT be run at this time.
5757
Any updates to [`config.json`](config.md) after this step MUST NOT affect the container.
5858
3. Once the container is created additional actions MAY be performed based on the features the runtime chooses to support.
5959
However, some actions might only be available based on the current state of the container (e.g. only available while it is started).
6060
4. Runtime's [`start`](runtime.md#start) command is invoked with the unique identifier of the container.
61-
The runtime MUST run the user-specified program, as specified by [`process`](config.md#process).
62-
5. The container process exits.
61+
5. The [prestart hooks](config.md#prestart) MUST be invoked by the runtime.
62+
If any prestart hook fails, the runtime MUST [generate an error](#errors), stop the container, and continue the lifecycle at step 10.
63+
6. The runtime MUST run the user-specified program, as specified by [`process`](config.md#process).
64+
7. The [poststart hooks](config.md#poststart) MUST be invoked by the runtime.
65+
If any poststart hook fails, the runtime MUST [log a warning](#warnings), but the remaining hooks and lifecycle continue as if the hook had succeeded.
66+
8. The container process exits.
6367
This MAY happen due to erroring out, exiting, crashing or the runtime's [`kill`](runtime.md#kill) operation being invoked.
64-
6. Runtime's [`delete`](runtime.md#delete) command is invoked with the unique identifier of the container.
65-
The container MUST be destroyed by undoing the steps performed during create phase (step 2).
68+
9. Runtime's [`delete`](runtime.md#delete) command is invoked with the unique identifier of the container.
69+
10. The container MUST be destroyed by undoing the steps performed during create phase (step 2).
70+
11. The [poststop hooks](config.md#poststop) MUST be invoked by the runtime.
71+
If any poststop hook fails, the runtime MUST [log a warning](#warnings), but the remaining hooks and lifecycle continue as if the hook had succeeded.
6672

6773
## <a name="runtimeErrors" />Errors
6874

6975
In cases where the specified operation generates an error, this specification does not mandate how, or even if, that error is returned or exposed to the user of an implementation.
7076
Unless otherwise stated, generating an error MUST leave the state of the environment as if the operation were never attempted - modulo any possible trivial ancillary changes such as logging.
7177

78+
## <a name="runtimeWarnings" />Warnings
79+
80+
In cases where the specified operation logs a warning, this specification does not mandate how, or even if, that warning is returned or exposed to the user of an implementation.
81+
Unless otherwise stated, logging a warning does not change the flow of the operation; it MUST continue as if the warning had not been logged.
82+
7283
## <a name="runtimeOperations" />Operations
7384

7485
OCI compliant runtimes MUST support the following operations, unless the operation is not supported by the base operating system.
@@ -79,19 +90,19 @@ Note: these operations are not specifying any command-line APIs, and the paramet
7990

8091
`state <container-id>`
8192

82-
This operation MUST generate an error if it is not provided the ID of a container.
83-
Attempting to query a container that does not exist MUST generate an error.
93+
This operation MUST [generate an error](#errors) if it is not provided the ID of a container.
94+
Attempting to query a container that does not exist MUST [generate an error](#errors).
8495
This operation MUST return the state of a container as specified in the [State](#state) section.
8596

8697
### <a name="runtimeCreate" />Create
8798

8899
`create <container-id> <path-to-bundle>`
89100

90-
This operation MUST generate an error if it is not provided a path to the bundle and the container ID to associate with the container.
91-
If the ID provided is not unique across all containers within the scope of the runtime, or is not valid in any other way, the implementation MUST generate an error and a new container MUST NOT be created.
101+
This operation MUST [generate an error](#errors) if it is not provided a path to the bundle and the container ID to associate with the container.
102+
If the ID provided is not unique across all containers within the scope of the runtime, or is not valid in any other way, the implementation MUST [generate an error](#errors) and a new container MUST NOT be created.
92103
Using the data in [`config.json`](config.md), this operation MUST create a new container.
93104
This means that all of the resources associated with the container MUST be created, however, the user-specified program MUST NOT be run at this time.
94-
If the runtime cannot create the container as specified in [`config.json`](config.md), it MUST generate an error and a new container MUST NOT be created.
105+
If the runtime cannot create the container as specified in [`config.json`](config.md), it MUST [generate an error](#errors) and a new container MUST NOT be created.
95106

96107
Upon successful completion of this operation the `status` property of this container MUST be `created`.
97108

@@ -103,28 +114,28 @@ Any changes made to the [`config.json`](config.md) file after this operation wil
103114
### <a name="runtimeStart" />Start
104115
`start <container-id>`
105116

106-
This operation MUST generate an error if it is not provided the container ID.
107-
Attempting to start a container that does not exist MUST generate an error.
108-
Attempting to start an already started container MUST have no effect on the container and MUST generate an error.
117+
This operation MUST [generate an error](#errors) if it is not provided the container ID.
118+
Attempting to start a container that does not exist MUST [generate an error](#errors).
119+
Attempting to start an already started container MUST have no effect on the container and MUST [generate an error](#errors).
109120
This operation MUST run the user-specified program as specified by [`process`](config.md#process).
110121

111122
Upon successful completion of this operation the `status` property of this container MUST be `running`.
112123

113124
### <a name="runtimeKill" />Kill
114125
`kill <container-id> <signal>`
115126

116-
This operation MUST generate an error if it is not provided the container ID.
117-
Attempting to send a signal to a container that is not running MUST have no effect on the container and MUST generate an error.
127+
This operation MUST [generate an error](#errors) if it is not provided the container ID.
128+
Attempting to send a signal to a container that is not running MUST have no effect on the container and MUST [generate an error](#errors).
118129
This operation MUST send the specified signal to the process in the container.
119130

120131
When the process in the container is stopped, irrespective of it being as a result of a `kill` operation or any other reason, the `status` property of this container MUST be `stopped`.
121132

122133
### <a name="runtimeDelete" />Delete
123134
`delete <container-id>`
124135

125-
This operation MUST generate an error if it is not provided the container ID.
126-
Attempting to delete a container that does not exist MUST generate an error.
127-
Attempting to delete a container whose process is still running MUST generate an error.
136+
This operation MUST [generate an error](#errors) if it is not provided the container ID.
137+
Attempting to delete a container that does not exist MUST [generate an error](#errors).
138+
Attempting to delete a container whose process is still running MUST [generate an error](#errors).
128139
Deleting a container MUST delete the resources that were created during the `create` step.
129140
Note that resources associated with the container, but not created by this container, MUST NOT be deleted.
130141
Once a container is deleted its ID MAY be used by a subsequent container.

0 commit comments

Comments
 (0)