Skip to content

Commit 8b05434

Browse files
authored
Merge pull request #442 from kzys/add-id
Make Firecracker's instance ID configurable
2 parents 901dd61 + 39e0475 commit 8b05434

File tree

4 files changed

+10
-7
lines changed

4 files changed

+10
-7
lines changed

runtime/integ_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ func writeRuntimeConfig(options ...func(*config.Config)) error {
9393
return nil
9494
}
9595

96-
var testNameToVMIDReplacer = strings.NewReplacer("/", "_")
96+
var testNameToVMIDReplacer = strings.NewReplacer("/", "-", "_", "-")
9797

9898
func testNameToVMID(s string) string {
9999
return testNameToVMIDReplacer.Replace(s)

runtime/noop_jailer.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ func newNoopJailer(ctx context.Context, logger *logrus.Entry, shimDir vm.Dir) *n
4444
}
4545
}
4646

47-
func (j *noopJailer) BuildJailedMachine(cfg *config.Config, machineConfig *firecracker.Config, vmID string) ([]firecracker.Opt, error) {
47+
func (j *noopJailer) BuildJailedMachine(cfg *config.Config, _ *firecracker.Config, vmID string) ([]firecracker.Opt, error) {
4848
if len(cfg.FirecrackerBinaryPath) == 0 {
4949
return []firecracker.Opt{}, nil
5050
}
@@ -57,6 +57,7 @@ func (j *noopJailer) BuildJailedMachine(cfg *config.Config, machineConfig *firec
5757
cmd := firecracker.VMCommandBuilder{}.
5858
WithBin(cfg.FirecrackerBinaryPath).
5959
WithSocketPath(relSocketPath).
60+
WithArgs([]string{"--id", vmID}).
6061
Build(j.ctx)
6162

6263
if cfg.DebugHelper.LogFirecrackerOutput() {

runtime/runc_jailer.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -451,6 +451,7 @@ func (j *runcJailer) setDefaultConfigValues(cfg *config.Config, socketPath strin
451451
cmd := firecracker.VMCommandBuilder{}.
452452
WithBin("/" + firecrackerFileName).
453453
WithSocketPath(socketPath).
454+
WithArgs([]string{"--id", j.vmID}).
454455
// Don't need to pass in an actual context here as we are only building
455456
// the command arguments and not actually building a command
456457
Build(context.Background())

runtime/service_integ_test.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -579,13 +579,14 @@ func TestLongUnixSocketPath_Isolated(t *testing.T) {
579579
// Verify that if the absolute path of the Firecracker unix sockets are longer
580580
// than the max length enforced by the kernel (UNIX_PATH_MAX, usually 108), we
581581
// don't fail (due to the internal implementation using relative paths).
582-
// We do this by using the max VMID len (76 chars), which in combination with the
582+
// We do this by using the max VMID len (64 chars), which in combination with the
583583
// default location we store state results in a path like
584-
// "/run/firecracker-containerd/default/<vmID>" (with len 112).
584+
// "/run/firecracker-containerd/<namespace>/<vmID>" (with len 112).
585585
const maxUnixSockLen = 108
586-
vmID := strings.Repeat("x", 76)
586+
namespace := strings.Repeat("n", 20)
587+
vmID := strings.Repeat("v", 64)
587588

588-
ctx := namespaces.WithNamespace(context.Background(), "default")
589+
ctx := namespaces.WithNamespace(context.Background(), namespace)
589590

590591
pluginClient, err := ttrpcutil.NewClient(containerdSockPath + ".ttrpc")
591592
require.NoError(t, err, "failed to create ttrpc client")
@@ -624,7 +625,7 @@ func TestLongUnixSocketPath_Isolated(t *testing.T) {
624625

625626
// double-check that the sockets are at the expected path and that their absolute
626627
// length exceeds 108 bytes
627-
shimDir, err := vm.ShimDir(cfg.ShimBaseDir, "default", vmID)
628+
shimDir, err := vm.ShimDir(cfg.ShimBaseDir, namespace, vmID)
628629
require.NoError(t, err, "failed to get shim dir")
629630

630631
if request.JailerConfig == nil {

0 commit comments

Comments
 (0)