-
Notifications
You must be signed in to change notification settings - Fork 228
[WIP] feat: expose mmds #304
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -185,7 +185,8 @@ type VMSpec struct { | |
// Specifying a path in SSH.Generate means "use this public key" | ||
// If SSH.PublicKey is set, this struct will marshal as a string using that path | ||
// If SSH.Generate is set, this struct will marshal as a bool => true | ||
SSH *SSH `json:"ssh,omitempty"` | ||
SSH *SSH `json:"ssh,omitempty"` | ||
Metadata string `json:"metadata,omitempty"` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. would |
||
} | ||
|
||
type VMImageSpec struct { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,12 +22,15 @@ import ( | |
// ExecuteFirecracker executes the firecracker process using the Go SDK | ||
func ExecuteFirecracker(vm *api.VM, dhcpIfaces []DHCPInterface) error { | ||
drivePath := vm.SnapshotDev() | ||
mmdsData := os.Getenv("FC_META") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. cleanup; take from vm spec |
||
enableMmds := mmdsData != "" | ||
|
||
networkInterfaces := make([]firecracker.NetworkInterface, 0, len(dhcpIfaces)) | ||
for _, dhcpIface := range dhcpIfaces { | ||
networkInterfaces = append(networkInterfaces, firecracker.NetworkInterface{ | ||
MacAddress: dhcpIface.MACFilter, | ||
HostDevName: dhcpIface.VMTAP, | ||
AllowMMDS: enableMmds, | ||
}) | ||
} | ||
|
||
|
@@ -83,6 +86,12 @@ func ExecuteFirecracker(vm *api.VM, dhcpIfaces []DHCPInterface) error { | |
// TODO: We could use /dev/null, but firecracker-go-sdk issues Mkfifo which collides with the existing device | ||
LogFifo: logSocketPath, | ||
MetricsFifo: metricsSocketPath, | ||
VsockDevices: []firecracker.VsockDevice{ | ||
{ | ||
CID: 3, | ||
Path: "vsock", | ||
}, | ||
}, | ||
} | ||
|
||
// Add the volumes to the VM | ||
|
@@ -119,19 +128,23 @@ func ExecuteFirecracker(vm *api.VM, dhcpIfaces []DHCPInterface) error { | |
m, err := firecracker.NewMachine(ctx, cfg, firecracker.WithProcessRunner(cmd)) | ||
if err != nil { | ||
return fmt.Errorf("failed to create machine: %s", err) | ||
} | ||
|
||
//defer os.Remove(cfg.SocketPath) | ||
|
||
//if opts.validMetadata != nil { | ||
// m.EnableMetadata(opts.validMetadata) | ||
//} | ||
} | ||
|
||
if err := m.Start(ctx); err != nil { | ||
return fmt.Errorf("failed to start machine: %v", err) | ||
} | ||
defer m.StopVMM() | ||
|
||
if enableMmds { | ||
//cfg.KernelArgs = fmt.Sprintf("%s -device vhost-vsock-pci,id=vhost-vsock-pci0,guest-cid=3") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. cleanup |
||
if err := m.SetMetadata(ctx, mmdsData); err != nil { | ||
return fmt.Errorf("failed to PUT metadata to MMDS: %v", err) | ||
} | ||
} | ||
|
||
//defer os.Remove(cfg.SocketPath) | ||
|
||
defer m.StopVMM() | ||
installSignalHandlers(ctx, m) | ||
|
||
// wait for the VMM to exit | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -49,6 +49,7 @@ func StartVM(vm *api.VM, debug bool) error { | |
config := &runtime.ContainerConfig{ | ||
Cmd: []string{fmt.Sprintf("--log-level=%s", logs.Logger.Level.String()), vm.GetUID().String()}, | ||
Labels: map[string]string{"ignite.name": vm.GetName()}, | ||
Env: []string{fmt.Sprintf("FC_META=%s", vm.Spec.Metadata)}, | ||
Binds: []*runtime.Bind{ | ||
{ | ||
HostPath: vmDir, | ||
|
@@ -74,6 +75,8 @@ func StartVM(vm *api.VM, debug bool) error { | |
runtime.BindBoth("/dev/net/tun"), // Needed for creating TAP adapters | ||
runtime.BindBoth("/dev/kvm"), // Pass through virtualization support | ||
runtime.BindBoth(vm.SnapshotDev()), // The block device to boot from | ||
runtime.BindBoth("/dev/vhost-vsock"), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. only if metadata is present? |
||
runtime.BindBoth("/dev/vsock"), | ||
}, | ||
StopTimeout: constants.STOP_TIMEOUT + constants.IGNITE_TIMEOUT, | ||
PortBindings: vm.Spec.Network.Ports, // Add the port mappings to Docker | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -127,12 +127,12 @@ func (dc *dockerClient) RunContainer(image string, config *runtime.ContainerConf | |
} | ||
|
||
stopTimeout := int(config.StopTimeout) | ||
|
||
c, err := dc.client.ContainerCreate(context.Background(), &container.Config{ | ||
Hostname: config.Hostname, | ||
Tty: true, // --tty | ||
OpenStdin: true, // --interactive | ||
Cmd: config.Cmd, | ||
Env: config.Env, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Cleanup later? |
||
Image: image, | ||
Labels: config.Labels, | ||
StopTimeout: &stopTimeout, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We'd also want to point this to a file; and use that content instead of requiring the JSON to be inline.