Add kpod version

Signed-off-by: umohnani8 <umohnani@redhat.com>
This commit is contained in:
umohnani8 2017-06-16 12:27:06 -04:00
parent 91977d3989
commit 9595d7900e
7 changed files with 107 additions and 2 deletions

View file

@ -14,6 +14,9 @@ ETCDIR_CRIO ?= ${ETCDIR}/crio
BUILDTAGS := selinux seccomp $(shell hack/btrfs_tag.sh) $(shell hack/libdm_tag.sh)
BASHINSTALLDIR=${PREFIX}/share/bash-completion/completions
GIT_COMMIT := $(shell git rev-parse --short HEAD)
BUILD_INFO := $(shell date +%s)
# If GOPATH not specified, use one in the local directory
ifeq ($(GOPATH),)
export GOPATH := $(CURDIR)/_output
@ -25,6 +28,8 @@ GOPKGBASEDIR := $(shell dirname "$(GOPKGDIR)")
# Update VPATH so make finds .gopathok
VPATH := $(VPATH):$(GOPATH)
LDFLAGS := -ldflags '-X main.gitCommit=${GIT_COMMIT} -X main.buildInfo=${BUILD_INFO}'
all: binaries crio.conf docs
default: help
@ -77,7 +82,7 @@ crioctl: .gopathok $(shell hack/find-godeps.sh $(GOPKGDIR) cmd/crioctl $(PROJECT
$(GO) build -o $@ $(PROJECT)/cmd/crioctl
kpod: .gopathok $(shell hack/find-godeps.sh $(GOPKGDIR) cmd/kpod $(PROJECT))
$(GO) build -o $@ $(PROJECT)/cmd/kpod
$(GO) build $(LDFLAGS) -o $@ $(PROJECT)/cmd/kpod
crio.conf: crio
./crio --config="" config --default > crio.conf

View file

@ -7,14 +7,18 @@ import (
"github.com/urfave/cli"
)
//Version of kpod
const Version string = "0.0.1"
func main() {
app := cli.NewApp()
app.Name = "kpod"
app.Usage = "manage pods and images"
app.Version = "0.0.1"
app.Version = Version
app.Commands = []cli.Command{
launchCommand,
versionCommand,
}
if err := app.Run(os.Args); err != nil {

43
cmd/kpod/version.go Normal file
View file

@ -0,0 +1,43 @@
package main
import (
"fmt"
"runtime"
"strconv"
"time"
"github.com/urfave/cli"
)
// Overwritten at build time
var (
gitCommit string
buildInfo string
)
// versionCmd gets and prints version info for version command
func versionCmd(c *cli.Context) error {
// Converts unix time from string to int64
buildTime, err := strconv.ParseInt(buildInfo, 10, 64)
if err != nil {
return err
}
fmt.Println("Version: ", Version)
fmt.Println("Go Version: ", runtime.Version())
fmt.Println("Git Commit: ", gitCommit)
// Prints out the build time in readable format
fmt.Println("Built: ", time.Unix(buildTime, 0).Format(time.ANSIC))
fmt.Println("OS/Arch: ", runtime.GOOS+"/"+runtime.GOARCH)
return nil
}
// Cli command to print out the full version of kpod
var versionCommand = cli.Command{
Name: "version",
Usage: "Display the KPOD Version Information",
Action: versionCmd,
}

View file

@ -27,6 +27,14 @@ _kpod_launch() {
_complete_ "$options_with_args" "$boolean_options"
}
_kpod_version() {
local options_with_args="
"
local boolean_options="
"
_complete_ "$options_with_args" "$boolean_options"
}
_kpod_kpod() {
local options_with_args="
"
@ -36,6 +44,7 @@ _kpod_kpod() {
"
commands="
launch
version
"
case "$prev" in

33
docs/kpod-version.1.md Normal file
View file

@ -0,0 +1,33 @@
% kpod(8) # kpod-version - Simple tool to view version information
% Dan Walsh
% SEPTEMBER 2016
# NAME
kpod-version - Display the KPOD Version Information
# SYNOPSIS
**kpod version**
[**--help**|**-h**]
# DESCRIPTION
Shows the the following information: Version, Go Version, Git Commit, Build Time,
OS, and Architecture.
**kpod [GLOBAL OPTIONS]**
**kpod [GLOBAL OPTIONS] version [OPTIONS]**
# GLOBAL OPTIONS
**--help, -h**
Print usage statement
# COMMANDS
## version
Display the KPOD Version Information
# SEE ALSO
kpod(1), crio(8), crio.conf(5)
# HISTORY
Dec 2016, Originally compiled by Dan Walsh <dwalsh@redhat.com>

View file

@ -13,6 +13,8 @@ CRIO_ROOT=${CRIO_ROOT:-$(cd "$INTEGRATION_ROOT/../.."; pwd -P)}
CRIO_BINARY=${CRIO_BINARY:-${CRIO_ROOT}/cri-o/crio}
# Path of the crioctl binary.
OCIC_BINARY=${OCIC_BINARY:-${CRIO_ROOT}/cri-o/crioctl}
# Path to kpod binary.
KPOD_BINARY=${KPOD_BINARY:-${CRIO_ROOT}/cri-o/kpod}
# Path of the conmon binary.
CONMON_BINARY=${CONMON_BINARY:-${CRIO_ROOT}/cri-o/conmon/conmon}
# Path of the pause binary.

9
test/kpod.bats Normal file
View file

@ -0,0 +1,9 @@
#!/usr/bin/env bats
load helpers
@test "kpod version test" {
run ${KPOD_BINARY} version
echo "$output"
[ "$status" -eq 0 ]
}