Skip to content

Commit 5de4919

Browse files
authored
Merge pull request #230 from xibz/219
machine config is not available at this time
2 parents 9ee5bca + 26e67db commit 5de4919

File tree

3 files changed

+59
-5
lines changed

3 files changed

+59
-5
lines changed

jailer.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ const (
3030
defaultJailerBin = "jailer"
3131

3232
rootfsFolderName = "root"
33+
34+
defaultSocketPath = "/run/firecracker.socket"
3335
)
3436

3537
var (
@@ -288,7 +290,14 @@ func jail(ctx context.Context, m *Machine, cfg *Config) error {
288290
jailerWorkspaceDir = filepath.Join(defaultJailerPath, filepath.Base(cfg.JailerCfg.ExecFile), cfg.JailerCfg.ID, rootfsFolderName)
289291
}
290292

291-
cfg.SocketPath = filepath.Join(jailerWorkspaceDir, "run", "firecracker.socket")
293+
var machineSocketPath string
294+
if cfg.SocketPath != "" {
295+
machineSocketPath = cfg.SocketPath
296+
} else {
297+
machineSocketPath = defaultSocketPath
298+
}
299+
300+
cfg.SocketPath = filepath.Join(jailerWorkspaceDir, machineSocketPath)
292301

293302
stdout := cfg.JailerCfg.Stdout
294303
if stdout == nil {
@@ -310,6 +319,7 @@ func jail(ctx context.Context, m *Machine, cfg *Config) error {
310319
WithDaemonize(cfg.JailerCfg.Daemonize).
311320
WithFirecrackerArgs(
312321
"--seccomp-level", cfg.SeccompLevel.String(),
322+
"--api-sock", machineSocketPath,
313323
).
314324
WithStdout(stdout).
315325
WithStderr(stderr)

jailer_test.go

Lines changed: 46 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ func TestJail(t *testing.T) {
156156
jailerCfg JailerConfig
157157
expectedArgs []string
158158
netns string
159+
socketPath string
159160
expectedSockPath string
160161
}{
161162
{
@@ -183,6 +184,8 @@ func TestJail(t *testing.T) {
183184
"--",
184185
"--seccomp-level",
185186
"0",
187+
"--api-sock",
188+
"/run/firecracker.socket",
186189
},
187190
expectedSockPath: filepath.Join(
188191
defaultJailerPath,
@@ -218,6 +221,8 @@ func TestJail(t *testing.T) {
218221
"--",
219222
"--seccomp-level",
220223
"0",
224+
"--api-sock",
225+
"/run/firecracker.socket",
221226
},
222227
expectedSockPath: filepath.Join(
223228
defaultJailerPath,
@@ -259,6 +264,8 @@ func TestJail(t *testing.T) {
259264
"--",
260265
"--seccomp-level",
261266
"0",
267+
"--api-sock",
268+
"/run/firecracker.socket",
262269
},
263270
expectedSockPath: filepath.Join(
264271
"/tmp",
@@ -268,6 +275,42 @@ func TestJail(t *testing.T) {
268275
"run",
269276
"firecracker.socket"),
270277
},
278+
{
279+
name: "custom socket path",
280+
socketPath: "api.sock",
281+
jailerCfg: JailerConfig{
282+
ID: "my-test-id",
283+
UID: Int(123),
284+
GID: Int(100),
285+
NumaNode: Int(0),
286+
ChrootStrategy: NewNaiveChrootStrategy("path", "kernel-image-path"),
287+
ExecFile: "/path/to/firecracker",
288+
},
289+
expectedArgs: []string{
290+
defaultJailerBin,
291+
"--id",
292+
"my-test-id",
293+
"--uid",
294+
"123",
295+
"--gid",
296+
"100",
297+
"--exec-file",
298+
"/path/to/firecracker",
299+
"--node",
300+
"0",
301+
"--",
302+
"--seccomp-level",
303+
"0",
304+
"--api-sock",
305+
"api.sock",
306+
},
307+
expectedSockPath: filepath.Join(
308+
defaultJailerPath,
309+
"firecracker",
310+
"my-test-id",
311+
rootfsFolderName,
312+
"api.sock"),
313+
},
271314
}
272315
for _, c := range testCases {
273316
t.Run(c.name, func(t *testing.T) {
@@ -277,8 +320,9 @@ func TestJail(t *testing.T) {
277320
},
278321
}
279322
cfg := &Config{
280-
JailerCfg: &c.jailerCfg,
281-
NetNS: c.netns,
323+
JailerCfg: &c.jailerCfg,
324+
NetNS: c.netns,
325+
SocketPath: c.socketPath,
282326
}
283327
jail(context.Background(), m, cfg)
284328

machine_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ func TestJailerMicroVMExecution(t *testing.T) {
157157
jailerFullRootPath := filepath.Join(jailerTestPath, filepath.Base(getFirecrackerBinaryPath()), id)
158158
os.MkdirAll(jailerTestPath, 0777)
159159

160-
socketPath := filepath.Join(jailerTestPath, "firecracker", "TestJailerMicroVMExecution.socket")
160+
socketPath := "TestJailerMicroVMExecution.socket"
161161
logFifo := filepath.Join(tmpDir, "firecracker.log")
162162
metricsFifo := filepath.Join(tmpDir, "firecracker-metrics")
163163
capturedLog := filepath.Join(tmpDir, "writer.fifo")
@@ -167,7 +167,7 @@ func TestJailerMicroVMExecution(t *testing.T) {
167167
fw.Close()
168168
exec.Command("cp", capturedLog, logPath).Run()
169169
os.Remove(capturedLog)
170-
os.Remove(socketPath)
170+
os.Remove(filepath.Join(jailerTestPath, "firecracker", socketPath))
171171
os.Remove(logFifo)
172172
os.Remove(metricsFifo)
173173
os.RemoveAll(tmpDir)

0 commit comments

Comments
 (0)