diff --git a/vendor/github.com/firecracker-microvm/firecracker-go-sdk/.gitignore b/vendor/github.com/firecracker-microvm/firecracker-go-sdk/.gitignore index a1d69f27f..0dc13c5cc 100644 --- a/vendor/github.com/firecracker-microvm/firecracker-go-sdk/.gitignore +++ b/vendor/github.com/firecracker-microvm/firecracker-go-sdk/.gitignore @@ -1,3 +1,4 @@ firecracker +jailer firecracker-* vmlinux diff --git a/vendor/github.com/firecracker-microvm/firecracker-go-sdk/CHANGELOG.md b/vendor/github.com/firecracker-microvm/firecracker-go-sdk/CHANGELOG.md index 3b2af6f20..335294eb7 100644 --- a/vendor/github.com/firecracker-microvm/firecracker-go-sdk/CHANGELOG.md +++ b/vendor/github.com/firecracker-microvm/firecracker-go-sdk/CHANGELOG.md @@ -1,3 +1,11 @@ +# [ Unreleased ] + +* Fixes a bug where fifos were not working properly with jailer enabled (#96) +* Fixes bug where context was not being used at all during startVM (#86) +* Updates the jailer's socket path to point to the unix socket in the jailer's workspace (#86) +* Fixes bug where default socketpath would always be used when not using jailer (#84). +* Update for compatibility with Firecracker 0.17.x + # 0.15.1 * Add the machine.Shutdown() method, enabling access to the SendCtrlAltDel API diff --git a/vendor/github.com/firecracker-microvm/firecracker-go-sdk/README.md b/vendor/github.com/firecracker-microvm/firecracker-go-sdk/README.md index 214cf6809..b931c863b 100644 --- a/vendor/github.com/firecracker-microvm/firecracker-go-sdk/README.md +++ b/vendor/github.com/firecracker-microvm/firecracker-go-sdk/README.md @@ -1,7 +1,7 @@ A basic Go interface to the Firecracker API ==== -[![Build status](https://badge.buildkite.com/de08ca676829bedbf6de040c2c2ba1a5d2892e220997c2abdd.svg)](https://buildkite.com/firecracker-microvm/firecracker-go-sdk) +[![Build status](https://badge.buildkite.com/de08ca676829bedbf6de040c2c2ba1a5d2892e220997c2abdd.svg?branch=master)](https://buildkite.com/firecracker-microvm/firecracker-go-sdk) This package is a Go library to interact with the Firecracker API. It is designed as an abstraction of the OpenAPI-generated client that @@ -38,6 +38,21 @@ Firecracker, by design, only supports Linux tap devices. The SDK provides facilities to attach a tap device to the Firecracker VM, but the client is responsible for further configuration. +Questions? +--- + +Please use +[GitHub issues](https://github.com/firecracker-microvm/firecracker-go-sdk/issues) +to report problems, discuss roadmap items, or make feature requests. + +If you've discovered an issue that may have security implications to +users or developers of this software, please do not report it using +GitHub issues, but instead follow +[Firecracker's security reporting guidelines](https://github.com/firecracker-microvm/firecracker/blob/master/SECURITY-POLICY.md). + +Other discussion: For general discussion, please join us in the +`#general` channel on the [Firecracker Slack](https://tinyurl.com/firecracker-microvm). + License ==== diff --git a/vendor/github.com/firecracker-microvm/firecracker-go-sdk/client/models/instance_action_info.go b/vendor/github.com/firecracker-microvm/firecracker-go-sdk/client/models/instance_action_info.go index fcc0f3355..c8fece6a1 100644 --- a/vendor/github.com/firecracker-microvm/firecracker-go-sdk/client/models/instance_action_info.go +++ b/vendor/github.com/firecracker-microvm/firecracker-go-sdk/client/models/instance_action_info.go @@ -34,9 +34,8 @@ type InstanceActionInfo struct { // Enumeration indicating what type of action is contained in the payload // Required: true - // Read Only: true // Enum: [BlockDeviceRescan FlushMetrics InstanceStart SendCtrlAltDel] - ActionType string `json:"action_type"` + ActionType *string `json:"action_type"` // payload Payload string `json:"payload,omitempty"` @@ -93,12 +92,12 @@ func (m *InstanceActionInfo) validateActionTypeEnum(path, location string, value func (m *InstanceActionInfo) validateActionType(formats strfmt.Registry) error { - if err := validate.RequiredString("action_type", "body", string(m.ActionType)); err != nil { + if err := validate.Required("action_type", "body", m.ActionType); err != nil { return err } // value enum - if err := m.validateActionTypeEnum("action_type", "body", m.ActionType); err != nil { + if err := m.validateActionTypeEnum("action_type", "body", *m.ActionType); err != nil { return err } diff --git a/vendor/github.com/firecracker-microvm/firecracker-go-sdk/client/models/instance_info.go b/vendor/github.com/firecracker-microvm/firecracker-go-sdk/client/models/instance_info.go index 2dca401ca..85d71102e 100644 --- a/vendor/github.com/firecracker-microvm/firecracker-go-sdk/client/models/instance_info.go +++ b/vendor/github.com/firecracker-microvm/firecracker-go-sdk/client/models/instance_info.go @@ -34,19 +34,16 @@ type InstanceInfo struct { // MicroVM / instance ID. // Required: true - // Read Only: true - ID string `json:"id"` + ID *string `json:"id"` // The current detailed state of the Firecracker instance. This value is read-only for the control-plane. // Required: true - // Read Only: true // Enum: [Uninitialized Starting Running Halting Halted] - State string `json:"state"` + State *string `json:"state"` // MicroVM hypervisor build version. // Required: true - // Read Only: true - VmmVersion string `json:"vmm_version"` + VmmVersion *string `json:"vmm_version"` } // Validate validates this instance info @@ -73,7 +70,7 @@ func (m *InstanceInfo) Validate(formats strfmt.Registry) error { func (m *InstanceInfo) validateID(formats strfmt.Registry) error { - if err := validate.RequiredString("id", "body", string(m.ID)); err != nil { + if err := validate.Required("id", "body", m.ID); err != nil { return err } @@ -120,12 +117,12 @@ func (m *InstanceInfo) validateStateEnum(path, location string, value string) er func (m *InstanceInfo) validateState(formats strfmt.Registry) error { - if err := validate.RequiredString("state", "body", string(m.State)); err != nil { + if err := validate.Required("state", "body", m.State); err != nil { return err } // value enum - if err := m.validateStateEnum("state", "body", m.State); err != nil { + if err := m.validateStateEnum("state", "body", *m.State); err != nil { return err } @@ -134,7 +131,7 @@ func (m *InstanceInfo) validateState(formats strfmt.Registry) error { func (m *InstanceInfo) validateVmmVersion(formats strfmt.Registry) error { - if err := validate.RequiredString("vmm_version", "body", string(m.VmmVersion)); err != nil { + if err := validate.Required("vmm_version", "body", m.VmmVersion); err != nil { return err } diff --git a/vendor/github.com/firecracker-microvm/firecracker-go-sdk/client/models/machine_configuration.go b/vendor/github.com/firecracker-microvm/firecracker-go-sdk/client/models/machine_configuration.go index 908ced476..a4f939e82 100644 --- a/vendor/github.com/firecracker-microvm/firecracker-go-sdk/client/models/machine_configuration.go +++ b/vendor/github.com/firecracker-microvm/firecracker-go-sdk/client/models/machine_configuration.go @@ -34,15 +34,18 @@ type MachineConfiguration struct { CPUTemplate CPUTemplate `json:"cpu_template,omitempty"` // Flag for enabling/disabling Hyperthreading - HtEnabled bool `json:"ht_enabled,omitempty"` + // Required: true + HtEnabled *bool `json:"ht_enabled"` // Memory size of VM - MemSizeMib int64 `json:"mem_size_mib,omitempty"` + // Required: true + MemSizeMib *int64 `json:"mem_size_mib"` // Number of vCPUs (either 1 or an even number) + // Required: true // Maximum: 32 // Minimum: 1 - VcpuCount int64 `json:"vcpu_count,omitempty"` + VcpuCount *int64 `json:"vcpu_count"` } // Validate validates this machine configuration @@ -53,6 +56,14 @@ func (m *MachineConfiguration) Validate(formats strfmt.Registry) error { res = append(res, err) } + if err := m.validateHtEnabled(formats); err != nil { + res = append(res, err) + } + + if err := m.validateMemSizeMib(formats); err != nil { + res = append(res, err) + } + if err := m.validateVcpuCount(formats); err != nil { res = append(res, err) } @@ -79,17 +90,35 @@ func (m *MachineConfiguration) validateCPUTemplate(formats strfmt.Registry) erro return nil } +func (m *MachineConfiguration) validateHtEnabled(formats strfmt.Registry) error { + + if err := validate.Required("ht_enabled", "body", m.HtEnabled); err != nil { + return err + } + + return nil +} + +func (m *MachineConfiguration) validateMemSizeMib(formats strfmt.Registry) error { + + if err := validate.Required("mem_size_mib", "body", m.MemSizeMib); err != nil { + return err + } + + return nil +} + func (m *MachineConfiguration) validateVcpuCount(formats strfmt.Registry) error { - if swag.IsZero(m.VcpuCount) { // not required - return nil + if err := validate.Required("vcpu_count", "body", m.VcpuCount); err != nil { + return err } - if err := validate.MinimumInt("vcpu_count", "body", int64(m.VcpuCount), 1, false); err != nil { + if err := validate.MinimumInt("vcpu_count", "body", int64(*m.VcpuCount), 1, false); err != nil { return err } - if err := validate.MaximumInt("vcpu_count", "body", int64(m.VcpuCount), 32, false); err != nil { + if err := validate.MaximumInt("vcpu_count", "body", int64(*m.VcpuCount), 32, false); err != nil { return err } diff --git a/vendor/github.com/firecracker-microvm/firecracker-go-sdk/client/operations/get_machine_config_parameters.go b/vendor/github.com/firecracker-microvm/firecracker-go-sdk/client/operations/get_machine_config_parameters.go deleted file mode 100644 index 6492ef285..000000000 --- a/vendor/github.com/firecracker-microvm/firecracker-go-sdk/client/operations/get_machine_config_parameters.go +++ /dev/null @@ -1,127 +0,0 @@ -// Code generated by go-swagger; DO NOT EDIT. - -// Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"). You may -// not use this file except in compliance with the License. A copy of the -// License is located at -// -// http://aws.amazon.com/apache2.0/ -// -// or in the "license" file accompanying this file. This file is distributed -// on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either -// express or implied. See the License for the specific language governing -// permissions and limitations under the License. - -package operations - -// This file was generated by the swagger tool. -// Editing this file might prove futile when you re-run the swagger generate command - -import ( - "net/http" - "time" - - "golang.org/x/net/context" - - "github.com/go-openapi/errors" - "github.com/go-openapi/runtime" - cr "github.com/go-openapi/runtime/client" - - strfmt "github.com/go-openapi/strfmt" -) - -// NewGetMachineConfigParams creates a new GetMachineConfigParams object -// with the default values initialized. -func NewGetMachineConfigParams() *GetMachineConfigParams { - - return &GetMachineConfigParams{ - - timeout: cr.DefaultTimeout, - } -} - -// NewGetMachineConfigParamsWithTimeout creates a new GetMachineConfigParams object -// with the default values initialized, and the ability to set a timeout on a request -func NewGetMachineConfigParamsWithTimeout(timeout time.Duration) *GetMachineConfigParams { - - return &GetMachineConfigParams{ - - timeout: timeout, - } -} - -// NewGetMachineConfigParamsWithContext creates a new GetMachineConfigParams object -// with the default values initialized, and the ability to set a context for a request -func NewGetMachineConfigParamsWithContext(ctx context.Context) *GetMachineConfigParams { - - return &GetMachineConfigParams{ - - Context: ctx, - } -} - -// NewGetMachineConfigParamsWithHTTPClient creates a new GetMachineConfigParams object -// with the default values initialized, and the ability to set a custom HTTPClient for a request -func NewGetMachineConfigParamsWithHTTPClient(client *http.Client) *GetMachineConfigParams { - - return &GetMachineConfigParams{ - HTTPClient: client, - } -} - -/*GetMachineConfigParams contains all the parameters to send to the API endpoint -for the get machine config operation typically these are written to a http.Request -*/ -type GetMachineConfigParams struct { - timeout time.Duration - Context context.Context - HTTPClient *http.Client -} - -// WithTimeout adds the timeout to the get machine config params -func (o *GetMachineConfigParams) WithTimeout(timeout time.Duration) *GetMachineConfigParams { - o.SetTimeout(timeout) - return o -} - -// SetTimeout adds the timeout to the get machine config params -func (o *GetMachineConfigParams) SetTimeout(timeout time.Duration) { - o.timeout = timeout -} - -// WithContext adds the context to the get machine config params -func (o *GetMachineConfigParams) WithContext(ctx context.Context) *GetMachineConfigParams { - o.SetContext(ctx) - return o -} - -// SetContext adds the context to the get machine config params -func (o *GetMachineConfigParams) SetContext(ctx context.Context) { - o.Context = ctx -} - -// WithHTTPClient adds the HTTPClient to the get machine config params -func (o *GetMachineConfigParams) WithHTTPClient(client *http.Client) *GetMachineConfigParams { - o.SetHTTPClient(client) - return o -} - -// SetHTTPClient adds the HTTPClient to the get machine config params -func (o *GetMachineConfigParams) SetHTTPClient(client *http.Client) { - o.HTTPClient = client -} - -// WriteToRequest writes these params to a swagger request -func (o *GetMachineConfigParams) WriteToRequest(r runtime.ClientRequest, reg strfmt.Registry) error { - - if err := r.SetTimeout(o.timeout); err != nil { - return err - } - var res []error - - if len(res) > 0 { - return errors.CompositeValidationError(res...) - } - return nil -} diff --git a/vendor/github.com/firecracker-microvm/firecracker-go-sdk/client/operations/get_machine_configuration_parameters.go b/vendor/github.com/firecracker-microvm/firecracker-go-sdk/client/operations/get_machine_configuration_parameters.go new file mode 100644 index 000000000..87ef3313f --- /dev/null +++ b/vendor/github.com/firecracker-microvm/firecracker-go-sdk/client/operations/get_machine_configuration_parameters.go @@ -0,0 +1,127 @@ +// Code generated by go-swagger; DO NOT EDIT. + +// Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"). You may +// not use this file except in compliance with the License. A copy of the +// License is located at +// +// http://aws.amazon.com/apache2.0/ +// +// or in the "license" file accompanying this file. This file is distributed +// on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either +// express or implied. See the License for the specific language governing +// permissions and limitations under the License. + +package operations + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "net/http" + "time" + + "golang.org/x/net/context" + + "github.com/go-openapi/errors" + "github.com/go-openapi/runtime" + cr "github.com/go-openapi/runtime/client" + + strfmt "github.com/go-openapi/strfmt" +) + +// NewGetMachineConfigurationParams creates a new GetMachineConfigurationParams object +// with the default values initialized. +func NewGetMachineConfigurationParams() *GetMachineConfigurationParams { + + return &GetMachineConfigurationParams{ + + timeout: cr.DefaultTimeout, + } +} + +// NewGetMachineConfigurationParamsWithTimeout creates a new GetMachineConfigurationParams object +// with the default values initialized, and the ability to set a timeout on a request +func NewGetMachineConfigurationParamsWithTimeout(timeout time.Duration) *GetMachineConfigurationParams { + + return &GetMachineConfigurationParams{ + + timeout: timeout, + } +} + +// NewGetMachineConfigurationParamsWithContext creates a new GetMachineConfigurationParams object +// with the default values initialized, and the ability to set a context for a request +func NewGetMachineConfigurationParamsWithContext(ctx context.Context) *GetMachineConfigurationParams { + + return &GetMachineConfigurationParams{ + + Context: ctx, + } +} + +// NewGetMachineConfigurationParamsWithHTTPClient creates a new GetMachineConfigurationParams object +// with the default values initialized, and the ability to set a custom HTTPClient for a request +func NewGetMachineConfigurationParamsWithHTTPClient(client *http.Client) *GetMachineConfigurationParams { + + return &GetMachineConfigurationParams{ + HTTPClient: client, + } +} + +/*GetMachineConfigurationParams contains all the parameters to send to the API endpoint +for the get machine configuration operation typically these are written to a http.Request +*/ +type GetMachineConfigurationParams struct { + timeout time.Duration + Context context.Context + HTTPClient *http.Client +} + +// WithTimeout adds the timeout to the get machine configuration params +func (o *GetMachineConfigurationParams) WithTimeout(timeout time.Duration) *GetMachineConfigurationParams { + o.SetTimeout(timeout) + return o +} + +// SetTimeout adds the timeout to the get machine configuration params +func (o *GetMachineConfigurationParams) SetTimeout(timeout time.Duration) { + o.timeout = timeout +} + +// WithContext adds the context to the get machine configuration params +func (o *GetMachineConfigurationParams) WithContext(ctx context.Context) *GetMachineConfigurationParams { + o.SetContext(ctx) + return o +} + +// SetContext adds the context to the get machine configuration params +func (o *GetMachineConfigurationParams) SetContext(ctx context.Context) { + o.Context = ctx +} + +// WithHTTPClient adds the HTTPClient to the get machine configuration params +func (o *GetMachineConfigurationParams) WithHTTPClient(client *http.Client) *GetMachineConfigurationParams { + o.SetHTTPClient(client) + return o +} + +// SetHTTPClient adds the HTTPClient to the get machine configuration params +func (o *GetMachineConfigurationParams) SetHTTPClient(client *http.Client) { + o.HTTPClient = client +} + +// WriteToRequest writes these params to a swagger request +func (o *GetMachineConfigurationParams) WriteToRequest(r runtime.ClientRequest, reg strfmt.Registry) error { + + if err := r.SetTimeout(o.timeout); err != nil { + return err + } + var res []error + + if len(res) > 0 { + return errors.CompositeValidationError(res...) + } + return nil +} diff --git a/vendor/github.com/firecracker-microvm/firecracker-go-sdk/client/operations/get_machine_config_responses.go b/vendor/github.com/firecracker-microvm/firecracker-go-sdk/client/operations/get_machine_configuration_responses.go similarity index 52% rename from vendor/github.com/firecracker-microvm/firecracker-go-sdk/client/operations/get_machine_config_responses.go rename to vendor/github.com/firecracker-microvm/firecracker-go-sdk/client/operations/get_machine_configuration_responses.go index 09d1725bc..cd4e5c79d 100644 --- a/vendor/github.com/firecracker-microvm/firecracker-go-sdk/client/operations/get_machine_config_responses.go +++ b/vendor/github.com/firecracker-microvm/firecracker-go-sdk/client/operations/get_machine_configuration_responses.go @@ -29,24 +29,24 @@ import ( client_models "github.com/firecracker-microvm/firecracker-go-sdk/client/models" ) -// GetMachineConfigReader is a Reader for the GetMachineConfig structure. -type GetMachineConfigReader struct { +// GetMachineConfigurationReader is a Reader for the GetMachineConfiguration structure. +type GetMachineConfigurationReader struct { formats strfmt.Registry } // ReadResponse reads a server response into the received o. -func (o *GetMachineConfigReader) ReadResponse(response runtime.ClientResponse, consumer runtime.Consumer) (interface{}, error) { +func (o *GetMachineConfigurationReader) ReadResponse(response runtime.ClientResponse, consumer runtime.Consumer) (interface{}, error) { switch response.Code() { case 200: - result := NewGetMachineConfigOK() + result := NewGetMachineConfigurationOK() if err := result.readResponse(response, consumer, o.formats); err != nil { return nil, err } return result, nil default: - result := NewGetMachineConfigDefault(response.Code()) + result := NewGetMachineConfigurationDefault(response.Code()) if err := result.readResponse(response, consumer, o.formats); err != nil { return nil, err } @@ -57,24 +57,24 @@ func (o *GetMachineConfigReader) ReadResponse(response runtime.ClientResponse, c } } -// NewGetMachineConfigOK creates a GetMachineConfigOK with default headers values -func NewGetMachineConfigOK() *GetMachineConfigOK { - return &GetMachineConfigOK{} +// NewGetMachineConfigurationOK creates a GetMachineConfigurationOK with default headers values +func NewGetMachineConfigurationOK() *GetMachineConfigurationOK { + return &GetMachineConfigurationOK{} } -/*GetMachineConfigOK handles this case with default header values. +/*GetMachineConfigurationOK handles this case with default header values. OK */ -type GetMachineConfigOK struct { +type GetMachineConfigurationOK struct { Payload *client_models.MachineConfiguration } -func (o *GetMachineConfigOK) Error() string { - return fmt.Sprintf("[GET /machine-config][%d] getMachineConfigOK %+v", 200, o.Payload) +func (o *GetMachineConfigurationOK) Error() string { + return fmt.Sprintf("[GET /machine-config][%d] getMachineConfigurationOK %+v", 200, o.Payload) } -func (o *GetMachineConfigOK) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error { +func (o *GetMachineConfigurationOK) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error { o.Payload = new(client_models.MachineConfiguration) @@ -86,33 +86,33 @@ func (o *GetMachineConfigOK) readResponse(response runtime.ClientResponse, consu return nil } -// NewGetMachineConfigDefault creates a GetMachineConfigDefault with default headers values -func NewGetMachineConfigDefault(code int) *GetMachineConfigDefault { - return &GetMachineConfigDefault{ +// NewGetMachineConfigurationDefault creates a GetMachineConfigurationDefault with default headers values +func NewGetMachineConfigurationDefault(code int) *GetMachineConfigurationDefault { + return &GetMachineConfigurationDefault{ _statusCode: code, } } -/*GetMachineConfigDefault handles this case with default header values. +/*GetMachineConfigurationDefault handles this case with default header values. Internal server error */ -type GetMachineConfigDefault struct { +type GetMachineConfigurationDefault struct { _statusCode int Payload *client_models.Error } -// Code gets the status code for the get machine config default response -func (o *GetMachineConfigDefault) Code() int { +// Code gets the status code for the get machine configuration default response +func (o *GetMachineConfigurationDefault) Code() int { return o._statusCode } -func (o *GetMachineConfigDefault) Error() string { - return fmt.Sprintf("[GET /machine-config][%d] GetMachineConfig default %+v", o._statusCode, o.Payload) +func (o *GetMachineConfigurationDefault) Error() string { + return fmt.Sprintf("[GET /machine-config][%d] getMachineConfiguration default %+v", o._statusCode, o.Payload) } -func (o *GetMachineConfigDefault) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error { +func (o *GetMachineConfigurationDefault) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error { o.Payload = new(client_models.Error) diff --git a/vendor/github.com/firecracker-microvm/firecracker-go-sdk/client/operations/operations_client.go b/vendor/github.com/firecracker-microvm/firecracker-go-sdk/client/operations/operations_client.go index 08603a846..cb55c187c 100644 --- a/vendor/github.com/firecracker-microvm/firecracker-go-sdk/client/operations/operations_client.go +++ b/vendor/github.com/firecracker-microvm/firecracker-go-sdk/client/operations/operations_client.go @@ -45,36 +45,6 @@ func NewClient(transport runtime.ClientTransport, formats strfmt.Registry) *Clie } } -/* -GetMachineConfig gets the machine configuration of the VM - -Gets the machine configuration of the VM. When called before the PUT operation, it will return the default values for the vCPU count (=1), memory size (=128 MiB). By default Hyperthreading is disabled and there is no CPU Template. -*/ -func (a *Client) GetMachineConfig(params *GetMachineConfigParams) (*GetMachineConfigOK, error) { - // TODO: Validate the params before sending - if params == nil { - params = NewGetMachineConfigParams() - } - - result, err := a.transport.Submit(&runtime.ClientOperation{ - ID: "GetMachineConfig", - Method: "GET", - PathPattern: "/machine-config", - ProducesMediaTypes: []string{"application/json"}, - ConsumesMediaTypes: []string{"application/json"}, - Schemes: []string{"http"}, - Params: params, - Reader: &GetMachineConfigReader{formats: a.formats}, - Context: params.Context, - Client: params.HTTPClient, - }) - if err != nil { - return nil, err - } - return result.(*GetMachineConfigOK), nil - -} - /* GetMmds gets the m m d s data store */ @@ -215,6 +185,36 @@ func (a *Client) DescribeInstance(params *DescribeInstanceParams) (*DescribeInst } +/* +GetMachineConfiguration gets the machine configuration of the VM + +Gets the machine configuration of the VM. When called before the PUT operation, it will return the default values for the vCPU count (=1), memory size (=128 MiB). By default Hyperthreading is disabled and there is no CPU Template. +*/ +func (a *Client) GetMachineConfiguration(params *GetMachineConfigurationParams) (*GetMachineConfigurationOK, error) { + // TODO: Validate the params before sending + if params == nil { + params = NewGetMachineConfigurationParams() + } + + result, err := a.transport.Submit(&runtime.ClientOperation{ + ID: "getMachineConfiguration", + Method: "GET", + PathPattern: "/machine-config", + ProducesMediaTypes: []string{"application/json"}, + ConsumesMediaTypes: []string{"application/json"}, + Schemes: []string{"http"}, + Params: params, + Reader: &GetMachineConfigurationReader{formats: a.formats}, + Context: params.Context, + Client: params.HTTPClient, + }) + if err != nil { + return nil, err + } + return result.(*GetMachineConfigurationOK), nil + +} + /* PatchGuestDriveByID updates the properties of a drive @@ -275,6 +275,36 @@ func (a *Client) PatchGuestNetworkInterfaceByID(params *PatchGuestNetworkInterfa } +/* +PatchMachineConfiguration partiallies updates the machine configuration of the VM + +Partially updates the Virtual Machine Configuration with the specified input. If any of the parameters has an incorrect value, the whole update fails. +*/ +func (a *Client) PatchMachineConfiguration(params *PatchMachineConfigurationParams) (*PatchMachineConfigurationNoContent, error) { + // TODO: Validate the params before sending + if params == nil { + params = NewPatchMachineConfigurationParams() + } + + result, err := a.transport.Submit(&runtime.ClientOperation{ + ID: "patchMachineConfiguration", + Method: "PATCH", + PathPattern: "/machine-config", + ProducesMediaTypes: []string{"application/json"}, + ConsumesMediaTypes: []string{"application/json"}, + Schemes: []string{"http"}, + Params: params, + Reader: &PatchMachineConfigurationReader{formats: a.formats}, + Context: params.Context, + Client: params.HTTPClient, + }) + if err != nil { + return nil, err + } + return result.(*PatchMachineConfigurationNoContent), nil + +} + /* PutGuestBootSource creates or updates the boot source @@ -467,14 +497,15 @@ func (a *Client) SetTransport(transport runtime.ClientTransport) { // ClientIface is an interface that can be used to mock out a Firecracker agent // for testing purposes. type ClientIface interface { - GetMachineConfig(params *GetMachineConfigParams) (*GetMachineConfigOK, error) GetMmds(params *GetMmdsParams) (*GetMmdsOK, error) PatchMmds(params *PatchMmdsParams) (*PatchMmdsNoContent, error) PutMmds(params *PutMmdsParams) (*PutMmdsNoContent, error) CreateSyncAction(params *CreateSyncActionParams) (*CreateSyncActionNoContent, error) DescribeInstance(params *DescribeInstanceParams) (*DescribeInstanceOK, error) + GetMachineConfiguration(params *GetMachineConfigurationParams) (*GetMachineConfigurationOK, error) PatchGuestDriveByID(params *PatchGuestDriveByIDParams) (*PatchGuestDriveByIDNoContent, error) PatchGuestNetworkInterfaceByID(params *PatchGuestNetworkInterfaceByIDParams) (*PatchGuestNetworkInterfaceByIDNoContent, error) + PatchMachineConfiguration(params *PatchMachineConfigurationParams) (*PatchMachineConfigurationNoContent, error) PutGuestBootSource(params *PutGuestBootSourceParams) (*PutGuestBootSourceNoContent, error) PutGuestDriveByID(params *PutGuestDriveByIDParams) (*PutGuestDriveByIDNoContent, error) PutGuestNetworkInterfaceByID(params *PutGuestNetworkInterfaceByIDParams) (*PutGuestNetworkInterfaceByIDNoContent, error) diff --git a/vendor/github.com/firecracker-microvm/firecracker-go-sdk/client/operations/patch_machine_configuration_parameters.go b/vendor/github.com/firecracker-microvm/firecracker-go-sdk/client/operations/patch_machine_configuration_parameters.go new file mode 100644 index 000000000..60d02deed --- /dev/null +++ b/vendor/github.com/firecracker-microvm/firecracker-go-sdk/client/operations/patch_machine_configuration_parameters.go @@ -0,0 +1,153 @@ +// Code generated by go-swagger; DO NOT EDIT. + +// Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"). You may +// not use this file except in compliance with the License. A copy of the +// License is located at +// +// http://aws.amazon.com/apache2.0/ +// +// or in the "license" file accompanying this file. This file is distributed +// on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either +// express or implied. See the License for the specific language governing +// permissions and limitations under the License. + +package operations + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "net/http" + "time" + + "golang.org/x/net/context" + + "github.com/go-openapi/errors" + "github.com/go-openapi/runtime" + cr "github.com/go-openapi/runtime/client" + + strfmt "github.com/go-openapi/strfmt" + + client_models "github.com/firecracker-microvm/firecracker-go-sdk/client/models" +) + +// NewPatchMachineConfigurationParams creates a new PatchMachineConfigurationParams object +// with the default values initialized. +func NewPatchMachineConfigurationParams() *PatchMachineConfigurationParams { + var () + return &PatchMachineConfigurationParams{ + + timeout: cr.DefaultTimeout, + } +} + +// NewPatchMachineConfigurationParamsWithTimeout creates a new PatchMachineConfigurationParams object +// with the default values initialized, and the ability to set a timeout on a request +func NewPatchMachineConfigurationParamsWithTimeout(timeout time.Duration) *PatchMachineConfigurationParams { + var () + return &PatchMachineConfigurationParams{ + + timeout: timeout, + } +} + +// NewPatchMachineConfigurationParamsWithContext creates a new PatchMachineConfigurationParams object +// with the default values initialized, and the ability to set a context for a request +func NewPatchMachineConfigurationParamsWithContext(ctx context.Context) *PatchMachineConfigurationParams { + var () + return &PatchMachineConfigurationParams{ + + Context: ctx, + } +} + +// NewPatchMachineConfigurationParamsWithHTTPClient creates a new PatchMachineConfigurationParams object +// with the default values initialized, and the ability to set a custom HTTPClient for a request +func NewPatchMachineConfigurationParamsWithHTTPClient(client *http.Client) *PatchMachineConfigurationParams { + var () + return &PatchMachineConfigurationParams{ + HTTPClient: client, + } +} + +/*PatchMachineConfigurationParams contains all the parameters to send to the API endpoint +for the patch machine configuration operation typically these are written to a http.Request +*/ +type PatchMachineConfigurationParams struct { + + /*Body + A subset of Machine Configuration Parameters + + */ + Body *client_models.MachineConfiguration + + timeout time.Duration + Context context.Context + HTTPClient *http.Client +} + +// WithTimeout adds the timeout to the patch machine configuration params +func (o *PatchMachineConfigurationParams) WithTimeout(timeout time.Duration) *PatchMachineConfigurationParams { + o.SetTimeout(timeout) + return o +} + +// SetTimeout adds the timeout to the patch machine configuration params +func (o *PatchMachineConfigurationParams) SetTimeout(timeout time.Duration) { + o.timeout = timeout +} + +// WithContext adds the context to the patch machine configuration params +func (o *PatchMachineConfigurationParams) WithContext(ctx context.Context) *PatchMachineConfigurationParams { + o.SetContext(ctx) + return o +} + +// SetContext adds the context to the patch machine configuration params +func (o *PatchMachineConfigurationParams) SetContext(ctx context.Context) { + o.Context = ctx +} + +// WithHTTPClient adds the HTTPClient to the patch machine configuration params +func (o *PatchMachineConfigurationParams) WithHTTPClient(client *http.Client) *PatchMachineConfigurationParams { + o.SetHTTPClient(client) + return o +} + +// SetHTTPClient adds the HTTPClient to the patch machine configuration params +func (o *PatchMachineConfigurationParams) SetHTTPClient(client *http.Client) { + o.HTTPClient = client +} + +// WithBody adds the body to the patch machine configuration params +func (o *PatchMachineConfigurationParams) WithBody(body *client_models.MachineConfiguration) *PatchMachineConfigurationParams { + o.SetBody(body) + return o +} + +// SetBody adds the body to the patch machine configuration params +func (o *PatchMachineConfigurationParams) SetBody(body *client_models.MachineConfiguration) { + o.Body = body +} + +// WriteToRequest writes these params to a swagger request +func (o *PatchMachineConfigurationParams) WriteToRequest(r runtime.ClientRequest, reg strfmt.Registry) error { + + if err := r.SetTimeout(o.timeout); err != nil { + return err + } + var res []error + + if o.Body != nil { + if err := r.SetBodyParam(o.Body); err != nil { + return err + } + } + + if len(res) > 0 { + return errors.CompositeValidationError(res...) + } + return nil +} diff --git a/vendor/github.com/firecracker-microvm/firecracker-go-sdk/client/operations/patch_machine_configuration_responses.go b/vendor/github.com/firecracker-microvm/firecracker-go-sdk/client/operations/patch_machine_configuration_responses.go new file mode 100644 index 000000000..81570f839 --- /dev/null +++ b/vendor/github.com/firecracker-microvm/firecracker-go-sdk/client/operations/patch_machine_configuration_responses.go @@ -0,0 +1,153 @@ +// Code generated by go-swagger; DO NOT EDIT. + +// Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"). You may +// not use this file except in compliance with the License. A copy of the +// License is located at +// +// http://aws.amazon.com/apache2.0/ +// +// or in the "license" file accompanying this file. This file is distributed +// on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either +// express or implied. See the License for the specific language governing +// permissions and limitations under the License. + +package operations + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "fmt" + "io" + + "github.com/go-openapi/runtime" + + strfmt "github.com/go-openapi/strfmt" + + client_models "github.com/firecracker-microvm/firecracker-go-sdk/client/models" +) + +// PatchMachineConfigurationReader is a Reader for the PatchMachineConfiguration structure. +type PatchMachineConfigurationReader struct { + formats strfmt.Registry +} + +// ReadResponse reads a server response into the received o. +func (o *PatchMachineConfigurationReader) ReadResponse(response runtime.ClientResponse, consumer runtime.Consumer) (interface{}, error) { + switch response.Code() { + + case 204: + result := NewPatchMachineConfigurationNoContent() + if err := result.readResponse(response, consumer, o.formats); err != nil { + return nil, err + } + return result, nil + + case 400: + result := NewPatchMachineConfigurationBadRequest() + if err := result.readResponse(response, consumer, o.formats); err != nil { + return nil, err + } + return nil, result + + default: + result := NewPatchMachineConfigurationDefault(response.Code()) + if err := result.readResponse(response, consumer, o.formats); err != nil { + return nil, err + } + if response.Code()/100 == 2 { + return result, nil + } + return nil, result + } +} + +// NewPatchMachineConfigurationNoContent creates a PatchMachineConfigurationNoContent with default headers values +func NewPatchMachineConfigurationNoContent() *PatchMachineConfigurationNoContent { + return &PatchMachineConfigurationNoContent{} +} + +/*PatchMachineConfigurationNoContent handles this case with default header values. + +Machine Configuration created/updated +*/ +type PatchMachineConfigurationNoContent struct { +} + +func (o *PatchMachineConfigurationNoContent) Error() string { + return fmt.Sprintf("[PATCH /machine-config][%d] patchMachineConfigurationNoContent ", 204) +} + +func (o *PatchMachineConfigurationNoContent) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error { + + return nil +} + +// NewPatchMachineConfigurationBadRequest creates a PatchMachineConfigurationBadRequest with default headers values +func NewPatchMachineConfigurationBadRequest() *PatchMachineConfigurationBadRequest { + return &PatchMachineConfigurationBadRequest{} +} + +/*PatchMachineConfigurationBadRequest handles this case with default header values. + +Machine Configuration cannot be updated due to bad input +*/ +type PatchMachineConfigurationBadRequest struct { + Payload *client_models.Error +} + +func (o *PatchMachineConfigurationBadRequest) Error() string { + return fmt.Sprintf("[PATCH /machine-config][%d] patchMachineConfigurationBadRequest %+v", 400, o.Payload) +} + +func (o *PatchMachineConfigurationBadRequest) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error { + + o.Payload = new(client_models.Error) + + // response payload + if err := consumer.Consume(response.Body(), o.Payload); err != nil && err != io.EOF { + return err + } + + return nil +} + +// NewPatchMachineConfigurationDefault creates a PatchMachineConfigurationDefault with default headers values +func NewPatchMachineConfigurationDefault(code int) *PatchMachineConfigurationDefault { + return &PatchMachineConfigurationDefault{ + _statusCode: code, + } +} + +/*PatchMachineConfigurationDefault handles this case with default header values. + +Internal server error +*/ +type PatchMachineConfigurationDefault struct { + _statusCode int + + Payload *client_models.Error +} + +// Code gets the status code for the patch machine configuration default response +func (o *PatchMachineConfigurationDefault) Code() int { + return o._statusCode +} + +func (o *PatchMachineConfigurationDefault) Error() string { + return fmt.Sprintf("[PATCH /machine-config][%d] patchMachineConfiguration default %+v", o._statusCode, o.Payload) +} + +func (o *PatchMachineConfigurationDefault) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error { + + o.Payload = new(client_models.Error) + + // response payload + if err := consumer.Consume(response.Body(), o.Payload); err != nil && err != io.EOF { + return err + } + + return nil +} diff --git a/vendor/github.com/firecracker-microvm/firecracker-go-sdk/client/swagger.yaml b/vendor/github.com/firecracker-microvm/firecracker-go-sdk/client/swagger.yaml index d18f3e2ab..a3399813e 100644 --- a/vendor/github.com/firecracker-microvm/firecracker-go-sdk/client/swagger.yaml +++ b/vendor/github.com/firecracker-microvm/firecracker-go-sdk/client/swagger.yaml @@ -4,7 +4,7 @@ info: description: RESTful public-facing API. The API is accessible through HTTP calls on specific URLs carrying JSON modeled data. The transport medium is a Unix Domain Socket. - version: 0.15.0 + version: 0.17.0 termsOfService: "" contact: email: "compute-capsule@amazon.com" @@ -210,6 +210,7 @@ paths: Gets the machine configuration of the VM. When called before the PUT operation, it will return the default values for the vCPU count (=1), memory size (=128 MiB). By default Hyperthreading is disabled and there is no CPU Template. + operationId: getMachineConfiguration responses: 200: description: OK @@ -247,6 +248,30 @@ paths: schema: $ref: "#/definitions/Error" + patch: + summary: Partially updates the Machine Configuration of the VM. + description: + Partially updates the Virtual Machine Configuration with the specified input. + If any of the parameters has an incorrect value, the whole update fails. + operationId: patchMachineConfiguration + parameters: + - name: body + in: body + description: A subset of Machine Configuration Parameters + schema: + $ref: "#/definitions/MachineConfiguration" + responses: + 204: + description: Machine Configuration created/updated + 400: + description: Machine Configuration cannot be updated due to bad input + schema: + $ref: "#/definitions/Error" + default: + description: Internal server error + schema: + $ref: "#/definitions/Error" + /mmds: put: summary: Creates a MMDS (Microvm Metadata Service) data store. @@ -428,7 +453,6 @@ definitions: action_type: description: Enumeration indicating what type of action is contained in the payload type: string - readOnly: true enum: - BlockDeviceRescan - FlushMetrics @@ -449,13 +473,11 @@ definitions: id: description: MicroVM / instance ID. type: string - readOnly: true state: description: The current detailed state of the Firecracker instance. This value is read-only for the control-plane. type: string - readOnly: true enum: - Uninitialized - Starting @@ -465,7 +487,6 @@ definitions: vmm_version: description: MicroVM hypervisor build version. type: string - readOnly: true Logger: type: object @@ -506,6 +527,10 @@ definitions: description: Describes the number of vCPUs, memory size, Hyperthreading capabilities and the CPU template. + required: + - vcpu_count + - mem_size_mib + - ht_enabled properties: vcpu_count: type: integer @@ -619,7 +644,6 @@ definitions: format: int64 description: The amount of milliseconds it takes for the bucket to refill. minimum: 0 - Vsock: type: object required: diff --git a/vendor/github.com/firecracker-microvm/firecracker-go-sdk/client_transports.go b/vendor/github.com/firecracker-microvm/firecracker-go-sdk/client_transports.go index 37f194b81..5d70f0749 100644 --- a/vendor/github.com/firecracker-microvm/firecracker-go-sdk/client_transports.go +++ b/vendor/github.com/firecracker-microvm/firecracker-go-sdk/client_transports.go @@ -1,3 +1,16 @@ +// Copyright 2018-2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"). You may +// not use this file except in compliance with the License. A copy of the +// License is located at +// +// http://aws.amazon.com/apache2.0/ +// +// or in the "license" file accompanying this file. This file is distributed +// on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either +// express or implied. See the License for the specific language governing +// permissions and limitations under the License. + package firecracker import ( diff --git a/vendor/github.com/firecracker-microvm/firecracker-go-sdk/firecracker.go b/vendor/github.com/firecracker-microvm/firecracker-go-sdk/firecracker.go index 2f2d24ef2..cc28215f3 100644 --- a/vendor/github.com/firecracker-microvm/firecracker-go-sdk/firecracker.go +++ b/vendor/github.com/firecracker-microvm/firecracker-go-sdk/firecracker.go @@ -213,20 +213,20 @@ func (f *Client) PutMmds(ctx context.Context, metadata interface{}, opts ...PutM return f.client.Operations.PutMmds(params) } -// GetMachineConfigOpt is a functional option to be used for the -// GetMachineConfig API in setting any additional optional fields. -type GetMachineConfigOpt func(*ops.GetMachineConfigParams) +// GetMachineConfigurationOpt is a functional option to be used for the +// GetMachineConfiguration API in setting any additional optional fields. +type GetMachineConfigurationOpt func(*ops.GetMachineConfigurationParams) -// GetMachineConfig is a wrapper for the swagger generated client to make +// GetMachineConfiguration is a wrapper for the swagger generated client to make // calling of the API easier. -func (f *Client) GetMachineConfig(opts ...GetMachineConfigOpt) (*ops.GetMachineConfigOK, error) { - p := ops.NewGetMachineConfigParams() +func (f *Client) GetMachineConfiguration(opts ...GetMachineConfigurationOpt) (*ops.GetMachineConfigurationOK, error) { + p := ops.NewGetMachineConfigurationParams() p.SetTimeout(firecrackerRequestTimeout) for _, opt := range opts { opt(p) } - return f.client.Operations.GetMachineConfig(p) + return f.client.Operations.GetMachineConfiguration(p) } // PatchGuestDriveByIDOpt is a functional option to be used for the PutMmds API in setting diff --git a/vendor/github.com/firecracker-microvm/firecracker-go-sdk/handlers.go b/vendor/github.com/firecracker-microvm/firecracker-go-sdk/handlers.go index 17f5bba7e..44040cfa0 100644 --- a/vendor/github.com/firecracker-microvm/firecracker-go-sdk/handlers.go +++ b/vendor/github.com/firecracker-microvm/firecracker-go-sdk/handlers.go @@ -22,6 +22,7 @@ import ( const ( StartVMMHandlerName = "fcinit.StartVMM" BootstrapLoggingHandlerName = "fcinit.BootstrapLogging" + CreateLogFilesHandlerName = "fcinit.CreateLogFilesHandler" CreateMachineHandlerName = "fcinit.CreateMachine" CreateBootSourceHandlerName = "fcinit.CreateBootSource" AttachDrivesHandlerName = "fcinit.AttachDrives" @@ -107,6 +108,29 @@ var StartVMMHandler = Handler{ }, } +// CreateLogFilesHandler is a named handler that will create the fifo log files +var CreateLogFilesHandler = Handler{ + Name: CreateLogFilesHandlerName, + Fn: func(ctx context.Context, m *Machine) error { + logFifoPath := m.cfg.LogFifo + metricsFifoPath := m.cfg.MetricsFifo + + if len(logFifoPath) == 0 || len(metricsFifoPath) == 0 { + // logging is disabled + return nil + } + + if err := createFifos(logFifoPath, metricsFifoPath); err != nil { + m.logger.Errorf("Unable to set up logging: %s", err) + return err + } + + m.logger.Debug("Created metrics and logging fifos.") + + return nil + }, +} + // BootstrapLoggingHandler is a named handler that will set up fifo logging of // firecracker process. var BootstrapLoggingHandler = Handler{ @@ -180,6 +204,7 @@ func NewSetMetadataHandler(metadata interface{}) Handler { var defaultFcInitHandlerList = HandlerList{}.Append( StartVMMHandler, + CreateLogFilesHandler, BootstrapLoggingHandler, CreateMachineHandler, CreateBootSourceHandler, diff --git a/vendor/github.com/firecracker-microvm/firecracker-go-sdk/jailer.go b/vendor/github.com/firecracker-microvm/firecracker-go-sdk/jailer.go index af7d3407a..f4497e42e 100644 --- a/vendor/github.com/firecracker-microvm/firecracker-go-sdk/jailer.go +++ b/vendor/github.com/firecracker-microvm/firecracker-go-sdk/jailer.go @@ -89,6 +89,13 @@ type JailerConfig struct { // ChrootStrategy will dictate how files are transfered to the root drive. ChrootStrategy HandlersAdapter + + // Stdout specifies the IO writer for STDOUT to use when spawning the jailer. + Stdout io.Writer + // Stderr specifies the IO writer for STDERR to use when spawning the jailer. + Stderr io.Writer + // Stdin specifies the IO reader for STDIN to use when spawning the jailer. + Stdin io.Reader } // JailerCommandBuilder will build a jailer command. This can be used to @@ -283,15 +290,26 @@ func (b JailerCommandBuilder) Build(ctx context.Context) *exec.Cmd { // Jail will set up proper handlers and remove configuration validation due to // stating of files func jail(ctx context.Context, m *Machine, cfg *Config) error { - rootfs := "" + jailerWorkspaceDir := "" if len(cfg.JailerCfg.ChrootBaseDir) > 0 { - rootfs = filepath.Join(cfg.JailerCfg.ChrootBaseDir, "firecracker", cfg.JailerCfg.ID) + jailerWorkspaceDir = filepath.Join(cfg.JailerCfg.ChrootBaseDir, "firecracker", cfg.JailerCfg.ID, rootfsFolderName) } else { - rootfs = filepath.Join(defaultJailerPath, cfg.JailerCfg.ID) + jailerWorkspaceDir = filepath.Join(defaultJailerPath, cfg.JailerCfg.ID, rootfsFolderName) + } + + cfg.SocketPath = filepath.Join(jailerWorkspaceDir, "api.socket") + + stdout := cfg.JailerCfg.Stdout + if stdout == nil { + stdout = os.Stdout + } + + stderr := cfg.JailerCfg.Stderr + if stderr == nil { + stderr = os.Stderr } - cfg.SocketPath = filepath.Join(rootfs, "api.socket") - m.cmd = NewJailerCommandBuilder(). + builder := NewJailerCommandBuilder(). WithID(cfg.JailerCfg.ID). WithUID(*cfg.JailerCfg.UID). WithGID(*cfg.JailerCfg.GID). @@ -300,9 +318,14 @@ func jail(ctx context.Context, m *Machine, cfg *Config) error { WithChrootBaseDir(cfg.JailerCfg.ChrootBaseDir). WithDaemonize(cfg.JailerCfg.Daemonize). WithSeccompLevel(cfg.JailerCfg.SeccompLevel). - WithStdout(os.Stdout). - WithStderr(os.Stderr). - Build(ctx) + WithStdout(stdout). + WithStderr(stderr) + + if stdin := cfg.JailerCfg.Stdin; stdin != nil { + builder = builder.WithStdin(stdin) + } + + m.cmd = builder.Build(ctx) if err := cfg.JailerCfg.ChrootStrategy.AdaptHandlers(&m.Handlers); err != nil { return err @@ -351,6 +374,29 @@ func LinkFilesHandler(rootfs, kernelImageFileName string) Handler { } m.cfg.KernelImagePath = kernelImageFileName + + for _, fifoPath := range []*string{&m.cfg.LogFifo, &m.cfg.MetricsFifo} { + if fifoPath == nil || *fifoPath == "" { + continue + } + + fileName := filepath.Base(*fifoPath) + if err := linkFileToRootFS( + m.cfg.JailerCfg, + filepath.Join(rootfs, fileName), + *fifoPath, + ); err != nil { + return err + } + + if err := os.Chown(filepath.Join(rootfs, fileName), *m.cfg.JailerCfg.UID, *m.cfg.JailerCfg.GID); err != nil { + return err + } + + // update fifoPath as jailer works relative to the chroot dir + *fifoPath = fileName + } + return nil }, } @@ -371,18 +417,18 @@ func NewNaiveChrootStrategy(rootfs, kernelImagePath string) NaiveChrootStrategy } } -// ErrCreateMachineHandlerMissing occurs when the CreateMachineHandler is not -// present in FcInit. -var ErrCreateMachineHandlerMissing = fmt.Errorf("%s is missing from FcInit's list", CreateMachineHandlerName) +// ErrRequiredHandlerMissing occurs when a required handler is not present in +// the handler list. +var ErrRequiredHandlerMissing = fmt.Errorf("required handler is missing from FcInit's list") // AdaptHandlers will inject the LinkFilesHandler into the handler list. func (s NaiveChrootStrategy) AdaptHandlers(handlers *Handlers) error { - if !handlers.FcInit.Has(CreateMachineHandlerName) { - return ErrCreateMachineHandlerMissing + if !handlers.FcInit.Has(CreateLogFilesHandlerName) { + return ErrRequiredHandlerMissing } handlers.FcInit = handlers.FcInit.AppendAfter( - CreateMachineHandlerName, + CreateLogFilesHandlerName, LinkFilesHandler(filepath.Join(s.Rootfs, rootfsFolderName), filepath.Base(s.KernelImagePath)), ) diff --git a/vendor/github.com/firecracker-microvm/firecracker-go-sdk/machine.go b/vendor/github.com/firecracker-microvm/firecracker-go-sdk/machine.go index e039081fc..4de651f7c 100644 --- a/vendor/github.com/firecracker-microvm/firecracker-go-sdk/machine.go +++ b/vendor/github.com/firecracker-microvm/firecracker-go-sdk/machine.go @@ -106,7 +106,7 @@ func (cfg *Config) Validate() error { } if _, err := os.Stat(cfg.KernelImagePath); err != nil { - return fmt.Errorf("failed to stat kernal image path, %q: %v", cfg.KernelImagePath, err) + return fmt.Errorf("failed to stat kernel image path, %q: %v", cfg.KernelImagePath, err) } rootPath := "" @@ -126,6 +126,17 @@ func (cfg *Config) Validate() error { return fmt.Errorf("socket %s already exists", cfg.SocketPath) } + if cfg.MachineCfg.VcpuCount == nil || + Int64Value(cfg.MachineCfg.VcpuCount) < 1 { + return fmt.Errorf("machine needs a nonzero VcpuCount") + } + if cfg.MachineCfg.MemSizeMib == nil || + Int64Value(cfg.MachineCfg.MemSizeMib) < 1 { + return fmt.Errorf("machine needs a nonzero amount of memory") + } + if cfg.MachineCfg.HtEnabled == nil { + return fmt.Errorf("machine needs a setting for ht_enabled") + } return nil } @@ -200,14 +211,9 @@ func NewMachine(ctx context.Context, cfg Config, opts ...Opt) (*Machine, error) m := &Machine{ exitCh: make(chan struct{}), } - logger := log.New() - - if cfg.Debug { - logger.SetLevel(log.DebugLevel) - } m.Handlers = defaultHandlers - m.logger = log.NewEntry(logger) + if cfg.EnableJailer { m.Handlers.Validation = m.Handlers.Validation.Append(JailerConfigValidationHandler) if err := jail(ctx, m, &cfg); err != nil { @@ -216,7 +222,7 @@ func NewMachine(ctx context.Context, cfg Config, opts ...Opt) (*Machine, error) } else { m.Handlers.Validation = m.Handlers.Validation.Append(ConfigValidationHandler) m.cmd = defaultFirecrackerVMMCommandBuilder. - WithSocketPath(m.cfg.SocketPath). + WithSocketPath(cfg.SocketPath). Build(ctx) } @@ -224,10 +230,20 @@ func NewMachine(ctx context.Context, cfg Config, opts ...Opt) (*Machine, error) opt(m) } + if m.logger == nil { + logger := log.New() + if cfg.Debug { + logger.SetLevel(log.DebugLevel) + } + + m.logger = log.NewEntry(logger) + } + if m.client == nil { m.client = NewClient(cfg.SocketPath, m.logger, cfg.Debug) } + m.machineConfig = cfg.MachineCfg m.cfg = cfg m.logger.Debug("Called NewMachine()") @@ -332,6 +348,11 @@ func (m *Machine) startVMM(ctx context.Context) error { os.Remove(m.cfg.LogFifo) os.Remove(m.cfg.MetricsFifo) errCh <- err + + // Notify subscribers that there will be no more values. + // When err is nil, two reads are performed (waitForSocket and close exitCh goroutine), + // second one never ends as it tries to read from empty channel. + close(errCh) }() // Set up a signal handler and pass INT, QUIT, and TERM through to firecracker @@ -357,8 +378,13 @@ func (m *Machine) startVMM(ctx context.Context) error { return err } go func() { - err := <-errCh - m.err = err + select { + case <-ctx.Done(): + m.err = ctx.Err() + case err := <-errCh: + m.err = err + } + close(m.exitCh) }() @@ -403,13 +429,6 @@ func (m *Machine) setupLogging(ctx context.Context) error { return nil } - if err := createFifos(m.cfg.LogFifo, m.cfg.MetricsFifo); err != nil { - m.logger.Errorf("Unable to set up logging: %s", err) - return err - } - - m.logger.Debug("Created metrics and logging fifos.") - l := models.Logger{ LogFifo: String(m.cfg.LogFifo), Level: String(m.cfg.LogLevel), @@ -475,9 +494,9 @@ func (m *Machine) createMachine(ctx context.Context) error { } m.logger.Debug("PutMachineConfiguration returned") - err = m.refreshMachineConfig() + err = m.refreshMachineConfiguration() if err != nil { - log.Errorf("Unable to inspect Firecracker MachineConfig. Continuing anyway. %s", err) + log.Errorf("Unable to inspect Firecracker MachineConfiguration. Continuing anyway. %s", err) } m.logger.Debug("createMachine returning") return err @@ -561,8 +580,9 @@ func (m *Machine) addVsock(ctx context.Context, dev VsockDevice) error { } func (m *Machine) startInstance(ctx context.Context) error { + action := models.InstanceActionInfoActionTypeInstanceStart info := models.InstanceActionInfo{ - ActionType: models.InstanceActionInfoActionTypeInstanceStart, + ActionType: &action, } resp, err := m.client.CreateSyncAction(ctx, &info) @@ -575,8 +595,9 @@ func (m *Machine) startInstance(ctx context.Context) error { } func (m *Machine) sendCtrlAltDel(ctx context.Context) error { + action := models.InstanceActionInfoActionTypeSendCtrlAltDel info := models.InstanceActionInfo{ - ActionType: models.InstanceActionInfoActionTypeSendCtrlAltDel, + ActionType: &action, } resp, err := m.client.CreateSyncAction(ctx, &info) @@ -588,11 +609,6 @@ func (m *Machine) sendCtrlAltDel(ctx context.Context) error { return err } -// EnableMetadata will append or replace the metadata handler. -func (m *Machine) EnableMetadata(metadata interface{}) { - m.Handlers.FcInit = m.Handlers.FcInit.Swappend(NewSetMetadataHandler(metadata)) -} - // SetMetadata sets the machine's metadata for MDDS func (m *Machine) SetMetadata(ctx context.Context, metadata interface{}) error { if _, err := m.client.PutMmds(ctx, metadata); err != nil { @@ -616,15 +632,15 @@ func (m *Machine) UpdateGuestDrive(ctx context.Context, driveID, pathOnHost stri return nil } -// refreshMachineConfig synchronizes our cached representation of the machine configuration +// refreshMachineConfiguration synchronizes our cached representation of the machine configuration // with that reported by the Firecracker API -func (m *Machine) refreshMachineConfig() error { - resp, err := m.client.GetMachineConfig() +func (m *Machine) refreshMachineConfiguration() error { + resp, err := m.client.GetMachineConfiguration() if err != nil { return err } - m.logger.Infof("refreshMachineConfig: %s", resp.Error()) + m.logger.Infof("refreshMachineConfiguration: %s", resp.Error()) m.machineConfig = *resp.Payload return nil } @@ -648,7 +664,7 @@ func (m *Machine) waitForSocket(timeout time.Duration, exitchan chan error) erro } // Send test HTTP request to make sure socket is available - if _, err := m.client.GetMachineConfig(); err != nil { + if _, err := m.client.GetMachineConfiguration(); err != nil { continue } diff --git a/vendor/github.com/firecracker-microvm/firecracker-go-sdk/machineiface.go b/vendor/github.com/firecracker-microvm/firecracker-go-sdk/machineiface.go new file mode 100644 index 000000000..cd285b01f --- /dev/null +++ b/vendor/github.com/firecracker-microvm/firecracker-go-sdk/machineiface.go @@ -0,0 +1,32 @@ +// Copyright 2018-2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"). You may +// not use this file except in compliance with the License. A copy of the +// License is located at +// +// http://aws.amazon.com/apache2.0/ +// +// or in the "license" file accompanying this file. This file is distributed +// on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either +// express or implied. See the License for the specific language governing +// permissions and limitations under the License. + +package firecracker + +import ( + "context" +) + +// This ensures the interface method signatures match that of Machine +var _ MachineIface = (*Machine)(nil) + +// MachineIface can be used for mocking and testing of the Machine. The Machine +// is subject to change, meaning this interface would change. +type MachineIface interface { + Start(context.Context) error + StopVMM() error + Shutdown(context.Context) error + Wait(context.Context) error + SetMetadata(context.Context, interface{}) error + UpdateGuestDrive(context.Context, string, string, ...PatchGuestDriveByIDOpt) error +} diff --git a/vendor/github.com/firecracker-microvm/firecracker-go-sdk/rate_limiter.go b/vendor/github.com/firecracker-microvm/firecracker-go-sdk/rate_limiter.go index f61d457aa..bf3537c14 100644 --- a/vendor/github.com/firecracker-microvm/firecracker-go-sdk/rate_limiter.go +++ b/vendor/github.com/firecracker-microvm/firecracker-go-sdk/rate_limiter.go @@ -1,3 +1,16 @@ +// Copyright 2018-2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"). You may +// not use this file except in compliance with the License. A copy of the +// License is located at +// +// http://aws.amazon.com/apache2.0/ +// +// or in the "license" file accompanying this file. This file is distributed +// on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either +// express or implied. See the License for the specific language governing +// permissions and limitations under the License. + package firecracker import ( diff --git a/vendor/github.com/firecracker-microvm/firecracker-go-sdk/swagger.go b/vendor/github.com/firecracker-microvm/firecracker-go-sdk/swagger.go index 745d1dabd..eb853b342 100644 --- a/vendor/github.com/firecracker-microvm/firecracker-go-sdk/swagger.go +++ b/vendor/github.com/firecracker-microvm/firecracker-go-sdk/swagger.go @@ -16,8 +16,8 @@ // --skip-validation is used in the command-lines below to remove the network dependency that the swagger generator has // in attempting to validate that the email address specified in the yaml file is valid. -//go:generate docker run --rm --net=none -v $PWD:/work -w /work quay.io/goswagger/swagger generate model -f ./client/swagger.yaml -T ./templates --model-package=client/models --client-package=client --copyright-file=COPYRIGHT_HEADER --skip-validation -//go:generate docker run --rm --net=none -v $PWD:/work -w /work quay.io/goswagger/swagger generate client -f ./client/swagger.yaml -T ./templates --model-package=client/models --client-package=client --copyright-file=COPYRIGHT_HEADER --skip-validation -//go:generate docker run --rm --net=none -v $PWD:/work -w /work quay.io/goswagger/swagger generate client -f ./client/swagger.yaml -C ./go_swagger_layout.yaml -T ./templates --model-package=client/models --client-package=fctesting --copyright-file=COPYRIGHT_HEADER --skip-validation +//go:generate docker run --add-host github.com:127.1.1.1 --rm --net=none -v $PWD:/work -w /work quay.io/goswagger/swagger generate model -f ./client/swagger.yaml -T ./templates --model-package=client/models --client-package=client --copyright-file=COPYRIGHT_HEADER --skip-validation +//go:generate docker run --add-host github.com:127.1.1.1 --rm --net=none -v $PWD:/work -w /work quay.io/goswagger/swagger generate client -f ./client/swagger.yaml -T ./templates --model-package=client/models --client-package=client --copyright-file=COPYRIGHT_HEADER --skip-validation +//go:generate docker run --add-host github.com:127.1.1.1 --rm --net=none -v $PWD:/work -w /work quay.io/goswagger/swagger generate client -f ./client/swagger.yaml -C ./go_swagger_layout.yaml -T ./templates --model-package=client/models --client-package=fctesting --copyright-file=COPYRIGHT_HEADER --skip-validation package firecracker diff --git a/vendor/github.com/firecracker-microvm/firecracker-go-sdk/utils.go b/vendor/github.com/firecracker-microvm/firecracker-go-sdk/utils.go index 7284ba744..7763b68e0 100644 --- a/vendor/github.com/firecracker-microvm/firecracker-go-sdk/utils.go +++ b/vendor/github.com/firecracker-microvm/firecracker-go-sdk/utils.go @@ -21,7 +21,7 @@ func waitForAliveVMM(ctx context.Context, client *Client) error { case <-ctx.Done(): return ctx.Err() case <-t.C: - if _, err := client.GetMachineConfig(); err == nil { + if _, err := client.GetMachineConfiguration(); err == nil { return nil } } diff --git a/vendor/github.com/firecracker-microvm/firecracker-go-sdk/version.go b/vendor/github.com/firecracker-microvm/firecracker-go-sdk/version.go index 24d1712df..86f8b0231 100644 --- a/vendor/github.com/firecracker-microvm/firecracker-go-sdk/version.go +++ b/vendor/github.com/firecracker-microvm/firecracker-go-sdk/version.go @@ -14,4 +14,4 @@ package firecracker // Version represents the current version of the SDK. -const Version = "0.15.1" +const Version = "0.17.0" diff --git a/vendor/modules.txt b/vendor/modules.txt index b3e1886bc..9998b7a49 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -48,7 +48,7 @@ github.com/docker/go-connections/sockets github.com/docker/go-connections/tlsconfig # github.com/docker/go-units v0.3.3 github.com/docker/go-units -# github.com/firecracker-microvm/firecracker-go-sdk v0.15.1 +# github.com/firecracker-microvm/firecracker-go-sdk v0.15.2-0.20190627223500-b2e8284e890c github.com/firecracker-microvm/firecracker-go-sdk github.com/firecracker-microvm/firecracker-go-sdk/client/models github.com/firecracker-microvm/firecracker-go-sdk/client