Skip to content

Commit

Permalink
fix: Match Firecracker 1.0.0 API (#385)
Browse files Browse the repository at this point in the history
I left the AllowMMDSRequests on our side of API, because it think it
makes sense to specify per interface, and under the hood, the
Firecracker provider knows how to handle it.

Fixes #384
  • Loading branch information
yitsushi authored Feb 7, 2022
1 parent 33f2d49 commit 101e1d5
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 17 deletions.
19 changes: 14 additions & 5 deletions infrastructure/firecracker/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func WithMicroVM(vm *models.MicroVM) ConfigOption {
cfg.MachineConfig = MachineConfig{
MemSizeMib: vm.Spec.MemoryInMb,
VcpuCount: vm.Spec.VCPU,
HTEnabled: false,
SMT: false,
}

cfg.NetDevices = []NetworkInterfaceConfig{}
Expand Down Expand Up @@ -115,6 +115,16 @@ func WithMicroVM(vm *models.MicroVM) ConfigOption {
cfg.BootSource.InitrdPath = &initrdPath
}

cfg.Mmds = &MMDSConfig{
NetworkInterfaces: []string{},
}

for _, iface := range vm.Spec.NetworkInterfaces {
if iface.AllowMetadataRequests {
cfg.Mmds.NetworkInterfaces = append(cfg.Mmds.NetworkInterfaces, iface.GuestDeviceName)
}
}

return nil
}
}
Expand Down Expand Up @@ -182,10 +192,9 @@ func createNetworkIface(iface *models.NetworkInterface, status *models.NetworkIn
}

netInt := &NetworkInterfaceConfig{
IfaceID: iface.GuestDeviceName,
HostDevName: hostDevName,
GuestMAC: macAddr,
AllowMMDSRequests: iface.AllowMetadataRequests,
IfaceID: iface.GuestDeviceName,
HostDevName: hostDevName,
GuestMAC: macAddr,
}

return netInt
Expand Down
15 changes: 11 additions & 4 deletions infrastructure/firecracker/testdata/vm_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,20 @@
"machine-config": {
"vcpu_count": 2,
"mem_size_mib": 1024,
"ht_enabled": false,
"smt": false,
"track_dirty_pages": false
},
"balloon": null,
"network-interfaces": [],
"network-interfaces": [
{
"iface_id": "mdms1",
"host_dev_name": "tap0"
}
],
"mmds-config": {
"network_interfaces": ["mdms1"]
},
"vsock": null,
"logger": null,
"metrics": null,
"mmds-config": null
"metrics": null
}
14 changes: 6 additions & 8 deletions infrastructure/firecracker/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ type MachineConfig struct {
VcpuCount int64 `json:"vcpu_count"`
// MemSizeMib is the memory size in MiB.
MemSizeMib int64 `json:"mem_size_mib"`
// HTEnabled enables or disabled hyperthreading.
HTEnabled bool `json:"ht_enabled"`
// SMT enables or disabled hyperthreading.
SMT bool `json:"smt"`
// CPUTemplate is a CPU template that it is used to filter the CPU features exposed to the guest.
CPUTemplate *string `json:"cpu_template,omitempty"`
// TrackDirtyPages enables or disables dirty page tracking. Enabling allows incremental snapshots.
Expand Down Expand Up @@ -103,12 +103,6 @@ type NetworkInterfaceConfig struct {
HostDevName string `json:"host_dev_name"`
// GuestMAC is the mac address to use.
GuestMAC string `json:"guest_mac,omitempty"`
// AllowMMDSRequests is true the device model will reply to HTTP GET
// requests sent to the MMDS address via this interface. In this case,
// both ARP requests for `169.254.169.254` and TCP segments heading to the
// same address are intercepted by the device model, and do not reach
// the associated TAP device.
AllowMMDSRequests bool `json:"allow_mmds_requests"`
// RxRateLimiter is the rate limiter for received packages.
// RxRateLimiter *RateLimiterConfig `json:"rx_rate_limiter,omitempty"`
// TxRateLimiter is the rate limiter for transmitted packages.
Expand Down Expand Up @@ -149,6 +143,10 @@ type MetricsConfig struct {
type MMDSConfig struct {
// IPV4Address is the MMDS IPv4 configured address.
IPV4Address *string `json:"ipv4_address,omitempty"`
// NetworkInterfaces that has access to the metadata service.
NetworkInterfaces []string `json:"network_interfaces"`
// Version of the MMDS.
Version *string `json:"version,omitempty"`
}

type VsockDeviceConfig struct {
Expand Down

0 comments on commit 101e1d5

Please sign in to comment.