Skip to content

Commit 284a2d0

Browse files
committed
Override Process.Args regardless of the existing value
Previously firecracker-containerd keeps /etc/containerd/firecracker-runc-config.json's Process.Args as is if the value exists. However passing VM ID (39e0475) doesn't work when it uses the exising fixed value. This change removes this confusing behavior and always overrides Process.Args. Signed-off-by: Kazuyoshi Kato <[email protected]>
1 parent f8f9585 commit 284a2d0

File tree

1 file changed

+13
-16
lines changed

1 file changed

+13
-16
lines changed

runtime/runc_jailer.go

Lines changed: 13 additions & 16 deletions
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")

0 commit comments

Comments
 (0)