Repository: firecracker-microvm/firecracker-containerd
Pull request #221 (2019-07-10 22:18:31)

Adding support for v0.17.0 of the SDK
This updates to use the newest version of the SDK which unconvered an
issue with one of the context that was passed during machine creation.
Originally it was using the request context which is a short lived
context and was causing the VM to be killed during execution. To fix
that the shim context is now used.

Signed-off-by: xibz <impactbchang@gmail.com>


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.



Patch:
diff --git a/go.mod b/go.mod
index e4d0107..f2b1d9e 100644
--- a/go.mod
+++ b/go.mod
@@ -17,7 +17,7 @@ require (
 	github.com/docker/go-events v0.0.0-20170721190031-9461782956ad // indirect
 	github.com/docker/go-metrics v0.0.0-20181218153428-b84716841b82 // indirect
 	github.com/docker/go-units v0.3.3
-	github.com/firecracker-microvm/firecracker-go-sdk v0.15.2-0.20190410183546-4f11ac73a965
+	github.com/firecracker-microvm/firecracker-go-sdk v0.15.2-0.20190627223500-b2e8284e890c
 	github.com/go-ole/go-ole v1.2.4 // indirect
 	github.com/godbus/dbus v0.0.0-20181025153459-66d97aec3384 // indirect
 	github.com/gofrs/uuid v3.2.0+incompatible
diff --git a/go.sum b/go.sum
index dc87684..85fec04 100644
--- a/go.sum
+++ b/go.sum
@@ -44,8 +44,8 @@ github.com/docker/go-metrics v0.0.0-20181218153428-b84716841b82 h1:X0fj836zx99zF
 github.com/docker/go-metrics v0.0.0-20181218153428-b84716841b82/go.mod h1:/u0gXw0Gay3ceNrsHubL3BtdOL2fHf93USgMTe0W5dI=
 github.com/docker/go-units v0.3.3 h1:Xk8S3Xj5sLGlG5g67hJmYMmUgXv5N4PhkjJHHqrwnTk=
 github.com/docker/go-units v0.3.3/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk=
-github.com/firecracker-microvm/firecracker-go-sdk v0.15.2-0.20190410183546-4f11ac73a965 h1:QKioOzqmg7DY/YDhGLYZsP8bq2T3BahVHdyPsf0uq/E=
-github.com/firecracker-microvm/firecracker-go-sdk v0.15.2-0.20190410183546-4f11ac73a965/go.mod h1:QcNsz2gYkcTI/zAQl3dYeLwf7KxtjKnt7aGklhn9yYk=
+github.com/firecracker-microvm/firecracker-go-sdk v0.15.2-0.20190627223500-b2e8284e890c h1:jAAxKV5SD/y2nNKNLHgAUmfgbrvfN4xBiKR+b2qK2pM=
+github.com/firecracker-microvm/firecracker-go-sdk v0.15.2-0.20190627223500-b2e8284e890c/go.mod h1:QcNsz2gYkcTI/zAQl3dYeLwf7KxtjKnt7aGklhn9yYk=
 github.com/globalsign/mgo v0.0.0-20180905125535-1ca0a4f7cbcb h1:D4uzjWwKYQ5XnAvUbuvHW93esHg7F8N/OYeBBcJoTr0=
 github.com/globalsign/mgo v0.0.0-20180905125535-1ca0a4f7cbcb/go.mod h1:xkRDCp4j0OGD1HRkm4kmhM+pmpv3AKq5SU7GMg4oO/Q=
 github.com/go-ole/go-ole v1.2.4 h1:nNBDSCOigTSiarFpYE9J/KtEA1IOW4CNeqT9TQDqCxI=
diff --git a/runtime/helpers.go b/runtime/helpers.go
index 75a8a5c..dbe9974 100644
--- a/runtime/helpers.go
+++ b/runtime/helpers.go
@@ -25,8 +25,9 @@ import (
 func machineConfigurationFromProto(cfg *Config, req *proto.FirecrackerMachineConfiguration) models.MachineConfiguration {
 	config := models.MachineConfiguration{
 		CPUTemplate: models.CPUTemplate(cfg.CPUTemplate),
-		VcpuCount:   int64(cfg.CPUCount),
-		MemSizeMib:  defaultMemSizeMb,
+		VcpuCount:   firecracker.Int64(int64(cfg.CPUCount)),
+		MemSizeMib:  firecracker.Int64(defaultMemSizeMb),
+		HtEnabled:   firecracker.Bool(cfg.HtEnabled),
 	}
 
 	if req == nil {
@@ -38,14 +39,14 @@ func machineConfigurationFromProto(cfg *Config, req *proto.FirecrackerMachineCon
 	}
 
 	if count := req.VcpuCount; count > 0 {
-		config.VcpuCount = int64(count)
+		config.VcpuCount = firecracker.Int64(int64(count))
 	}
 
 	if size := req.MemSizeMib; size > 0 {
-		config.MemSizeMib = int64(size)
+		config.MemSizeMib = firecracker.Int64(int64(size))
 	}
 
-	config.HtEnabled = req.HtEnabled
+	config.HtEnabled = firecracker.Bool(req.HtEnabled)
 
 	return config
 }
diff --git a/runtime/service.go b/runtime/service.go
index f851219..700e064 100644
--- a/runtime/service.go
+++ b/runtime/service.go
@@ -488,7 +488,7 @@ func (s *service) createVM(requestCtx context.Context, request *proto.CreateVMRe
 		return errors.Wrapf(err, "failed to close vsock")
 	}
 
-	if err = s.machine.Start(requestCtx); err != nil {
+	if err = s.machine.Start(s.shimCtx); err != nil {
 		return errors.Wrapf(err, "failed to start the VM")
 	}
 
diff --git a/tools/docker/Dockerfile b/tools/docker/Dockerfile
index d743714..af33802 100644
--- a/tools/docker/Dockerfile
+++ b/tools/docker/Dockerfile
@@ -86,7 +86,7 @@ RUN --mount=type=cache,from=build-base,source=/home/builder/cargo/registry,targe
 	source ${CARGO_HOME}/env \
 	&& git clone https://github.com/firecracker-microvm/firecracker.git \
 	&& cd firecracker \
-	&& git checkout v0.15.2 \
+	&& git checkout v0.17.0 \
 	&& cargo build --release --features vsock --target x86_64-unknown-linux-musl \
 	&& cp target/x86_64-unknown-linux-musl/release/firecracker /output \
 	&& cp target/x86_64-unknown-linux-musl/release/jailer /output
@@ -138,8 +138,6 @@ RUN --mount=type=cache,from=build-base,source=/home/builder/go/pkg/mod,target=/h
 #
 #########################################
 
-
-
 # Build a rootfs for the microVM, including runc and firecracker-containerd's agent
 FROM alpine:3.8 as firecracker-vm-root
 COPY _submodules/runc/runc /usr/local/bin


Test patch:
diff --git a/runtime/helpers_test.go b/runtime/helpers_test.go
index f93926e..2818079 100644
--- a/runtime/helpers_test.go
+++ b/runtime/helpers_test.go
@@ -49,9 +49,9 @@ func TestMachineConfigurationFromProto(t *testing.T) {
 			},
 			expectedMachineConfig: models.MachineConfiguration{
 				CPUTemplate: models.CPUTemplateC3,
-				VcpuCount:   vcpuCount,
-				MemSizeMib:  memSize,
-				HtEnabled:   true,
+				VcpuCount:   firecracker.Int64(vcpuCount),
+				MemSizeMib:  firecracker.Int64(memSize),
+				HtEnabled:   firecracker.Bool(true),
 			},
 		},
 		{
@@ -63,9 +63,9 @@ func TestMachineConfigurationFromProto(t *testing.T) {
 			proto: &proto.FirecrackerMachineConfiguration{},
 			expectedMachineConfig: models.MachineConfiguration{
 				CPUTemplate: models.CPUTemplateC3,
-				VcpuCount:   vcpuCount,
-				MemSizeMib:  defaultMemSizeMb,
-				HtEnabled:   false,
+				VcpuCount:   firecracker.Int64(vcpuCount),
+				MemSizeMib:  firecracker.Int64(defaultMemSizeMb),
+				HtEnabled:   firecracker.Bool(false),
 			},
 		},
 		{
@@ -76,9 +76,9 @@ func TestMachineConfigurationFromProto(t *testing.T) {
 			},
 			expectedMachineConfig: models.MachineConfiguration{
 				CPUTemplate: models.CPUTemplateC3,
-				VcpuCount:   vcpuCount,
-				MemSizeMib:  defaultMemSizeMb,
-				HtEnabled:   false,
+				VcpuCount:   firecracker.Int64(vcpuCount),
+				MemSizeMib:  firecracker.Int64(defaultMemSizeMb),
+				HtEnabled:   firecracker.Bool(false),
 			},
 		},
 		{
@@ -95,9 +95,9 @@ func TestMachineConfigurationFromProto(t *testing.T) {
 			},
 			expectedMachineConfig: models.MachineConfiguration{
 				CPUTemplate: models.CPUTemplateC3,
-				VcpuCount:   vcpuCount,
-				MemSizeMib:  memSize,
-				HtEnabled:   true,
+				VcpuCount:   firecracker.Int64(vcpuCount),
+				MemSizeMib:  firecracker.Int64(memSize),
+				HtEnabled:   firecracker.Bool(true),
 			},
 		},
 	}
diff --git a/runtime/service_test.go b/runtime/service_test.go
index ad817d4..4445176 100644
--- a/runtime/service_test.go
+++ b/runtime/service_test.go
@@ -95,8 +95,9 @@ func TestBuildVMConfiguration(t *testing.T) {
 				},
 				MachineCfg: models.MachineConfiguration{
 					CPUTemplate: models.CPUTemplateC3,
-					VcpuCount:   2,
-					MemSizeMib:  defaultMemSizeMb,
+					VcpuCount:   firecracker.Int64(2),
+					MemSizeMib:  firecracker.Int64(defaultMemSizeMb),
+					HtEnabled:   firecracker.Bool(false),
 				},
 			},
 		},
@@ -128,8 +129,9 @@ func TestBuildVMConfiguration(t *testing.T) {
 				},
 				MachineCfg: models.MachineConfiguration{
 					CPUTemplate: models.CPUTemplateC3,
-					VcpuCount:   2,
-					MemSizeMib:  defaultMemSizeMb,
+					VcpuCount:   firecracker.Int64(2),
+					MemSizeMib:  firecracker.Int64(defaultMemSizeMb),
+					HtEnabled:   firecracker.Bool(false),
 				},
 			},
 		},
@@ -165,8 +167,9 @@ func TestBuildVMConfiguration(t *testing.T) {
 				},
 				MachineCfg: models.MachineConfiguration{
 					CPUTemplate: models.CPUTemplateT2,
-					VcpuCount:   3,
-					MemSizeMib:  defaultMemSizeMb,
+					VcpuCount:   firecracker.Int64(3),
+					MemSizeMib:  firecracker.Int64(defaultMemSizeMb),
+					HtEnabled:   firecracker.Bool(false),
 				},
 			},
 		},