Skip to content

Commit 056fce3

Browse files
authored
Merge pull request #459 from kzys/runc-args
Override Process.Args regardless of the existing value
2 parents f8f9585 + 3a1c474 commit 056fce3

File tree

2 files changed

+16
-19
lines changed

2 files changed

+16
-19
lines changed

runtime/runc_jailer.go

+13-16
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ func (j *runcJailer) BuildJailedRootHandler(cfg *config.Config, machineConfig *f
258258
j.logger.Debugf("Writing %q for runc", rootPathToConfig)
259259
// we pass m.Cfg as opposed to machineConfig as we want the populated
260260
// config defaults when calling NewMachine
261-
if err := j.overwriteConfig(cfg, &m.Cfg, filepath.Base(m.Cfg.SocketPath), rootPathToConfig); err != nil {
261+
if err := j.overwriteConfig(&m.Cfg, filepath.Base(m.Cfg.SocketPath), rootPathToConfig); err != nil {
262262
return errors.Wrap(err, "failed to overwrite config.json")
263263
}
264264

@@ -478,7 +478,7 @@ func (j *runcJailer) jailerCommand(containerName string, isDebug bool) *exec.Cmd
478478
}
479479

480480
// overwriteConfig will set the proper default values if a field had not been set.
481-
func (j *runcJailer) overwriteConfig(cfg *config.Config, machineConfig *firecracker.Config, socketPath, configPath string) error {
481+
func (j *runcJailer) overwriteConfig(machineConfig *firecracker.Config, socketPath, configPath string) error {
482482
spec := j.configSpec
483483
if spec.Process.User.UID != 0 ||
484484
spec.Process.User.GID != 0 {
@@ -489,7 +489,7 @@ func (j *runcJailer) overwriteConfig(cfg *config.Config, machineConfig *firecrac
489489
)
490490
}
491491

492-
spec = j.setDefaultConfigValues(cfg, socketPath, spec)
492+
spec = j.setDefaultConfigValues(socketPath, spec)
493493
spec.Root.Path = rootfsFolder
494494
spec.Root.Readonly = false
495495
spec.Process.User.UID = j.Config.UID
@@ -537,24 +537,21 @@ func (j runcJailer) CgroupPath() string {
537537
return filepath.Join(basePath, j.vmID)
538538
}
539539

540-
// setDefaultConfigValues will process the spec file provided and allow any
541-
// empty/zero values to be replaced with default values.
542-
func (j *runcJailer) setDefaultConfigValues(cfg *config.Config, socketPath string, spec specs.Spec) specs.Spec {
540+
// setDefaultConfigValues will override the spec to start Firecracker inside.
541+
func (j *runcJailer) setDefaultConfigValues(socketPath string, spec specs.Spec) specs.Spec {
543542
if spec.Process == nil {
544543
spec.Process = &specs.Process{}
545544
}
546545

547-
if spec.Process.Args == nil {
548-
cmd := firecracker.VMCommandBuilder{}.
549-
WithBin("/" + firecrackerFileName).
550-
WithSocketPath(socketPath).
551-
WithArgs([]string{"--id", j.vmID}).
552-
// Don't need to pass in an actual context here as we are only building
553-
// the command arguments and not actually building a command
554-
Build(context.Background())
546+
cmd := firecracker.VMCommandBuilder{}.
547+
WithBin("/" + firecrackerFileName).
548+
WithSocketPath(socketPath).
549+
WithArgs([]string{"--id", j.vmID}).
550+
// Don't need to pass in an actual context here as we are only building
551+
// the command arguments and not actually building a command
552+
Build(context.Background())
555553

556-
spec.Process.Args = cmd.Args
557-
}
554+
spec.Process.Args = cmd.Args
558555

559556
cgroupPath := j.CgroupPath()
560557
j.logger.WithField("CgroupPath", cgroupPath).Debug("using cgroup path")

runtime/service_integ_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -1602,13 +1602,13 @@ func TestStopVM_Isolated(t *testing.T) {
16021602

16031603
t.Run(test.name, func(t *testing.T) {
16041604
req := test.createVMRequest
1605-
req.VMID = testNameToVMID(test.name)
1605+
req.VMID = testNameToVMID(t.Name())
16061606
testFunc(t, req)
16071607
})
16081608

16091609
t.Run(test.name+"/Jailer", func(t *testing.T) {
16101610
req := test.createVMRequest
1611-
req.VMID = testNameToVMID(test.name) + "_Jailer"
1611+
req.VMID = testNameToVMID(t.Name())
16121612
req.JailerConfig = &proto.JailerConfig{
16131613
UID: 300000,
16141614
GID: 300000,
@@ -2007,7 +2007,7 @@ func TestCreateVM_Isolated(t *testing.T) {
20072007
UID: 30000,
20082008
GID: 30000,
20092009
}
2010-
t.Run(subtest.name+" with Jailer", func(t *testing.T) {
2010+
t.Run(subtest.name+"/Jailer", func(t *testing.T) {
20112011
runTest(t, requestWithJailer, validate)
20122012
})
20132013
}

0 commit comments

Comments
 (0)