mirror of
https://github.com/kyverno/kyverno.git
synced 2025-01-20 18:52:16 +00:00
print version info in main log
This commit is contained in:
parent
a1322276b7
commit
4b568efd70
6 changed files with 47 additions and 17 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -2,3 +2,4 @@ certs
|
||||||
Gopkg.lock
|
Gopkg.lock
|
||||||
.vscode
|
.vscode
|
||||||
gh-pages/public
|
gh-pages/public
|
||||||
|
_output
|
15
Makefile
15
Makefile
|
@ -5,16 +5,17 @@
|
||||||
BIN ?= kyverno
|
BIN ?= kyverno
|
||||||
|
|
||||||
GIT_VERSION := $(shell git describe --dirty --always --tags)
|
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')
|
TIMESTAMP := $(shell date '+%Y-%m-%d_%I:%M:%S%p')
|
||||||
|
|
||||||
PACKAGE ?=github.com/nirmata/kyverno
|
PACKAGE ?=github.com/nirmata/kyverno
|
||||||
MAIN ?=$(PACKAGE)
|
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
|
REPO=registry-v2.nirmata.io/nirmata/kyverno
|
||||||
TAG=0.1
|
IMAGE_TAG=$(GIT_VERSION)
|
||||||
|
|
||||||
GOOS ?= $(shell go env GOOS)
|
GOOS ?= $(shell go env GOOS)
|
||||||
OUTPUT=$(shell pwd)/_output/cli/$(BIN)
|
OUTPUT=$(shell pwd)/_output/cli/$(BIN)
|
||||||
|
@ -36,11 +37,11 @@ cli-dirs:
|
||||||
@mkdir -p _output/cli
|
@mkdir -p _output/cli
|
||||||
|
|
||||||
image:
|
image:
|
||||||
docker build -t $(REPO):$(TAG) .
|
docker build -t $(REPO):$(IMAGE_TAG) .
|
||||||
docker tag $(REPO):$(TAG) $(REPO):latest
|
# docker tag $(REPO):$(IMAGE_TAG) $(REPO):latest
|
||||||
|
|
||||||
push:
|
push:
|
||||||
docker push $(REPO):$(TAG)
|
docker push $(REPO):$(IMAGE_TAG)
|
||||||
docker push $(REPO):latest
|
docker push $(REPO):latest
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
|
|
9
init.go
9
init.go
|
@ -8,11 +8,18 @@ import (
|
||||||
client "github.com/nirmata/kyverno/client"
|
client "github.com/nirmata/kyverno/client"
|
||||||
"github.com/nirmata/kyverno/pkg/config"
|
"github.com/nirmata/kyverno/pkg/config"
|
||||||
tls "github.com/nirmata/kyverno/pkg/tls"
|
tls "github.com/nirmata/kyverno/pkg/tls"
|
||||||
|
"github.com/nirmata/kyverno/pkg/version"
|
||||||
rest "k8s.io/client-go/rest"
|
rest "k8s.io/client-go/rest"
|
||||||
clientcmd "k8s.io/client-go/tools/clientcmd"
|
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) {
|
func createClientConfig(kubeconfig string) (*rest.Config, error) {
|
||||||
if kubeconfig == "" {
|
if kubeconfig == "" {
|
||||||
log.Printf("Using in-cluster configuration")
|
log.Printf("Using in-cluster configuration")
|
||||||
|
|
2
main.go
2
main.go
|
@ -20,6 +20,8 @@ var (
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
printVersionInfo()
|
||||||
|
|
||||||
clientConfig, err := createClientConfig(kubeconfig)
|
clientConfig, err := createClientConfig(kubeconfig)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("Error building kubeconfig: %v\n", err)
|
log.Fatalf("Error building kubeconfig: %v\n", err)
|
||||||
|
|
|
@ -4,15 +4,10 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
|
|
||||||
|
"github.com/nirmata/kyverno/pkg/version"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
|
||||||
buildVersion = "--"
|
|
||||||
buildHash = "--"
|
|
||||||
buildTime = "--"
|
|
||||||
)
|
|
||||||
|
|
||||||
// NewCmdVersion is a command to display the build version
|
// NewCmdVersion is a command to display the build version
|
||||||
func NewCmdVersion(cmdOut io.Writer) *cobra.Command {
|
func NewCmdVersion(cmdOut io.Writer) *cobra.Command {
|
||||||
|
|
||||||
|
@ -28,7 +23,7 @@ func NewCmdVersion(cmdOut io.Writer) *cobra.Command {
|
||||||
}
|
}
|
||||||
|
|
||||||
func showVersion() {
|
func showVersion() {
|
||||||
fmt.Printf("Version: %s\n", buildVersion)
|
fmt.Printf("Version: %s\n", version.BuildVersion)
|
||||||
fmt.Printf("Time: %s\n", buildTime)
|
fmt.Printf("Time: %s\n", version.BuildTime)
|
||||||
fmt.Printf("Git commit ID: %s\n", buildHash)
|
fmt.Printf("Git commit ID: %s\n", version.BuildHash)
|
||||||
}
|
}
|
||||||
|
|
24
pkg/version/version.go
Normal file
24
pkg/version/version.go
Normal 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,
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue