Skip to content

Commit bd8884e

Browse files
committed
runtime: specify default kernel arguments
Related: #59 Signed-off-by: Samuel Karp <[email protected]>
1 parent e1f9ba6 commit bd8884e

File tree

5 files changed

+61
-6
lines changed

5 files changed

+61
-6
lines changed

docs/getting-started.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,9 @@ configuration file has the following fields:
214214
changes every execution when run by containerd.
215215
* `kernel_image_path` (required) - A path where the kernel image file is
216216
located. A fully-qualified path is recommended.
217-
* `kernel_args` (required) - Arguments for the kernel command line.
217+
* `kernel_args` (optional) - Arguments for the kernel command line. If left
218+
undefined, the runtime specifies "console=ttyS0 noapic reboot=k panic=1
219+
pci=off nomodules rw".
218220
* `root_drive` (required) - A path where the root drive image file is located. A
219221
fully-qualified path is recommended.
220222
* `cpu_count` (required) - The number of vCPUs to make available to a microVM.

docs/quickstart.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,6 @@ sudo tee -a /etc/containerd/firecracker-runtime.json <<EOF
139139
{
140140
"firecracker_binary_path": "/usr/local/bin/firecracker",
141141
"kernel_image_path": "/var/lib/firecracker-containerd/runtime/hello-vmlinux.bin",
142-
"kernel_args": "console=ttyS0 noapic reboot=k panic=1 pci=off nomodules rw",
143142
"root_drive": "/var/lib/firecracker-containerd/runtime/hello-rootfs.ext4",
144143
"cpu_count": 1,
145144
"cpu_template": "T2",

runtime/README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,9 @@ configuration file has the following fields:
4040
changes every execution when run by containerd.
4141
* `kernel_image_path` (required) - A path where the kernel image file is
4242
located. A fully-qualified path is recommended.
43-
* `kernel_args` (required) - Arguments for the kernel command line.
43+
* `kernel_args` (optional) - Arguments for the kernel command line. If left
44+
undefined, the runtime specifies "console=ttyS0 noapic reboot=k panic=1
45+
pci=off nomodules rw".
4446
* `root_drive` (required) - A path where the root drive image file is located. A
4547
fully-qualified path is recommended.
4648
* `cpu_count` (required) - The number of vCPUs to make available to a microVM.

runtime/config.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ const (
2525
configPathEnvName = "FIRECRACKER_CONTAINERD_RUNTIME_CONFIG_PATH"
2626
defaultConfigPath = "/etc/containerd/firecracker-runtime.json"
2727
defaultSocketPath = "./firecracker.sock"
28+
defaultKernelArgs = "console=ttyS0 noapic reboot=k panic=1 pci=off nomodules rw"
2829
)
2930

3031
// Config represents runtime configuration parameters
@@ -58,10 +59,12 @@ func LoadConfig(path string) (*Config, error) {
5859
return nil, errors.Wrapf(err, "failed to read config from %q", path)
5960
}
6061

61-
var cfg Config
62-
if err := json.Unmarshal(data, &cfg); err != nil {
62+
cfg := &Config{
63+
KernelArgs: defaultKernelArgs,
64+
}
65+
if err := json.Unmarshal(data, cfg); err != nil {
6366
return nil, errors.Wrapf(err, "failed to unmarshal config from %q", path)
6467
}
6568

66-
return &cfg, nil
69+
return cfg, nil
6770
}

runtime/config_test.go

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
"io/ioutil"
6+
"os"
7+
"testing"
8+
9+
"github.com/stretchr/testify/assert"
10+
)
11+
12+
func TestLoadConfigDefaults(t *testing.T) {
13+
configContent := `{}`
14+
configFile, cleanup := createTempConfig(t, configContent)
15+
defer cleanup()
16+
cfg, err := LoadConfig(configFile)
17+
if err != nil {
18+
t.Error(err, "failed to load config")
19+
}
20+
21+
assert.Equal(t, cfg.KernelArgs, defaultKernelArgs, "expected default kernel args")
22+
}
23+
24+
func TestLoadConfigOverrides(t *testing.T) {
25+
overrideKernelArgs := "OVERRIDE KERNEL ARGS"
26+
configContent := fmt.Sprintf(`{"kernel_args":"%s"}`, overrideKernelArgs)
27+
configFile, cleanup := createTempConfig(t, configContent)
28+
defer cleanup()
29+
cfg, err := LoadConfig(configFile)
30+
if err != nil {
31+
t.Error(err, "failed to load config")
32+
}
33+
34+
assert.Equal(t, cfg.KernelArgs, overrideKernelArgs, "expected overridden kernel args")
35+
}
36+
37+
func createTempConfig(t *testing.T, contents string) (string, func()) {
38+
t.Helper()
39+
configFile, err := ioutil.TempFile("", "config")
40+
if err != nil {
41+
t.Fatal(err, "failed to create temp config file")
42+
}
43+
err = ioutil.WriteFile(configFile.Name(), []byte(contents), 0644)
44+
if err != nil {
45+
os.Remove(configFile.Name())
46+
t.Fatal(err, "failed to write contents to temp config file")
47+
}
48+
return configFile.Name(), func() { os.Remove(configFile.Name()) }
49+
}

0 commit comments

Comments
 (0)