Repository: firecracker-microvm/firecracker-containerd
Pull request #222 (2019-07-11 20:30:50)

Update getting started
Signed-off-by: Maksym Pavlenko <makpav@amazon.com>

*Description of changes:*
This PR updates getting started guide with info about containerd's default labels.
It allows to specify `--runtime` and `--snapshotter` flags just once when creating a namespace (or add labels to an existing one), and then just use `ctr` without these params.

ref: https://github.com/containerd/containerd/pull/3403

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/docs/getting-started.md b/docs/getting-started.md
index 62abbad..20cdfb1 100644
--- a/docs/getting-started.md
+++ b/docs/getting-started.md
@@ -236,3 +236,20 @@ $ sudo ctr --address /run/firecracker-containerd/containerd.sock \
   run --snapshotter firecracker-naive --runtime aws.firecracker --tty \
   docker.io/library/busybox:latest busybox-test
 ```
+
+Alternatively you can specify `--runtime` and `--snapshotter` just once when creating a new namespace using containerd's default labels:
+
+```bash
+$ sudo ctr --address /run/firecracker-containerd/containerd.sock \
+  namespaces create fc
+
+$ sudo ctr --address /run/firecracker-containerd/containerd.sock \
+  namespaces label fc \
+  containerd.io/defaults/runtime=aws.firecracker \
+  containerd.io/defaults/snapshotter=firecracker-naive
+
+$ sudo ctr --address /run/firecracker-containerd/containerd.sock \
+  -n fc \
+  run --tty \
+  docker.io/library/busybox:latest busybox-test
+```
diff --git a/go.mod b/go.mod
index f2b1d9e..7583263 100644
--- a/go.mod
+++ b/go.mod
@@ -6,7 +6,7 @@ require (
 	github.com/StackExchange/wmi v0.0.0-20181212234831-e0a55b97c705 // indirect
 	github.com/containerd/cgroups v0.0.0-20181105182409-82cb49fc1779 // indirect
 	github.com/containerd/console v0.0.0-20181022165439-0650fd9eeb50 // indirect
-	github.com/containerd/containerd v1.2.1-0.20190626153021-bb9616ba206c
+	github.com/containerd/containerd v1.2.1-0.20190711201753-f2b6c31d0fa7
 	github.com/containerd/continuity v0.0.0-20181027224239-bea7585dbfac
 	github.com/containerd/fifo v0.0.0-20180307165137-3d5202aec260
 	github.com/containerd/go-runc v0.0.0-20190226155025-7d11b49dc076 // indirect
@@ -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.20190627223500-b2e8284e890c
+	github.com/firecracker-microvm/firecracker-go-sdk v0.15.2-0.20190410183546-4f11ac73a965
 	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 85fec04..564cc53 100644
--- a/go.sum
+++ b/go.sum
@@ -20,8 +20,8 @@ github.com/containerd/cgroups v0.0.0-20181105182409-82cb49fc1779 h1:j1IsLW6/hNZP
 github.com/containerd/cgroups v0.0.0-20181105182409-82cb49fc1779/go.mod h1:X9rLEHIqSf/wfK8NsPqxJmeZgW4pcfzdXITDrUSJ6uI=
 github.com/containerd/console v0.0.0-20181022165439-0650fd9eeb50 h1:WMpHmC6AxwWb9hMqhudkqG7A/p14KiMnl6d3r1iUMjU=
 github.com/containerd/console v0.0.0-20181022165439-0650fd9eeb50/go.mod h1:Tj/on1eG8kiEhd0+fhSDzsPAFESxzBBvdyEgyryXffw=
-github.com/containerd/containerd v1.2.1-0.20190626153021-bb9616ba206c h1:m/ToFT22QUZDGCSrSwiayu75/NDnTWIeHGNY770sLiU=
-github.com/containerd/containerd v1.2.1-0.20190626153021-bb9616ba206c/go.mod h1:bC6axHOhabU15QhwfG7w5PipXdVtMXFTttgp+kVtyUA=
+github.com/containerd/containerd v1.2.1-0.20190711201753-f2b6c31d0fa7 h1:oIh8usyIH8KVp/+g15ki0h9wizhWZraz5l5AKu9wGqM=
+github.com/containerd/containerd v1.2.1-0.20190711201753-f2b6c31d0fa7/go.mod h1:bC6axHOhabU15QhwfG7w5PipXdVtMXFTttgp+kVtyUA=
 github.com/containerd/continuity v0.0.0-20181027224239-bea7585dbfac h1:PThQaO4yCvJzJBUW1XoFQxLotWRhvX2fgljJX8yrhFI=
 github.com/containerd/continuity v0.0.0-20181027224239-bea7585dbfac/go.mod h1:GL3xCUCBDV3CZiTSEKksMWbLE66hEyuu9qyDOOqM47Y=
 github.com/containerd/fifo v0.0.0-20180307165137-3d5202aec260 h1:XGyg7oTtD0DoRFhbpV6x1WfV0flKC4UxXU7ab1zC08U=
@@ -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.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/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/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 dbe9974..75a8a5c 100644
--- a/runtime/helpers.go
+++ b/runtime/helpers.go
@@ -25,9 +25,8 @@ import (
 func machineConfigurationFromProto(cfg *Config, req *proto.FirecrackerMachineConfiguration) models.MachineConfiguration {
 	config := models.MachineConfiguration{
 		CPUTemplate: models.CPUTemplate(cfg.CPUTemplate),
-		VcpuCount:   firecracker.Int64(int64(cfg.CPUCount)),
-		MemSizeMib:  firecracker.Int64(defaultMemSizeMb),
-		HtEnabled:   firecracker.Bool(cfg.HtEnabled),
+		VcpuCount:   int64(cfg.CPUCount),
+		MemSizeMib:  defaultMemSizeMb,
 	}
 
 	if req == nil {
@@ -39,14 +38,14 @@ func machineConfigurationFromProto(cfg *Config, req *proto.FirecrackerMachineCon
 	}
 
 	if count := req.VcpuCount; count > 0 {
-		config.VcpuCount = firecracker.Int64(int64(count))
+		config.VcpuCount = int64(count)
 	}
 
 	if size := req.MemSizeMib; size > 0 {
-		config.MemSizeMib = firecracker.Int64(int64(size))
+		config.MemSizeMib = int64(size)
 	}
 
-	config.HtEnabled = firecracker.Bool(req.HtEnabled)
+	config.HtEnabled = req.HtEnabled
 
 	return config
 }
diff --git a/runtime/service.go b/runtime/service.go
index 700e064..2342bed 100644
--- a/runtime/service.go
+++ b/runtime/service.go
@@ -175,11 +175,6 @@ func NewService(shimCtx context.Context, id string, remotePublisher shim.Publish
 		}
 	}
 
-	if config.Debug {
-		logrus.SetLevel(logrus.DebugLevel)
-		logger.Logger.SetLevel(logrus.DebugLevel)
-	}
-
 	s := &service{
 		taskManager:   vm.NewTaskManager(shimCtx, logger),
 		eventExchange: exchange.NewExchange(),
@@ -488,7 +483,7 @@ func (s *service) createVM(requestCtx context.Context, request *proto.CreateVMRe
 		return errors.Wrapf(err, "failed to close vsock")
 	}
 
-	if err = s.machine.Start(s.shimCtx); err != nil {
+	if err = s.machine.Start(requestCtx); err != nil {
 		return errors.Wrapf(err, "failed to start the VM")
 	}
 
@@ -587,8 +582,6 @@ func (s *service) buildVMConfiguration(req *proto.CreateVMRequest) (*firecracker
 		LogFifo:      s.shimDir.FirecrackerLogFifoPath(),
 		MetricsFifo:  s.shimDir.FirecrackerMetricsFifoPath(),
 		MachineCfg:   machineConfigurationFromProto(s.config, req.MachineCfg),
-		LogLevel:     s.config.LogLevel,
-		Debug:        s.config.Debug,
 	}
 
 	logger.Debugf("using socket path: %s", cfg.SocketPath)
diff --git a/tools/docker/Dockerfile b/tools/docker/Dockerfile
index af33802..d743714 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.17.0 \
+	&& git checkout v0.15.2 \
 	&& 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,6 +138,8 @@ 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 2818079..f93926e 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:   firecracker.Int64(vcpuCount),
-				MemSizeMib:  firecracker.Int64(memSize),
-				HtEnabled:   firecracker.Bool(true),
+				VcpuCount:   vcpuCount,
+				MemSizeMib:  memSize,
+				HtEnabled:   true,
 			},
 		},
 		{
@@ -63,9 +63,9 @@ func TestMachineConfigurationFromProto(t *testing.T) {
 			proto: &proto.FirecrackerMachineConfiguration{},
 			expectedMachineConfig: models.MachineConfiguration{
 				CPUTemplate: models.CPUTemplateC3,
-				VcpuCount:   firecracker.Int64(vcpuCount),
-				MemSizeMib:  firecracker.Int64(defaultMemSizeMb),
-				HtEnabled:   firecracker.Bool(false),
+				VcpuCount:   vcpuCount,
+				MemSizeMib:  defaultMemSizeMb,
+				HtEnabled:   false,
 			},
 		},
 		{
@@ -76,9 +76,9 @@ func TestMachineConfigurationFromProto(t *testing.T) {
 			},
 			expectedMachineConfig: models.MachineConfiguration{
 				CPUTemplate: models.CPUTemplateC3,
-				VcpuCount:   firecracker.Int64(vcpuCount),
-				MemSizeMib:  firecracker.Int64(defaultMemSizeMb),
-				HtEnabled:   firecracker.Bool(false),
+				VcpuCount:   vcpuCount,
+				MemSizeMib:  defaultMemSizeMb,
+				HtEnabled:   false,
 			},
 		},
 		{
@@ -95,9 +95,9 @@ func TestMachineConfigurationFromProto(t *testing.T) {
 			},
 			expectedMachineConfig: models.MachineConfiguration{
 				CPUTemplate: models.CPUTemplateC3,
-				VcpuCount:   firecracker.Int64(vcpuCount),
-				MemSizeMib:  firecracker.Int64(memSize),
-				HtEnabled:   firecracker.Bool(true),
+				VcpuCount:   vcpuCount,
+				MemSizeMib:  memSize,
+				HtEnabled:   true,
 			},
 		},
 	}
diff --git a/runtime/service_test.go b/runtime/service_test.go
index 4445176..3d83694 100644
--- a/runtime/service_test.go
+++ b/runtime/service_test.go
@@ -15,7 +15,6 @@ package main
 
 import (
 	"context"
-	"fmt"
 	"io/ioutil"
 	"os"
 	"path/filepath"
@@ -95,9 +94,8 @@ func TestBuildVMConfiguration(t *testing.T) {
 				},
 				MachineCfg: models.MachineConfiguration{
 					CPUTemplate: models.CPUTemplateC3,
-					VcpuCount:   firecracker.Int64(2),
-					MemSizeMib:  firecracker.Int64(defaultMemSizeMb),
-					HtEnabled:   firecracker.Bool(false),
+					VcpuCount:   2,
+					MemSizeMib:  defaultMemSizeMb,
 				},
 			},
 		},
@@ -129,9 +127,8 @@ func TestBuildVMConfiguration(t *testing.T) {
 				},
 				MachineCfg: models.MachineConfiguration{
 					CPUTemplate: models.CPUTemplateC3,
-					VcpuCount:   firecracker.Int64(2),
-					MemSizeMib:  firecracker.Int64(defaultMemSizeMb),
-					HtEnabled:   firecracker.Bool(false),
+					VcpuCount:   2,
+					MemSizeMib:  defaultMemSizeMb,
 				},
 			},
 		},
@@ -167,9 +164,8 @@ func TestBuildVMConfiguration(t *testing.T) {
 				},
 				MachineCfg: models.MachineConfiguration{
 					CPUTemplate: models.CPUTemplateT2,
-					VcpuCount:   firecracker.Int64(3),
-					MemSizeMib:  firecracker.Int64(defaultMemSizeMb),
-					HtEnabled:   firecracker.Bool(false),
+					VcpuCount:   3,
+					MemSizeMib:  defaultMemSizeMb,
 				},
 			},
 		},
@@ -202,65 +198,3 @@ func TestBuildVMConfiguration(t *testing.T) {
 		})
 	}
 }
-
-func TestDebugConfig(t *testing.T) {
-	cases := []struct {
-		name    string
-		service *service
-	}{
-		{
-			name: "empty",
-			service: &service{
-				logger: logrus.NewEntry(logrus.New()),
-				config: &Config{},
-			},
-		},
-		{
-			name: "LogLevel set",
-			service: &service{
-				logger: logrus.NewEntry(logrus.New()),
-				config: &Config{
-					LogLevel: "foo",
-				},
-			},
-		},
-		{
-			name: "Debug set",
-			service: &service{
-				logger: logrus.NewEntry(logrus.New()),
-				config: &Config{
-					Debug: true,
-				},
-			},
-		},
-		{
-			name: "Both set",
-			service: &service{
-				logger: logrus.NewEntry(logrus.New()),
-				config: &Config{
-					LogLevel: "foo",
-					Debug:    true,
-				},
-			},
-		},
-	}
-
-	path, err := ioutil.TempDir("./", "TestDebugConfig")
-	assert.NoError(t, err, "failed to create temp directory")
-
-	defer os.RemoveAll(path)
-
-	for i, c := range cases {
-		c := c
-		stubDrivePath := filepath.Join(path, fmt.Sprintf("%d", i))
-		err := os.MkdirAll(stubDrivePath, os.ModePerm)
-		assert.NoError(t, err, "failed to create stub drive path")
-		c.service.stubDriveHandler = newStubDriveHandler(stubDrivePath, c.service.logger)
-		req := proto.CreateVMRequest{}
-
-		cfg, err := c.service.buildVMConfiguration(&req)
-		assert.NoError(t, err, "failed to build firecracker configuration")
-		assert.Equal(t, c.service.config.LogLevel, cfg.LogLevel)
-		assert.Equal(t, c.service.config.Debug, cfg.Debug)
-	}
-}