Skip to content

Commit

Permalink
Add -version flag to the in-VM agent
Browse files Browse the repository at this point in the history
Investigating issues like #370 will be easier if the agent can report
the version.

Signed-off-by: Kazuyoshi Kato <katokazu@amazon.com>
  • Loading branch information
kzys committed Jan 9, 2020
1 parent b95b509 commit 5606c60
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
5 changes: 3 additions & 2 deletions agent/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,15 @@ GOMOD := $(shell go env GOMOD)
GOSUM := $(GOMOD:.mod=.sum)
SOURCES:=$(shell find . -name '*.go')
DOCKER_IMAGE_TAG?=latest
VERSION := $(shell git describe --always)

all: agent

agent: *.go $(GOMOD) $(GOSUM)
ifneq ($(STATIC_AGENT),)
CGO_ENABLED=0 go build -installsuffix cgo -a -ldflags "-s" $(EXTRAGOARGS) -o agent
CGO_ENABLED=0 go build -installsuffix cgo -a -ldflags "-s -X main.version=$(VERSION)" $(EXTRAGOARGS) -o agent
else
go build $(EXTRAGOARGS) -o agent
go build $(EXTRAGOARGS) -ldflags "-X main.version=$(VERSION)" -o agent
endif

test:
Expand Down
18 changes: 18 additions & 0 deletions agent/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package main
import (
"context"
"flag"
"fmt"
"os"
"os/signal"
"syscall"
Expand Down Expand Up @@ -47,20 +48,31 @@ const (
enableSubreaper = 1
)

var (
version string
)

func main() {
var (
port int
debug bool
version bool
)

flag.IntVar(&port, "port", defaultPort, "Vsock port to listen to")
flag.BoolVar(&debug, "debug", false, "Turn on debug mode")
flag.BoolVar(&version, "version", false, "Show the version")
flag.Parse()

if debug {
logrus.SetLevel(logrus.DebugLevel)
}

if version {
showVersion()
return
}

signals := make(chan os.Signal, 32)
signal.Notify(signals, syscall.SIGINT, syscall.SIGTERM, unix.SIGCHLD)

Expand Down Expand Up @@ -155,3 +167,9 @@ func main() {
panic(err)
}
}

func showVersion() {
// After Go 1.12, We can use runtime/debug.BuildInfo instead.
// https://github.com/golang/go/issues/22147
fmt.Printf("containerd Firecracker agent %s\n", version)
}

0 comments on commit 5606c60

Please sign in to comment.