From 9bb8e36aef7b00e64a099a2c64ef87042bbf12cd Mon Sep 17 00:00:00 2001 From: "James O. D. Hunt" Date: Mon, 17 Aug 2020 17:46:48 +0100 Subject: [PATCH] shimv2: Add a "--version" cli option All components should support a `--version` option to allow clear identification of the version of the component being used. Note that the build changes are required to allow the shim binary to access the golang code generated by the build (such as the `version` variable). Fixes: #2886. Signed-off-by: James O. D. Hunt --- Makefile | 1 + cli/containerd-shim-kata-v2/main.go | 12 +++++++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 71c07ecd4a..49e5745947 100644 --- a/Makefile +++ b/Makefile @@ -718,6 +718,7 @@ clean: $(GENERATED_FILES) \ $(NETMON_TARGET) \ $(SHIMV2) \ + $(SHIMV2_DIR)/$(notdir $(GENERATED_CONFIG)) \ $(TARGET) \ .git-commit .git-commit.tmp diff --git a/cli/containerd-shim-kata-v2/main.go b/cli/containerd-shim-kata-v2/main.go index 03ce932ee8..88319834bf 100644 --- a/cli/containerd-shim-kata-v2/main.go +++ b/cli/containerd-shim-kata-v2/main.go @@ -6,15 +6,25 @@ package main import ( + "fmt" + "os" + "github.com/containerd/containerd/runtime/v2/shim" "github.com/kata-containers/runtime/containerd-shim-v2" ) +const shimID = "io.containerd.kata.v2" + func shimConfig(config *shim.Config) { config.NoReaper = true config.NoSubreaper = true } func main() { - shim.Run("io.containerd.kata.v2", containerdshim.New, shimConfig) + if len(os.Args) == 2 && os.Args[1] == "--version" { + fmt.Printf("%s containerd shim: id: %q, version: %s, commit: %v\n", project, shimID, version, commit) + os.Exit(0) + } + + shim.Run(shimID, containerdshim.New, shimConfig) }