Skip to content

Commit 28023a7

Browse files
committed
Add description of standard hooks
This change adds a description of standard hooks to the CDI specification. These hooks can be used to update the LDCache in the container or to create symlinks. Signed-off-by: Evan Lezar <[email protected]>
1 parent 039c460 commit 28023a7

File tree

1 file changed

+100
-0
lines changed

1 file changed

+100
-0
lines changed

SPEC.md

+100
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,106 @@ The `containerEdits` field has the following definition:
250250
* `enableMBM` (boolean, OPTIONAL) whether to enable memory bandwidth monitoring
251251
* `additionalGids` (array of uint32s, OPTIONAL) A list of additional group IDs to add with the container process. These values are added to the `user.additionalGids` field in the OCI runtime specification. Values of 0 are ignored. Added in v0.7.0.
252252

253+
## Container Lifecycle Hooks
254+
255+
The `hooks` specified in a set of container edits, allow vendor-specific logic
256+
to be executed at various points in the container lifecycle. These are typically
257+
used for behaviour that depends on the container contents in some way.
258+
259+
In the case of OCI-compliant runtimes, these hooks are mapped directly to
260+
[OCI runtime hooks](https://github.com/opencontainers/runtime-spec/blob/main/config.md#posix-platform-hooks). For
261+
other use cases, it is the responsibility of the runtime developer to determine:
262+
263+
* If a hook is applicable for the specific use case
264+
* Which operations are equivalent to a hook in their runtime
265+
266+
In order to simplify onboarding new use cases and provide more clarity on the
267+
*intent* of the hooks present in a generated CDI specification, the following
268+
hooks specifically called out in the spec:
269+
270+
### create-symlinks
271+
272+
The `create-symlinks` hook is a `createContainer` hook that is used to ensure that
273+
required symlinks exist in a container. Typically these symlinks point to injected
274+
libraries or executables.
275+
276+
The hooks will have the following YAML definition:
277+
```yaml
278+
hooks:
279+
- path: <comnand-prefix>
280+
hookName: createContainer
281+
args:
282+
- <command-prefix-basename>
283+
- create-symlinks
284+
- --link=<target>::<link-path-in-container>
285+
```
286+
This hook will result in the following command being executed:
287+
```shell
288+
<command-prefix> create-symlinks --link=<target>::<link-path-in-container>
289+
```
290+
291+
And will:
292+
1. ensure that the parents of `<link-path-in-container>` exist in the container.
293+
2. create a symlink from `<link-path-in-container>` to `<target>` in the container.
294+
295+
which is equivalent to running:
296+
```shell
297+
mkdir -p $(dirname <link-path-in-container>)
298+
ln -s -f <target> <link-path-in-container>
299+
```
300+
in the container root.
301+
302+
The following should be noted:
303+
* `<command-prefix>` is a CLI that implements the `create-symlinks` command.
304+
* `<command-prefix>` is an absolute path on the *host*.
305+
* The `<command-prefix-basename>` argument is the basename of the `<command-prefix>` path or the full `<command-prefix>` path.
306+
* The `--link=<target>::<link-path-in-container>` arguments can be repeated for multiple links.
307+
* The hook is run from the host, and as such care should be taken to ensure that `<link-path-in-container>` does not resolve outside of the container root.
308+
* The hook is run in the mount namespace of the container.
309+
* The `<target>` need not exist in the container.
310+
311+
### update-ldcache
312+
313+
The `update-ldcache` hook is a `createContainer` hook that is used to ensure that
314+
the ldcache in a container is updated to include any injected libraries. This
315+
ensures that a user does not have to update environment variables such as `LD_LIBRARY_PATH`
316+
themselves. The hook also creates `SONAME` symlinks for any injected libraries.
317+
318+
The hooks will have the following YAML definition:
319+
```yaml
320+
hooks:
321+
- path: <comnand-prefix>
322+
hookName: createContainer
323+
args:
324+
- <command-prefix-basename>
325+
- update-ldcache
326+
- --folder=<container-folder1>
327+
```
328+
This hook will result in the following command being executed:
329+
```shell
330+
<command-prefix> update-ldcache --folder=<container-folder>
331+
```
332+
333+
And will:
334+
1. Ensure that shared libraries in the requested container folder(s) (`<container-folder>`) in the container are added to `/etc/ld.so.cache` in the container with the correct priority.
335+
2. Create the relevant `SONAME` symlinks in the container.
336+
337+
which is equivalent to running:
338+
```shell
339+
echo <container-folder> > /etc/ld.so.conf.f/00-mounted-libraries.conf
340+
ldconfig -C /etc/ld.so.cache -f /etc/ld.so.conf
341+
```
342+
in the container root.
343+
344+
The following should be noted:
345+
* `<command-prefix>` is a CLI that implements the `update-ldcache` command.
346+
* `<command-prefix>` is an absolute path on the *host*.
347+
* If `/etc/ld.so.cache` does not exit in a container, updating the LDCache is skipped, but the `SONAME` symlinks are still created.
348+
* The `<command-prefix-basename>` argument is the basename of the `<command-prefix>` path or the full `<command-prefix>` path.
349+
* The `--folder=<container-folder>` arguments can be repeated for multiple folder. These are added to the generated `.conf` file in the order specified.
350+
* The hook is run from the host, and as such care should be taken to ensure that `<container-folder>` does not resolve outside of the container root.
351+
* The hook is run in the mount namespace of the container.
352+
253353
## Error Handling
254354
* Kind requested is not present in any CDI file.
255355
Container runtimes should surface an error when a non-existent kind is requested.

0 commit comments

Comments
 (0)