Skip to content

Commit 0430aaf

Browse files
author
Doug Davis
committed
Split create and start
Signed-off-by: Doug Davis <[email protected]>
1 parent bf58a8f commit 0430aaf

File tree

2 files changed

+64
-35
lines changed

2 files changed

+64
-35
lines changed

config.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,15 @@ Each container has exactly one *root filesystem*, specified in the *root* object
2727

2828
* **`path`** (string, required) Specifies the path to the root filesystem for the container. A directory MUST exist at the path declared by the field.
2929
* **`readonly`** (bool, optional) If true then the root filesystem MUST be read-only inside the container. Defaults to false.
30+
* **`autoremove`** (bool, optional) If true then the container will be automatically deleted once the PID namespace is deleted. This removes the need for an explicit call to the `delete` operation. Defaults to false.
3031

3132
### Example
3233

3334
```json
3435
"root": {
3536
"path": "rootfs",
36-
"readonly": true
37+
"readonly": true,
38+
"autoremove": true
3739
}
3840
```
3941

runtime.md

Lines changed: 61 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@ The state of a container MUST include, at least, the following properties:
1313
* **`id`**: (string) is the container's ID.
1414
This MUST be unique across all containers on this host.
1515
There is no requirement that it be unique across hosts.
16-
The ID is provided in the state because hooks will be executed with the state as the payload.
17-
This allows the hooks to perform cleanup and teardown logic after the runtime destroys its own state.
1816
* **`pid`**: (int) is the ID of the main process within the container, as seen by the host.
1917
* **`bundlePath`**: (string) is the absolute path to the container's bundle directory.
2018
This is provided so that consumers can find the container's configuration and root filesystem on the host.
@@ -34,22 +32,25 @@ See [Query State](#query-state) for information on retrieving the state of a con
3432

3533
## Lifecycle
3634
The lifecycle describes the timeline of events that happen from when a container is created to when it ceases to exist.
37-
38-
1. OCI compliant runtime is invoked with a reference to the location of the bundle.
39-
How this reference is passed to the runtime is an implementation detail.
40-
2. The container's runtime environment MUST be created according to the configuration in [`config.json`](config.md).
41-
Any updates to `config.json` after container is running MUST not affect the container.
42-
3. The prestart hooks MUST be invoked by the runtime.
43-
If any prestart hook fails, then the container MUST be stopped and the lifecycle continues at step 7.
44-
4. The user specified process MUST be executed in the container.
45-
5. The poststart hooks MUST be invoked by the runtime.
46-
If any poststart hook fails, then the container MUST be stopped and the lifecycle continues at step 7.
47-
6. Additional actions such as pausing the container, resuming the container or signaling the container MAY be performed using the runtime interface.
48-
The container MAY also error out, exit or crash.
49-
7. The container MUST be destroyed by undoing the steps performed during create phase (step 2).
50-
8. The poststop hooks MUST be invoked by the runtime and errors, if any, SHOULD be logged.
51-
52-
Note: The lifecycle is a WIP and it will evolve as we have more use cases and more information on the viability of a separate create phase.
35+
1. OCI compliant runtime's `create` command is invoked with a reference to the location of the bundle and a unique identifier.
36+
How these references are passed to the runtime is an implementation detail.
37+
2. The container's runtime environment (namespaces, mounts, etc.) MUST be created according to the configuration in [`config.json`](config.md).
38+
If a new PID namespace is requested in the [`config.json`](config.md), a PID namespace MUST created at this time.
39+
However, the user-specified code (from [`process`](config.md#process-configuration) MUST NOT be run at this time.
40+
With the exception of the user-specified process, any updates to `config.json` after container is created MUST NOT affect the container.
41+
3. Once the container is created additional actions MAY be performed based on the features the runtime chooses to support.
42+
However, some actions might only be available based on the current state of the container (e.g. only available while it is started).
43+
4. Runtime's `start` command is invoked with the unique identifier of the container.
44+
The runtime MUST run the user-specified code, as specified by [`process`](config.md#process-configuration), in the container's PID namespace.
45+
Any updates to the user-specified code in [`process`](config.md#process-configuration) after this point MUST NOT have any effect on the container.
46+
5. The container's processes are stopped.
47+
This MAY happen due to them erroring out, exiting or crashing.
48+
The runtime's `stop` operation MAY also be used to stop the processes running within the container.
49+
6. If the [`autoremove`](config.md#root-configuration) property is present with a value of `true` the runtime's `delete` operation is automatically invoked.
50+
6. Runtime's `delete` command is invoked with the identifier of the container.
51+
The container MUST be destroyed by undoing the steps performed during create phase (step 2).
52+
For clarity, the runtime MUST make a best-effort attempt to delete all resources that were create in step 2.
53+
The phrase "best-effort" is to allow for situations where some other processes, or container, is "holding on" to a resource and the runtime is therefore unable to delete it.
5354

5455
## Operations
5556

@@ -64,34 +65,60 @@ Unless otherwise stated, generating an error MUST leave the state of the environ
6465
`state <container-id>`
6566

6667
This operation MUST generate an error if it is not provided the ID of a container.
68+
Attempting to query a container that does not exist MUST generate an error.
6769
This operation MUST return the state of a container as specified in the [State](#state) section.
68-
In particular, the state MUST be serialized as JSON.
70+
The state MUST be serialized as JSON.
6971

7072

71-
### Start
73+
### Create
7274

73-
`start <container-id> <path-to-bundle>`
75+
`create <container-id> <path-to-bundle>`
7476

7577
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.
76-
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.
77-
Using the data in `config.json`, that are in the bundle's directory, this operation MUST create a new container.
78-
This includes creating the relevant namespaces, resource limits, etc and configuring the appropriate capabilities for the container.
79-
A new process within the scope of the container MUST be created as specified by the `config.json` file otherwise an error MUST be generated.
78+
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.
79+
Using the data in [`config.json`](config.md), this operation MUST create a new container.
80+
This includes creating, or entering, the namespaces specified in the [`config.json`](config.md), resource limits, etc. and configuring the appropriate capabilities for the container.
81+
If the `config.json` specifies that a PID namespace is to be created then one MUST be created, but the user-specified code within that namespace MUST NOT be run at this time.
82+
In some implementations this means that a temporary process is created in the PID namespace but it pauses until the `start` operation is invoked before replacing the process with the user-specified code.
8083

81-
Attempting to start an already running container MUST have no effect on the container and MUST generate an error.
84+
### Start
85+
`start <container-id>`
8286

83-
### Stop
87+
This operation MUST generate an error if it is not provided the container ID.
88+
Attempting to start a container that does not exist MUST generate an error.
89+
This operation MUST run the user-specified code as specified by [`process`](config.md#process-configuration) in the configuration file at start-time (the values may have changed since [create](#create)-time).
90+
If the runtime fails to run code as specified, an error MUST be generated.
91+
For the purpose of the `start` command, the runtime MUST ignore `config.json` properties outside of `process`.
92+
This process MUST be run in the PID namespace associated with the container.
93+
94+
Attempting to start an already started container MUST have no effect on the container and MUST generate an error.
95+
96+
### Run
97+
`run <container-id>`
8498

99+
This operation MUST generate an error if it is not provided the container ID.
100+
Attempting to run a container that does not exist MUST generate an error.
101+
This operation MUST invoke the `create` operation, and if there are no errors, then invoke the `start` operation.
102+
The implementation MAY immediately execute `start` without any pause after `create` completes.
103+
For example if the implementation used a temporary process to implement `create`, it need not do this in the implementation of `run`.
104+
105+
### Stop
85106
`stop <container-id>`
86107

87108
This operation MUST generate an error if it is not provided the container ID.
88-
This operation MUST stop and delete a running container.
89-
Stopping a container MUST stop all of the processes running within the scope of the container.
90-
Deleting a container MUST delete the associated namespaces and resources associated with the container.
91-
Once a container is deleted, its `id` MAY be used by subsequent containers.
92109
Attempting to stop a container that is not running MUST have no effect on the container and MUST generate an error.
110+
This operation MUST stop all of the processes running within the container.
111+
If the [`autoremove`](config.md#root-configuration) property is is set to `false` then this operation MUST NOT delete any resources associated with the container, except for the PID namespace.
112+
If the [`autoremove`](config.md#root-configuration) property is is set to `true` then the `delete` operation MUST automatically be invoked by the runtime.
93113

94-
## Hooks
114+
### Delete
95115

96-
Many of the operations specified in this specification have "hooks" that allow for additional actions to be taken before or after each operation.
97-
See [runtime configuration for hooks](./config.md#hooks) for more information.
116+
`delete <container-id>`
117+
118+
This operation MUST generate an error if it is not provided the container ID.
119+
Attempting to delete a container that does not exist MUST generate an error.
120+
If the container is running then this operation MUST first stop it, per the `stop` operation defined above.
121+
If the stopping of the container fails then the container MUST NOT be deleted and an error MUST be generated.
122+
Deleting a container MUST delete the namespaces, and resources, that were created during the `create` step.
123+
Note that namespaces associated with the container but not created by this container MUST NOT be deleted.
124+
Once a container is deleted, its `id` MAY be used by subsequent containers.

0 commit comments

Comments
 (0)