-
Notifications
You must be signed in to change notification settings - Fork 61
/
runner.go
72 lines (61 loc) · 2.04 KB
/
runner.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
// SPDX-License-Identifier: BSD-3-Clause
// Copyright (c) 2022, Unikraft GmbH and The KraftKit Authors.
// Licensed under the BSD-3-Clause License (the "License").
// You may not use this file except in compliance with the License.
package run
import (
"context"
"fmt"
machineapi "kraftkit.sh/api/machine/v1alpha1"
"kraftkit.sh/packmanager"
)
// runner is an interface for defining different mechanisms to execute the
// provided unikernel. Standardizing first the check, Runnable, to determine
// whether the provided input is capable of executing, and Prepare, actually
// performing the preparation of the Machine specification for the controller.
type runner interface {
// String implements fmt.Stringer and returns the user-facing sentence
// representing the runner's context.
fmt.Stringer
// Name is a unique identifier for the runner.
Name() string
// Runnable checks whether the provided configuration is runnable.
Runnable(context.Context, *RunOptions, ...string) (bool, error)
// Prepare the provided configuration into a machine specification ready for
// execution by the controller.
Prepare(context.Context, *RunOptions, *machineapi.Machine, ...string) error
}
// runners is the list of built-in runners which are checked sequentially for
// capability. The first to test positive via Runnable is used with the
// controller.
func runners() ([]runner, error) {
r := []runner{
&runnerLinuxu{},
&runnerKernel{},
&runnerKraftfileUnikraft{},
&runnerKraftfileRuntime{},
}
umbrella, err := packmanager.PackageManagers()
if err != nil {
return nil, err
}
for _, pm := range umbrella {
r = append(r, &runnerPackage{
pm: pm,
})
}
return r, nil
}
// runnersByName is a utility method that returns a map of the available runners
// such that their alias name can be quickly looked up.
func runnersByName() (map[string]runner, error) {
runners, err := runners()
if err != nil {
return nil, err
}
ret := make(map[string]runner, len(runners))
for _, runner := range runners {
ret[runner.String()] = runner
}
return ret, nil
}