Skip to content

Commit 5fa964a

Browse files
committed
Create CNI-enabled firecracker-runtime.json on the fly
As #291 suggested, this change adds a helper that modifies firecracker-runtime.json. Signed-off-by: Kazuyoshi Kato <[email protected]>
1 parent 7649f00 commit 5fa964a

File tree

5 files changed

+65
-29
lines changed

5 files changed

+65
-29
lines changed

runtime/cni_integ_test.go

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -357,11 +357,16 @@ func writeCNIConf(path, chainedPluginName, networkName, nameserver string) error
357357
func useDefaultNetworkInterfaceRuntimeConfig(t *testing.T) {
358358
t.Helper()
359359

360-
err := os.RemoveAll(runtimeConfigPath)
361-
require.NoError(t, err, "failed to remove existing firecracker containerd runtime config file")
362-
363-
err = os.Symlink(defaultNetworkInterfaceRuntimeConfigPath, runtimeConfigPath)
364-
require.NoError(t, err, "failed to symlink default network interface runtime config")
360+
writeRuntimeConfig(func(c *Config) {
361+
c.DefaultNetworkInterfaces = []proto.FirecrackerNetworkInterface{
362+
{
363+
CNIConfig: &proto.CNIConfiguration{
364+
NetworkName: "fcnet",
365+
InterfaceName: "veth0",
366+
},
367+
},
368+
}
369+
})
365370
}
366371

367372
func runCommand(ctx context.Context, t *testing.T, name string, args ...string) {

runtime/integ.go

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
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+
package main
14+
15+
import (
16+
"encoding/json"
17+
"os"
18+
)
19+
20+
const runtimeConfigPath = "/etc/containerd/firecracker-runtime.json"
21+
22+
var defaultRuntimeConfig = Config{
23+
FirecrackerBinaryPath: "/usr/local/bin/firecracker",
24+
KernelImagePath: "/var/lib/firecracker-containerd/runtime/default-vmlinux.bin",
25+
KernelArgs: "ro console=ttyS0 noapic reboot=k panic=1 pci=off nomodules systemd.journald.forward_to_console systemd.unit=firecracker.target init=/sbin/overlay-init",
26+
RootDrive: "/var/lib/firecracker-containerd/runtime/default-rootfs.img",
27+
CPUCount: 1,
28+
CPUTemplate: "T2",
29+
LogLevel: "Debug",
30+
}
31+
32+
func writeRuntimeConfig(options ...func(*Config)) error {
33+
config := defaultRuntimeConfig
34+
for _, option := range options {
35+
option(&config)
36+
}
37+
38+
file, err := os.Create(runtimeConfigPath)
39+
if err != nil {
40+
return err
41+
}
42+
defer file.Close()
43+
44+
bytes, err := json.Marshal(config)
45+
if err != nil {
46+
return err
47+
}
48+
49+
_, err = file.Write(bytes)
50+
if err != nil {
51+
return err
52+
}
53+
54+
return nil
55+
}

runtime/service_integ_test.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,6 @@ const (
6363
defaultVMRootfsPath = "/var/lib/firecracker-containerd/runtime/default-rootfs.img"
6464
defaultVMNetDevName = "eth0"
6565
varRunDir = "/run/firecracker-containerd"
66-
67-
runtimeConfigPath = "/etc/containerd/firecracker-runtime.json"
68-
defaultNetworkInterfaceRuntimeConfigPath = "/etc/containerd/firecracker-runtime-defaultnetwork.json"
6966
)
7067

7168
// Images are presumed by the isolated tests to have already been pulled

tools/docker/Dockerfile

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,6 @@ COPY _submodules/firecracker/target/$FIRECRACKER_TARGET/release/firecracker /usr
149149
COPY _submodules/firecracker/target/$FIRECRACKER_TARGET/release/jailer /usr/local/bin/
150150
COPY _submodules/runc/runc /usr/local/bin
151151
COPY tools/image-builder/rootfs.img /var/lib/firecracker-containerd/runtime/default-rootfs.img
152-
COPY tools/docker/firecracker-runtime.json /etc/containerd/firecracker-runtime.json
153152

154153
# pull the images the tests need into the content store so we don't need internet
155154
# access during the tests themselves
@@ -165,7 +164,6 @@ RUN make -C /firecracker-containerd/internal test-bridged-tap && \
165164
chmod a+x /firecracker-containerd/internal/test-bridged-tap
166165

167166
COPY tools/docker/firecracker-runtime.json /etc/containerd/firecracker-runtime.json
168-
COPY tools/docker/firecracker-runtime-defaultnetwork.json /etc/containerd/firecracker-runtime-defaultnetwork.json
169167
COPY tools/docker/naive-snapshotter/entrypoint.sh /entrypoint
170168

171169
ENTRYPOINT ["/entrypoint"]

tools/docker/firecracker-runtime-defaultnetwork.json

Lines changed: 0 additions & 19 deletions
This file was deleted.

0 commit comments

Comments
 (0)