Skip to content

Commit 76e2f54

Browse files
committed
godoc: add new and enhance existing documentation
Signed-off-by: Samuel Karp <[email protected]>
1 parent 8b22e08 commit 76e2f54

File tree

5 files changed

+137
-52
lines changed

5 files changed

+137
-52
lines changed

command_builder.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ import (
2222
var defaultFirecrackerVMMCommandBuilder = VMCommandBuilder{}.
2323
WithBin("firecracker")
2424

25-
// VMCommandBuilder is a command builder that builds a command specific
26-
// to the firecracker command using exec.Command.
25+
// VMCommandBuilder is a utility for building an exec.Cmd that represents how to
26+
// start the Firecracker VMM.
2727
type VMCommandBuilder struct {
2828
bin string
2929
args []string

doc.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License"). You may
4+
// not use this file except in compliance with the License. A copy of the
5+
// License is located at
6+
//
7+
// http://aws.amazon.com/apache2.0/
8+
//
9+
// or in the "license" file accompanying this file. This file is distributed
10+
// on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
11+
// express or implied. See the License for the specific language governing
12+
// permissions and limitations under the License.
13+
14+
/*
15+
Package firecracker provides a library to interact with the Firecracker API.
16+
17+
Firecracker is an open-source virtualization technology that is purpose-built
18+
for creating and managing secure, multi-tenant containers and functions-based
19+
services. See https://firecracker-microvm.github.io/ for more details.
20+
21+
This library requires Go 1.11 and can be used with Go modules.
22+
23+
BUG(aws): There are some Firecracker features that are not yet supported by the
24+
SDK. These are tracked as GitHub issues with the firecracker-feature label:
25+
https://github.com/firecracker-microvm/firecracker-go-sdk/issues?q=is%3Aissue+is%3Aopen+label%3Afirecracker-feature
26+
27+
This library is licensed under the Apache 2.0 License.
28+
*/
29+
package firecracker

firecracker.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ import (
1919
"net/http"
2020
"time"
2121

22-
"github.com/sirupsen/logrus"
2322
"github.com/go-openapi/strfmt"
23+
"github.com/sirupsen/logrus"
2424

2525
"github.com/firecracker-microvm/firecracker-go-sdk/client"
2626
models "github.com/firecracker-microvm/firecracker-go-sdk/client/models"
@@ -30,10 +30,12 @@ import (
3030

3131
const firecrackerRequestTimeout = 500 * time.Millisecond
3232

33+
// FirecrackerClient is a client for interacting with the Firecracker API
3334
type FirecrackerClient struct {
3435
client *client.Firecracker
3536
}
3637

38+
// NewFirecrackerClient creates a FirecrackerClient
3739
func NewFirecrackerClient(socketPath string, logger *logrus.Entry, debug bool) *FirecrackerClient {
3840
httpClient := client.NewHTTPClient(strfmt.NewFormats())
3941

machine.go

Lines changed: 95 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ const (
4242
CPUTemplateC3 = models.CPUTemplateC3
4343
)
4444

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.
4747
type Firecracker interface {
4848
PutLogger(ctx context.Context, logger *models.Logger) (*ops.PutLoggerNoContent, error)
4949
PutMachineConfiguration(ctx context.Context, cfg *models.MachineConfiguration) (*ops.PutMachineConfigurationNoContent, error)
@@ -58,27 +58,74 @@ type Firecracker interface {
5858

5959
// Config is a collection of user-configurable VMM settings
6060
type Config struct {
61+
// SocketPath defines the file path where the Firecracker control socket
62+
// should be created.
6163
SocketPath string
6264

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.
73105
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.
75113
NetworkInterfaces []NetworkInterface
76-
VsockDevices []VsockDevice
77-
Console string
78-
Debug bool
79-
machineCfg models.MachineConfiguration
80114

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.
82129
DisableValidation bool
83130
}
84131

@@ -90,21 +137,21 @@ func (cfg *Config) Validate() error {
90137
}
91138

92139
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)
94141
}
95142
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)
97144
}
98145

99146
// Check the non-existence of some files:
100147
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)
102149
}
103150

104151
return nil
105152
}
106153

