Skip to content

Commit f6fb24c

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

File tree

5 files changed

+74
-6
lines changed

5 files changed

+74
-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: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
// Copyright 2018-2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License"). You may
4+
// not use this file except in compliance with the License. A copy of the
5+
// License is located at
6+
//
7+
// http://aws.amazon.com/apache2.0/
8+
//
9+
// or in the "license" file accompanying this file. This file is distributed
10+
// on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
11+
// express or implied. See the License for the specific language governing
12+
// permissions and limitations under the License.
13+
14+
package main
15+
16+
import (
17+
"fmt"
18+
"io/ioutil"
19+
"os"
20+
"testing"
21+
22+
"github.com/stretchr/testify/assert"
23+
)
24+
25+
func TestLoadConfigDefaults(t *testing.T) {
26+
configContent := `{}`
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, defaultKernelArgs, "expected default kernel args")
35+
}
36+
37+
func TestLoadConfigOverrides(t *testing.T) {
38+
overrideKernelArgs := "OVERRIDE KERNEL ARGS"
39+
configContent := fmt.Sprintf(`{"kernel_args":"%s"}`, overrideKernelArgs)
40+
configFile, cleanup := createTempConfig(t, configContent)
41+
defer cleanup()
42+
cfg, err := LoadConfig(configFile)
43+
if err != nil {
44+
t.Error(err, "failed to load config")
45+
}
46+
47+
assert.Equal(t, cfg.KernelArgs, overrideKernelArgs, "expected overridden kernel args")
48+
}
49+
50+
func createTempConfig(t *testing.T, contents string) (string, func()) {
51+
t.Helper()
52+
configFile, err := ioutil.TempFile("", "config")
53+
if err != nil {
54+
t.Fatal(err, "failed to create temp config file")
55+
}
56+
err = ioutil.WriteFile(configFile.Name(), []byte(contents), 0644)
57+
if err != nil {
58+
os.Remove(configFile.Name())
59+
t.Fatal(err, "failed to write contents to temp config file")
60+
}
61+
return configFile.Name(), func() { os.Remove(configFile.Name()) }
62+
}

0 commit comments

Comments
 (0)