Skip to content

Commit

Permalink
Log aws.firecracker's version since supporting -version is hard
Browse files Browse the repository at this point in the history
Because the shim's flag parsing is owned by containerd's shim package,
supporting -version/-v is not straightforward. Instead the binary logs
the version.

Signed-off-by: Kazuyoshi Kato <katokazu@amazon.com>
  • Loading branch information
kzys committed Jan 10, 2020
1 parent 6bef84d commit a731d81
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
4 changes: 3 additions & 1 deletion runtime/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ DOCKER_IMAGE_TAG?=latest
GO_CACHE_VOLUME_NAME?=gocache
FIRECRACKER_CONTAINERD_TEST_IMAGE?=localhost/firecracker-containerd-test

REVISION=$(shell git rev-parse HEAD)

INTEG_TEST_SUFFIX := _Isolated
INTEG_TESTNAMES=$(shell docker run --rm \
--network=none \
Expand All @@ -37,7 +39,7 @@ all: runtime
runtime: containerd-shim-aws-firecracker

containerd-shim-aws-firecracker: $(SOURCES) $(GOMOD) $(GOSUM)
go build -o containerd-shim-aws-firecracker $(EXTRAGOARGS)
go build -o containerd-shim-aws-firecracker $(EXTRAGOARGS) -ldflags "-X main.revision=$(REVISION)"

install: containerd-shim-aws-firecracker
install -D -o root -g root -m755 -t $(INSTALLROOT)/bin containerd-shim-aws-firecracker
Expand Down
2 changes: 2 additions & 0 deletions runtime/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ import (

const shimID = "aws.firecracker"

var revision string

func init() {
logrus.SetFormatter(&logrus.TextFormatter{
TimestampFormat: log.RFC3339NanoFixed,
Expand Down
14 changes: 10 additions & 4 deletions runtime/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -332,10 +332,6 @@ func (s *service) StartShim(shimCtx context.Context, containerID, containerdBina
// task is deleted
containerCount = 1
exitAfterAllTasksDeleted = true

log.Info("will start a single-task VM since no VMID has been provided")
} else {
log.WithField("vmID", s.vmID).Info("will start a persistent VM")
}

client, err := ttrpcutil.NewClient(containerdTTRPCAddress)
Expand All @@ -358,6 +354,16 @@ func (s *service) StartShim(shimCtx context.Context, containerID, containerdBina
}
}

// The shim cannot support traditional -version/-v flag because
// - shim.Run() will call flag.Parse(). So our main cannot call flag.Parse() before that.
// - -address is required and NewService() won't be called if the flag is missing.
// So we log the version informaion here instead
str := ""
if exitAfterAllTasksDeleted {
str = " The VM will be torn down after serving a single task."
}
log.WithField("vmID", s.vmID).Infof("successfully started shim (%s).%s", revision, str)

return fcShim.SocketAddress(shimCtx, s.vmID)
}

Expand Down

0 comments on commit a731d81

Please sign in to comment.