Skip to content

Commit

Permalink
Split create and start
Browse files Browse the repository at this point in the history
Also renamed "stop" to "delete" this way if we split it into stop & delete
later on then delete is still pretty much the same.

Signed-off-by: Doug Davis <dug@us.ibm.com>
  • Loading branch information
Doug Davis committed Apr 1, 2016
1 parent b8d67bb commit 84bb619
Showing 1 changed file with 33 additions and 31 deletions.
64 changes: 33 additions & 31 deletions runtime.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,21 +34,19 @@ See [Query State](#query-state) for information on retrieving the state of a con
## Lifecycle
The lifecycle describes the timeline of events that happen from when a container is created to when it ceases to exist.

1. OCI compliant runtime is invoked with a reference to the location of the bundle.
How this reference is passed to the runtime is an implementation detail.
2. The container's runtime environment MUST be created according to the configuration in [`config.json`](config.md).
Any updates to `config.json` after container is running MUST not affect the container.
3. The prestart hooks MUST be invoked by the runtime.
If any prestart hook fails, then the container MUST be stopped and the lifecycle continues at step 8.
4. The user specified process MUST be executed in the container.
5. The poststart hooks MUST be invoked by the runtime.
If any poststart hook fails, then the container MUST be stopped and the lifecycle continues at step 8.
6. Additional actions such as pausing the container, resuming the container or signaling the container MAY be performed using the runtime interface.
1. OCI compliant runtime's `create` command is invoked with a reference to the location of the bundle and a unique identifier.
How these references are passed to the runtime is an implementation detail.
2. The container's runtime environment (namespaces, mounts, etc.) MUST be created according to the configuration in [`config.json`](config.md).
If a new PID namespace is requested in the [`config.json`](config.md), a PID namespace MUST created at this time.
However, the user specified process MUST NOT be created at this time.

This comment has been minimized.

Copy link
@wking

wking Apr 4, 2016

Contributor

I'd suggest “the user specified process MUST NOT be created” → “the user-specified code (from process) MUST NOT be executed”. Because the process that will eventually execute that code must be created here, it just shouldn't be running user-specified code yet.

This comment has been minimized.

Copy link
@duglin

duglin Apr 13, 2016

Contributor

done

With the exception of the user specified process, any updates to `config.json` after container is created MUST NOT affect the container.
3. Runtime's `start` command is invoked with the unique identifier of the container.
The runtime MUST create and start the user specified process, as indicated in [`config.json`](config.md), in the container's PID namespace.

This comment has been minimized.

Copy link
@wking

wking Apr 4, 2016

Contributor

I'd suggest making it very clear that the user-specified code should be run by the container process created by create, not just by any process in the container's namespaces. How about replacing the whole sentence with something like:

The container process created by start MUST apply the configuration specified in process and execute the code specified by process.args.

This comment has been minimized.

Copy link
@duglin

duglin Apr 13, 2016

Contributor

Actually, I'm not sure this is correct. The intent of my text was to make it so that you can set the 'process' in the config.json after create() but before start() - this is for cases where we may not know the process to run at create-time.

This comment has been minimized.

Copy link
@wking

wking via email Apr 13, 2016

Contributor
Any updates to the user specified process in [`config.json`](config.md) after this point MUST NOT have any effect on the container.
4. Additional actions such as pausing the container, resuming the container or signaling the container MAY be performed using the runtime interface.
The container MAY also error out, exit or crash.
7. The container MUST be destroyed by undoing the steps performed during create phase (step 2).
8. The poststop hooks MUST be invoked by the runtime and errors, if any, MAY be logged.

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.
5. Irrespective of how the user defined process stops (i.e. PID 1 exits), once the PID namespace is deleted the container MUST be destroyed by undoing the steps performed during create phase (step 2).
For clarity, all namespaces that were created in step 2 MUST be deleted.

## Operations

Expand All @@ -67,28 +65,37 @@ This operation MUST return the state of a container as specified in the [State](
In particular, the state MUST be serialized as JSON.


### Start
### Create

`start <container-id> <path-to-bundle>`
`create <container-id> <path-to-bundle>`

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.
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.
Using the data in `config.json`, that are in the bundle's directory, this operation MUST create a new container.
This includes creating the relevant namespaces, resource limits, etc and configuring the appropriate capabilities for the container.
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.
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.
Using the data in [`config.json`](config.md), that is in the root of the bundle's directory, this operation MUST create a new container.
This includes creating the namespaces specified in the [`config.json`](config.md), resource limits, etc and configuring the appropriate capabilities for the container.

This comment has been minimized.

Copy link
@julz

julz Apr 4, 2016

Contributor

creating the namespaces -> creating or entering the namespaces? (to make it clear that the exec-by-creating-a-config-json-that-enters-an-existing-container flow can be implemented here)

This comment has been minimized.

Copy link
@wking

wking Apr 4, 2016

Contributor

And if resource limits are being created at create-time, I'd recommend moving rlimits out of process (partially rolling back #341). Then we can have create be “everything except process” and start be “everything in process”.

This comment has been minimized.

Copy link
@duglin

duglin Apr 13, 2016

Contributor

did Julz's suggestion

If the `config.json` specifies that a PID namespace is to be created then one MUST be created, but the user specified process within that namespace MUST NOT be created at this time.
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 one.

### Start
`start <container-id>`

Attempting to start an already running container MUST have no effect on the container and MUST generate an error.
This operation MUST generate an error if it is not provided the container ID.
This operation MUST create, and start, the user specified process as specified by the [`config.json`](config.md) file otherwise an error MUST be generated and no process MUST be started.
This process MUST be run in the PID namespace associated with the container.

Attempting to start an already started container MUST have no effect on the container and MUST generate an error.

### Stop
### Delete

This comment has been minimized.

Copy link
@julz

julz Apr 4, 2016

Contributor

is delete necessary in this flow? I think since we say that pid 1 exiting cleans up we just need Kill. This maintains the pid-1-equals-container link and just opens up a nice time for hooks to run after create but before start (and a way to easily create a pod-like thing by creating multiple configs that enter a container's namespaces at create time). I think therefore we just need kill, maybe with a force or sync option that guarantees to only return when the process is dead?

This comment has been minimized.

Copy link
@julz

julz Apr 4, 2016

Contributor

ah, I just read the comment in the commit, it's here so if you split delete and stop you can have a different phase for delete. Makes sense, but maybe we don't even need the operation in this flow (since it's fully described in Create and happens automatically when the container exits). If this op stays it should actually probably still be called 'stop' since that's what it does. If we later allowed namespaces to persist past pid 1's death (which I still say doesnt make much sense, see below) we could add a 'delete' at that point to clean them up.

Reflecting on this jfwiw I still can't see a use case you can't achieve with just using the sleep pid 1 (either implied or Started) to keep the namespaces alive and using a series of containers that create their own pid namespace (and any other subset of namespaces they) to re-use the sandbox. Since it's super common to want a container to share only some namespaces (sidecar wants own rootfs but shared net, debugging container needs access to pids yada yada) I don't think it's possible to avoid talking about namespaces at the low level. We can avoid all the path complexities just by allowing a config to name an existing container by ID rather than a path to enter an existing namespace, though, which seems like it gives most of the benefits, even docker users can say --net=container:$id and --pid= etc. so we already break down the sandbox this way at the top level without confusing users all that much.

This comment has been minimized.

Copy link
@duglin

duglin Apr 5, 2016

Contributor

Couple of things....

  • I agree that there's an implicit delete/stop as part of the create() but I still think we need a stop/delete so that an end-user can terminate a container prematurely. We could look at it more like a "kill" command, to send a signal, but that gets to my next point....
  • if we have a merged stop and delete command (or kill/signal cmd), I think either verb can technically work. However, if we do split them later on I'd prefer to not break existing users. Meaning, someone using delete() today will continue to work even after we add stop() and they won't need to change anything to today's semantics of stop+delete. However, someone using stop() today will need to add a delete() after the split otherwise they'll have stuff left over. Kind of a backwards compat issue.

This comment has been minimized.

Copy link
@wking

wking via email Apr 5, 2016

Contributor

`stop <container-id>`
`delete <container-id>`

This operation MUST generate an error if it is not provided the container ID.
Attempting to delete a container that is not running, or that does not exist, MUST have no effect on the container and MUST generate an error.
This operation MUST stop and delete a running container.
Stopping a container MUST stop all of the processes running within the scope of the container.
Deleting a container MUST delete the associated namespaces and resources associated with the container.
Deleting a container MUST delete the namespaces, and resources, that were created during the `create` step.
Note that namespaces associated with the container but not created by this container MUST NOT be deleted.
Once a container is deleted, its `id` MAY be used by subsequent containers.
Attempting to stop a container that is not running MUST have no effect on the container and MUST generate an error.

### Exec

Expand Down Expand Up @@ -118,12 +125,7 @@ Example:
"cwd": "...",
}
```
This specification does not manadate the name of this JSON file.
This specification does not mandate the name of this JSON file.
See the specification of the `config.json` file for the definition of these fields.
The stopping, or exiting, of these secondary process MUST have no effect on the state of the container.
In other words, a container (and its PID 1 process) MUST NOT be stopped due to the exiting of a secondary process.

## Hooks

Many of the operations specified in this specification have "hooks" that allow for additional actions to be taken before or after each operation.
See [runtime configuration for hooks](./config.md#hooks) for more information.

0 comments on commit 84bb619

Please sign in to comment.