107-
// Machine is the main object for manipulating firecracker VMs
154+
// Machine is the main object for manipulating Firecracker microVMs
108155
type Machine struct {
109156
cfg Config
110157
client Firecracker
@@ -115,32 +162,41 @@ type Machine struct {
115162

116163
// Logger returns a logrus logger appropriate for logging hypervisor messages
117164
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")
120166
}
121167

122-
// NetworkInterface represents a Firecracker VMs network interface.
168+
// NetworkInterface represents a Firecracker microVM's network interface.
123169
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.
125174
HostDevName string
126-
AllowMDDS bool
175+
// AllowMMDS makes the Firecracker MMDS available on this network interface.
176+
AllowMDDS bool
127177
}
128178

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.
131180
type BlockDevice struct {
181+
// HostPath defines the filesystem path of the block device on the host.
132182
HostPath string
133-
Mode string
183+
// Mode defines whether the device is writable. Valid values are "ro" and
184+
// "rw".
185+
Mode string
134186
}
135187

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.
138190
type VsockDevice struct {
191+
// Path defines the filesystem path of the vsock device on the host.
139192
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
141196
}
142197

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
144200
func (m Machine) socketPath() string {
145201
return m.cfg.SocketPath
146202
}
@@ -155,7 +211,8 @@ func (m Machine) LogLevel() string {
155211
return m.cfg.LogLevel
156212
}
157213

158-
// NewMachine initializes a new Machine instance
214+
// NewMachine initializes a new Machine instance and performs validation of the
215+
// provided Config.
159216
func NewMachine(cfg Config, opts ...Opt) (*Machine, error) {
160217
if err := cfg.Validate(); err != nil {
161218
return nil, err
@@ -288,7 +345,7 @@ func (m *Machine) startVMM(ctx context.Context) (<-chan error, error) {
288345
exitCh <- err
289346
}()
290347

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
292349
vmchan := make(chan error)
293350
sigchan := make(chan os.Signal)
294351
signal.Notify(sigchan, os.Interrupt,
@@ -335,7 +392,7 @@ func (m *Machine) stopVMM() error {
335392
return nil
336393
}
337394

338-
// createFifos sets up the firecracker logging and metrics fifos
395+
// createFifos sets up the firecracker logging and metrics FIFOs
339396
func createFifos(logFifo, metricsFifo string) error {
340397
log.Debugf("Creating FIFO %s", logFifo)
341398
err := syscall.Mkfifo(logFifo, 0700)
@@ -489,7 +546,7 @@ func (m *Machine) addVsock(ctx context.Context, dev VsockDevice) error {
489546
return nil
490547
}
491548

492-
// StartInstance starts the firecracker VM
549+
// StartInstance starts the Firecracker microVM
493550
func (m *Machine) StartInstance(ctx context.Context) error {
494551
return m.startInstance(ctx)
495552
}

opts.go

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,32 +19,29 @@ import (
1919
"github.com/sirupsen/logrus"
2020
)
2121

22-
// Opt represents a functional option to help
23-
// modify functionality of a Machine.
22+
// Opt represents a functional option to help modify functionality of a Machine.
2423
type Opt func(*Machine)
2524

26-
// WithClient will use the client in place rather
27-
// than the client constructed during bootstrapping of
28-
// the machine. This option is useful for mocking out
25+
// WithClient will use the client in place rather than the client constructed
26+
// during bootstrapping of the machine. This option is useful for mocking out
2927
// tests.
3028
func WithClient(client Firecracker) Opt {
3129
return func(machine *Machine) {
3230
machine.client = client
3331
}
3432
}
3533

36-
// WithLogger will allow for the Machine to use
37-
// the provided logger.
34+
// WithLogger will allow for the Machine to use the provided logger.
3835
func WithLogger(logger *logrus.Entry) Opt {
3936
return func(machine *Machine) {
4037
machine.logger = logger
4138
}
4239
}
4340

44-
// WithProcessRunner will allow for a specific command
45-
// to be run instead of the default firecracker command.
46-
// For example, this could be used to instead call the
47-
// jailer instead of firecracker directly.
41+
// WithProcessRunner will allow for a specific command to be run instead of the
42+
// default firecracker command.
43+
// For example, this could be used to instead call the jailer instead of
44+
// firecracker directly.
4845
func WithProcessRunner(cmd *exec.Cmd) Opt {
4946
return func(machine *Machine) {
5047
machine.cmd = cmd

0 commit comments

Comments
 (0)