mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-06-25 15:02:45 +00:00
kata-monitor: add version subcommand
This add a subcommand/options for `kata-monitor` command. Fixes: #1004 Signed-off-by: bin liu <bin@hyper.sh>
This commit is contained in:
parent
d80e479ca2
commit
993a8da3aa
@ -603,8 +603,9 @@ $(SHIMV2_OUTPUT): $(SOURCES) $(GENERATED_FILES) $(MAKEFILE_LIST)
|
|||||||
$(QUIET_BUILD)(cd $(SHIMV2_DIR)/ && ln -fs $(GENERATED_CONFIG))
|
$(QUIET_BUILD)(cd $(SHIMV2_DIR)/ && ln -fs $(GENERATED_CONFIG))
|
||||||
$(QUIET_BUILD)(cd $(SHIMV2_DIR)/ && go build $(KATA_LDFLAGS) $(BUILDFLAGS) -o $@ .)
|
$(QUIET_BUILD)(cd $(SHIMV2_DIR)/ && go build $(KATA_LDFLAGS) $(BUILDFLAGS) -o $@ .)
|
||||||
|
|
||||||
$(MONITOR_OUTPUT): $(SOURCES) $(GENERATED_FILES) $(MAKEFILE_LIST)
|
$(MONITOR_OUTPUT): $(SOURCES) $(GENERATED_FILES) $(MAKEFILE_LIST) .git-commit
|
||||||
$(QUIET_BUILD)(cd $(MONITOR_DIR)/ && go build $(KATA_LDFLAGS) $(BUILDFLAGS) -o $@ .)
|
$(QUIET_BUILD)(cd $(MONITOR_DIR)/ && go build \
|
||||||
|
--ldflags "-X main.GitCommit=$(shell cat .git-commit)" -o $@ .)
|
||||||
|
|
||||||
.PHONY: \
|
.PHONY: \
|
||||||
check \
|
check \
|
||||||
|
@ -9,6 +9,8 @@ import (
|
|||||||
"flag"
|
"flag"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
|
"runtime"
|
||||||
|
"text/template"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
kataMonitor "github.com/kata-containers/kata-containers/src/runtime/pkg/kata-monitor"
|
kataMonitor "github.com/kata-containers/kata-containers/src/runtime/pkg/kata-monitor"
|
||||||
@ -20,12 +22,77 @@ var containerdAddr = flag.String("containerd-address", "/run/containerd/containe
|
|||||||
var containerdConfig = flag.String("containerd-conf", "/etc/containerd/config.toml", "Containerd config file.")
|
var containerdConfig = flag.String("containerd-conf", "/etc/containerd/config.toml", "Containerd config file.")
|
||||||
var logLevel = flag.String("log-level", "info", "Log level of logrus(trace/debug/info/warn/error/fatal/panic).")
|
var logLevel = flag.String("log-level", "info", "Log level of logrus(trace/debug/info/warn/error/fatal/panic).")
|
||||||
|
|
||||||
|
// These values are overridden via ldflags
|
||||||
|
var (
|
||||||
|
appName = "kata-monitor"
|
||||||
|
// version is the kata monitor version.
|
||||||
|
version = "0.1.0"
|
||||||
|
|
||||||
|
GitCommit = "unknown-commit"
|
||||||
|
)
|
||||||
|
|
||||||
|
type versionInfo struct {
|
||||||
|
AppName string
|
||||||
|
Version string
|
||||||
|
GitCommit string
|
||||||
|
GoVersion string
|
||||||
|
Os string
|
||||||
|
Arch string
|
||||||
|
}
|
||||||
|
|
||||||
|
var versionTemplate = `{{.AppName}}
|
||||||
|
Version: {{.Version}}
|
||||||
|
Go version: {{.GoVersion}}
|
||||||
|
Git commit: {{.GitCommit}}
|
||||||
|
OS/Arch: {{.Os}}/{{.Arch}}
|
||||||
|
`
|
||||||
|
|
||||||
|
func printVersion(ver versionInfo) {
|
||||||
|
t, err := template.New("version").Parse(versionTemplate)
|
||||||
|
|
||||||
|
if err = t.Execute(os.Stdout, ver); err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
ver := versionInfo{
|
||||||
|
AppName: appName,
|
||||||
|
Version: version,
|
||||||
|
GoVersion: runtime.Version(),
|
||||||
|
Os: runtime.GOOS,
|
||||||
|
Arch: runtime.GOARCH,
|
||||||
|
GitCommit: GitCommit,
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(os.Args) == 2 && (os.Args[1] == "--version" || os.Args[1] == "version") {
|
||||||
|
printVersion(ver)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
// init logrus
|
// init logrus
|
||||||
initLog()
|
initLog()
|
||||||
|
|
||||||
|
announceFields := logrus.Fields{
|
||||||
|
// properties from version info
|
||||||
|
"app": ver.AppName,
|
||||||
|
"version": ver.Version,
|
||||||
|
"go-version": ver.GoVersion,
|
||||||
|
"os": ver.Os,
|
||||||
|
"arch": ver.Arch,
|
||||||
|
"git-commit": ver.GitCommit,
|
||||||
|
|
||||||
|
// properties from command-line options
|
||||||
|
"listen-address": *monitorListenAddr,
|
||||||
|
"containerd-address": *containerdAddr,
|
||||||
|
"containerd-conf": *containerdConfig,
|
||||||
|
"log-level": *logLevel,
|
||||||
|
}
|
||||||
|
|
||||||
|
logrus.WithFields(announceFields).Info("announce")
|
||||||
|
|
||||||
// create new kataMonitor
|
// create new kataMonitor
|
||||||
km, err := kataMonitor.NewKataMonitor(*containerdAddr, *containerdConfig)
|
km, err := kataMonitor.NewKataMonitor(*containerdAddr, *containerdConfig)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Loading…
Reference in New Issue
Block a user