Skip to content

Commit a58c849

Browse files
committed
krun: parse annotations for krun.variant
Support the use of OCI annotations as a way for the container engine to configure the microVM. The user may add the `krun.variant` annotation to specify the flavor of libkrun they want to use. The current supported values are ["sev", "aws-nitro"]. Signed-off-by: Jake Correnti <jakecorrenti+github@proton.me>
1 parent e0a6f43 commit a58c849

1 file changed

Lines changed: 13 additions & 8 deletions

File tree

src/libcrun/handlers/krun.c

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161

6262
#define KRUN_FLAVOR_NITRO "aws-nitro"
6363
#define KRUN_FLAVOR_SEV "sev"
64+
#define KRUN_FLAVOR_DEFAULT "default"
6465

6566
struct krun_config
6667
{
@@ -226,7 +227,7 @@ libkrun_configure_vm (uint32_t ctx_id, void *handle, bool *configured, yajl_val
226227
}
227228

228229
static int
229-
libkrun_configure_flavor (void *cookie, yajl_val *config_tree, libcrun_error_t *err)
230+
libkrun_configure_flavor (void *cookie, yajl_val *config_tree, libcrun_container_t *container, libcrun_error_t *err)
230231
{
231232
int ret, sev_indicated = 0, nitro_indicated = 0;
232233
const char *path_flavor[] = { "flavor", (const char *) 0 };
@@ -238,14 +239,18 @@ libkrun_configure_flavor (void *cookie, yajl_val *config_tree, libcrun_error_t *
238239
close_handles[0] = NULL;
239240
close_handles[1] = NULL;
240241

241-
// Read if the SEV flavor was indicated in the krun VM config.
242-
val_flavor = yajl_tree_get (*config_tree, path_flavor, yajl_t_string);
243-
if (val_flavor != NULL && YAJL_IS_STRING (val_flavor))
242+
// Check if the user provided the krun variant through OCI annotations.
243+
flavor = (char *) find_annotation (container, "krun.variant");
244+
if (flavor == NULL)
244245
{
245-
flavor = YAJL_GET_STRING (val_flavor);
246+
// If the user doesn't specify a variant via OCI annotations, check the krun VM config to see if the "flavor" field was populated.
247+
val_flavor = yajl_tree_get (*config_tree, path_flavor, yajl_t_string);
248+
if (val_flavor != NULL && YAJL_IS_STRING (val_flavor))
249+
flavor = YAJL_GET_STRING (val_flavor);
250+
}
246251

247-
// The SEV flavor will be used if the krun VM config indicates to use SEV
248-
// within the "flavor" field.
252+
if (flavor != NULL)
253+
{
249254
sev_indicated |= strcmp (flavor, KRUN_FLAVOR_SEV) == 0;
250255
nitro_indicated |= strcmp (flavor, KRUN_FLAVOR_NITRO) == 0;
251256
}
@@ -327,7 +332,7 @@ libkrun_exec (void *cookie, libcrun_container_t *container, const char *pathname
327332
if (UNLIKELY (ret < 0))
328333
error (EXIT_FAILURE, -ret, "libkrun VM config exists, but unable to parse");
329334

330-
ret = libkrun_configure_flavor (cookie, &config_tree, &err);
335+
ret = libkrun_configure_flavor (cookie, &config_tree, container, &err);
331336
if (UNLIKELY (ret < 0))
332337
error (EXIT_FAILURE, -ret, "unable to configure libkrun flavor");
333338

0 commit comments

Comments
 (0)