@@ -42,8 +42,8 @@ const (
42
42
CPUTemplateC3 = models .CPUTemplateC3
43
43
)
44
44
45
- // Firecracker is an interface that can be used to mock
46
- // out an Firecracker agent for testing purposes.
45
+ // Firecracker is an interface that can be used to mock out a Firecracker agent
46
+ // for testing purposes.
47
47
type Firecracker interface {
48
48
PutLogger (ctx context.Context , logger * models.Logger ) (* ops.PutLoggerNoContent , error )
49
49
PutMachineConfiguration (ctx context.Context , cfg * models.MachineConfiguration ) (* ops.PutMachineConfigurationNoContent , error )
@@ -58,27 +58,74 @@ type Firecracker interface {
58
58
59
59
// Config is a collection of user-configurable VMM settings
60
60
type Config struct {
61
+ // SocketPath defines the file path where the Firecracker control socket
62
+ // should be created.
61
63
SocketPath string
62
64
63
- LogFifo string
64
- LogLevel string
65
- MetricsFifo string
66
- KernelImagePath string
67
- KernelArgs string
68
- CPUCount int64
69
- HtEnabled bool
70
- CPUTemplate CPUTemplate
71
- MemInMiB int64
72
- RootDrive BlockDevice
65
+ // LogFifo defines the file path where the Firecracker log named-pipe should
66
+ // be located.
67
+ LogFifo string
68
+
69
+ // LogLevel defines the verbosity of Firecracker logging. Valid values are
70
+ // "Error", "Warning", "Info", and "Debug", and are case-sensitive.
71
+ LogLevel string
72
+
73
+ // MetricsFifo defines the file path where the Firecracker metrics
74
+ // named-pipe should be located.
75
+ MetricsFifo string
76
+
77
+ // KernelImagePath defines the file path where the kernel image is located.
78
+ // The kernel image must be an uncompressed ELF image.
79
+ KernelImagePath string
80
+
81
+ // KernelArgs defines the command-line arguments that should be passed to
82
+ // the kernel.
83
+ KernelArgs string
84
+
85
+ // CPUCount defines the number of CPU threads that should be available to
86
+ // the micro-VM.
87
+ CPUCount int64
88
+
89
+ // HtEnabled defines whether hyper-threading should be enabled for the
90
+ // microVM.
91
+ HtEnabled bool
92
+
93
+ // CPUTemplate defines the Firecracker CPU template to use. Valid values
94
+ // are CPUTemplateT2 and CPUTemplateC3,
95
+ CPUTemplate CPUTemplate
96
+
97
+ // MemInMiB defines the amount of memory that should be made available to
98
+ // the microVM.
99
+ MemInMiB int64
100
+
101
+ // RootDrive specifies the BlockDevice that contains the root filesystem.
102
+ RootDrive BlockDevice
103
+
104
+ // RootPartitionUUID defines the UUID that specifies the root partition.
73
105
RootPartitionUUID string
74
- AdditionalDrives []BlockDevice
106
+
107
+ // AdditionalDrives specifies additional BlockDevices that should be made
108
+ // available to the microVM.
109
+ AdditionalDrives []BlockDevice
110
+
111
+ // NetworkInterfaces specifies the tap devices that should be made available
112
+ // to the microVM.
75
113
NetworkInterfaces []NetworkInterface
76
- VsockDevices []VsockDevice
77
- Console string
78
- Debug bool
79
- machineCfg models.MachineConfiguration
80
114
81
- // Allows for easier mock testing
115
+ // VsockDevices specifies the vsock devices that should be made available to
116
+ // the microVM.
117
+ VsockDevices []VsockDevice
118
+
119
+ // Console is a deprecated field.
120
+ // Deprecated: This field should not be used and will be removed.
121
+ Console string
122
+
123
+ // Debug enables debug-level logging for the SDK.
124
+ Debug bool
125
+ machineCfg models.MachineConfiguration
126
+
127
+ // DisableValidation allows for easier mock testing by disabling the
128
+ // validation of configuration performed by the SDK.
82
129
DisableValidation bool
83
130
}
84
131
@@ -90,21 +137,21 @@ func (cfg *Config) Validate() error {
90
137
}
91
138
92
139
if _ , err := os .Stat (cfg .KernelImagePath ); err != nil {
93
- return fmt .Errorf ("Failed to stat kernal image path, %q: %v" , cfg .KernelImagePath , err )
140
+ return fmt .Errorf ("failed to stat kernal image path, %q: %v" , cfg .KernelImagePath , err )
94
141
}
95
142
if _ , err := os .Stat (cfg .RootDrive .HostPath ); err != nil {
96
- return fmt .Errorf ("Failed to stat host path, %q: %v" , cfg .RootDrive .HostPath , err )
143
+ return fmt .Errorf ("failed to stat host path, %q: %v" , cfg .RootDrive .HostPath , err )
97
144
}
98
145
99
146
// Check the non-existence of some files:
100
147
if _ , err := os .Stat (cfg .SocketPath ); err == nil {
101
- return fmt .Errorf ("Socket %s already exists" , cfg .SocketPath )
148
+ return fmt .Errorf ("socket %s already exists" , cfg .SocketPath )
102
149
}
103
150
104
151
return nil
105
152
}
106
153
107
- // Machine is the main object for manipulating firecracker VMs
154
+ // Machine is the main object for manipulating Firecracker microVMs
108
155
type Machine struct {
109
156
cfg Config
110
157
client Firecracker
@@ -115,32 +162,41 @@ type Machine struct {
115
162
116
163
// Logger returns a logrus logger appropriate for logging hypervisor messages
117
164
func (m * Machine ) Logger () * log.Entry {
118
- // return m.logger.WithField("subsystem", "firecracker-go-sdk")
119
- return m .logger
165
+ return m .logger .WithField ("subsystem" , "firecracker-go-sdk" )
120
166
}
121
167
122
- // NetworkInterface represents a Firecracker VMs network interface.
168
+ // NetworkInterface represents a Firecracker microVM's network interface.
123
169
type NetworkInterface struct {
124
- MacAddress string
170
+ // MacAddress defines the MAC address that should be assigned to the network
171
+ // interface inside the microVM.
172
+ MacAddress string
173
+ // HostDevName defines the file path of the tap device on the host.
125
174
HostDevName string
126
- AllowMDDS bool
175
+ // AllowMMDS makes the Firecracker MMDS available on this network interface.
176
+ AllowMDDS bool
127
177
}
128
178
129
- // BlockDevice represents a host block device mapped to the firecracker VM.
130
- // mode is either "ro" or "rw"
179
+ // BlockDevice represents a host block device mapped to the Firecracker microVM.
131
180
type BlockDevice struct {
181
+ // HostPath defines the filesystem path of the block device on the host.
132
182
HostPath string
133
- Mode string
183
+ // Mode defines whether the device is writable. Valid values are "ro" and
184
+ // "rw".
185
+ Mode string
134
186
}
135
187
136
- // VsockDevice represents a vsock connection between the
137
- // host and the guest VM .
188
+ // VsockDevice represents a vsock connection between the host and the guest
189
+ // microVM .
138
190
type VsockDevice struct {
191
+ // Path defines the filesystem path of the vsock device on the host.
139
192
Path string
140
- CID uint32
193
+ // CID defines the 32-bit Context Identifier for the vsock device. See
194
+ // the vsock(7) manual page for more information.
195
+ CID uint32
141
196
}
142
197
143
- // SocketPath returns the filesystem path to the socket used for VMM communication
198
+ // SocketPath returns the filesystem path to the socket used for VMM
199
+ // communication
144
200
func (m Machine ) socketPath () string {
145
201
return m .cfg .SocketPath
146
202
}
@@ -155,7 +211,8 @@ func (m Machine) LogLevel() string {
155
211
return m .cfg .LogLevel
156
212
}
157
213
158
- // NewMachine initializes a new Machine instance
214
+ // NewMachine initializes a new Machine instance and performs validation of the
215
+ // provided Config.
159
216
func NewMachine (cfg Config , opts ... Opt ) (* Machine , error ) {
160
217
if err := cfg .Validate (); err != nil {
161
218
return nil , err
@@ -288,7 +345,7 @@ func (m *Machine) startVMM(ctx context.Context) (<-chan error, error) {
288
345
exitCh <- err
289
346
}()
290
347
291
- // Set up a signal hander and pass INT, QUIT, and TERM through to firecracker
348
+ // Set up a signal handler and pass INT, QUIT, and TERM through to firecracker
292
349
vmchan := make (chan error )
293
350
sigchan := make (chan os.Signal )
294
351
signal .Notify (sigchan , os .Interrupt ,
@@ -335,7 +392,7 @@ func (m *Machine) stopVMM() error {
335
392
return nil
336
393
}
337
394
338
- // createFifos sets up the firecracker logging and metrics fifos
395
+ // createFifos sets up the firecracker logging and metrics FIFOs
339
396
func createFifos (logFifo , metricsFifo string ) error {
340
397
log .Debugf ("Creating FIFO %s" , logFifo )
341
398
err := syscall .Mkfifo (logFifo , 0700 )
@@ -489,7 +546,7 @@ func (m *Machine) addVsock(ctx context.Context, dev VsockDevice) error {
489
546
return nil
490
547
}
491
548
492
- // StartInstance starts the firecracker VM
549
+ // StartInstance starts the Firecracker microVM
493
550
func (m * Machine ) StartInstance (ctx context.Context ) error {
494
551
return m .startInstance (ctx )
495
552
}
0 commit comments