1
0
Fork 0
mirror of https://github.com/kyverno/kyverno.git synced 2024-12-14 11:57:48 +00:00

print version info in main log

This commit is contained in:
shuting 2019-05-29 15:24:19 -07:00
parent a1322276b7
commit 4b568efd70
6 changed files with 47 additions and 17 deletions

1
.gitignore vendored
View file

@ -2,3 +2,4 @@ certs
Gopkg.lock
.vscode
gh-pages/public
_output

View file

@ -5,16 +5,17 @@
BIN ?= kyverno
GIT_VERSION := $(shell git describe --dirty --always --tags)
GIT_HASH := $(shell git log -1 --pretty=format:"%H")
GIT_BRANCH := $(shell git branch | grep \* | cut -d ' ' -f2)
GIT_HASH := $(GIT_BRANCH)/$(shell git log -1 --pretty=format:"%H")
TIMESTAMP := $(shell date '+%Y-%m-%d_%I:%M:%S%p')
PACKAGE ?=github.com/nirmata/kyverno
MAIN ?=$(PACKAGE)
LD_FLAGS="-s -w -X $(PACKAGE)/pkg/kyverno/version.buildVersion=$(GIT_VERSION) -X $(PACKAGE)/pkg/kyverno/version.buildHash=$(GIT_HASH) -X $(PACKAGE)/pkg/kyverno/version.buildTime=$(TIMESTAMP)"
LD_FLAGS="-s -w -X $(PACKAGE)/pkg/version.BuildVersion=$(GIT_VERSION) -X $(PACKAGE)/pkg/version.BuildHash=$(GIT_HASH) -X $(PACKAGE)/pkg/version.BuildTime=$(TIMESTAMP)"
REPO=nirmata/kyverno
TAG=0.1
REPO=registry-v2.nirmata.io/nirmata/kyverno
IMAGE_TAG=$(GIT_VERSION)
GOOS ?= $(shell go env GOOS)
OUTPUT=$(shell pwd)/_output/cli/$(BIN)
@ -36,11 +37,11 @@ cli-dirs:
@mkdir -p _output/cli
image:
docker build -t $(REPO):$(TAG) .
docker tag $(REPO):$(TAG) $(REPO):latest
docker build -t $(REPO):$(IMAGE_TAG) .
# docker tag $(REPO):$(IMAGE_TAG) $(REPO):latest
push:
docker push $(REPO):$(TAG)
docker push $(REPO):$(IMAGE_TAG)
docker push $(REPO):latest
clean:

View file

@ -8,11 +8,18 @@ import (
client "github.com/nirmata/kyverno/client"
"github.com/nirmata/kyverno/pkg/config"
tls "github.com/nirmata/kyverno/pkg/tls"
"github.com/nirmata/kyverno/pkg/version"
rest "k8s.io/client-go/rest"
clientcmd "k8s.io/client-go/tools/clientcmd"
)
func printVersionInfo() {
v := version.GetVersion()
log.Printf("Kyverno version: %s\n", v.BuildVersion)
log.Printf("Kyverno BuildHash: %s\n", v.BuildHash)
log.Printf("Kyverno BuildTime: %s\n", v.BuildTime)
}
func createClientConfig(kubeconfig string) (*rest.Config, error) {
if kubeconfig == "" {
log.Printf("Using in-cluster configuration")

View file

@ -20,6 +20,8 @@ var (
)
func main() {
printVersionInfo()
clientConfig, err := createClientConfig(kubeconfig)
if err != nil {
log.Fatalf("Error building kubeconfig: %v\n", err)

View file

@ -4,15 +4,10 @@ import (
"fmt"
"io"
"github.com/nirmata/kyverno/pkg/version"
"github.com/spf13/cobra"
)
var (
buildVersion = "--"
buildHash = "--"
buildTime = "--"
)
// NewCmdVersion is a command to display the build version
func NewCmdVersion(cmdOut io.Writer) *cobra.Command {
@ -28,7 +23,7 @@ func NewCmdVersion(cmdOut io.Writer) *cobra.Command {
}
func showVersion() {
fmt.Printf("Version: %s\n", buildVersion)
fmt.Printf("Time: %s\n", buildTime)
fmt.Printf("Git commit ID: %s\n", buildHash)
fmt.Printf("Version: %s\n", version.BuildVersion)
fmt.Printf("Time: %s\n", version.BuildTime)
fmt.Printf("Git commit ID: %s\n", version.BuildHash)
}

24
pkg/version/version.go Normal file
View file

@ -0,0 +1,24 @@
package version
// These fields are set during an official build
var (
BuildVersion = "--"
BuildHash = "--"
BuildTime = "--"
)
// VersionInfo gets json info about the agent version
type VersionInfo struct {
BuildVersion string
BuildHash string
BuildTime string
}
// GetVersion gets the current agent version
func GetVersion() *VersionInfo {
return &VersionInfo{
BuildVersion: BuildVersion,
BuildHash: BuildHash,
BuildTime: BuildTime,
}
}