mirror of
https://github.com/kyverno/kyverno.git
synced 2024-12-14 11:57:48 +00:00
Merge pull request #123 from nirmata/119_version
Show version info for each release
This commit is contained in:
commit
81ae5b0eb6
9 changed files with 96 additions and 7 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -2,3 +2,4 @@ certs
|
|||
Gopkg.lock
|
||||
.vscode
|
||||
gh-pages/public
|
||||
_output
|
36
Makefile
36
Makefile
|
@ -1,10 +1,24 @@
|
|||
.DEFAULT_GOAL: build
|
||||
|
||||
|
||||
# The CLI binary to build
|
||||
BIN ?= kyverno
|
||||
|
||||
GIT_VERSION := $(shell git describe --dirty --always --tags)
|
||||
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"
|
||||
|
||||
REPO=nirmata/kyverno
|
||||
TAG=0.1
|
||||
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=registry-v2.nirmata.io/nirmata/kyverno
|
||||
IMAGE_TAG=$(GIT_VERSION)
|
||||
|
||||
GOOS ?= $(shell go env GOOS)
|
||||
OUTPUT=$(shell pwd)/_output/cli/$(BIN)
|
||||
|
||||
build:
|
||||
GOOS=linux go build -ldflags=$(LD_FLAGS) $(MAIN)
|
||||
|
@ -12,12 +26,22 @@ build:
|
|||
local:
|
||||
go build -ldflags=$(LD_FLAGS) $(MAIN)
|
||||
|
||||
cli: cli-dirs
|
||||
GOOS=$(GOOS) \
|
||||
go build \
|
||||
-o $(OUTPUT) \
|
||||
-ldflags $(LD_FLAGS) \
|
||||
$(PACKAGE)/cmd/$(BIN)
|
||||
|
||||
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:
|
||||
|
|
9
init.go
9
init.go
|
@ -5,11 +5,18 @@ import (
|
|||
|
||||
client "github.com/nirmata/kyverno/pkg/dclient"
|
||||
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")
|
||||
|
|
2
main.go
2
main.go
|
@ -18,6 +18,8 @@ var (
|
|||
)
|
||||
|
||||
func main() {
|
||||
printVersionInfo()
|
||||
|
||||
clientConfig, err := createClientConfig(kubeconfig)
|
||||
if err != nil {
|
||||
log.Fatalf("Error building kubeconfig: %v\n", err)
|
||||
|
|
|
@ -5,6 +5,7 @@ import (
|
|||
"os"
|
||||
|
||||
"github.com/nirmata/kyverno/pkg/kyverno/apply"
|
||||
"github.com/nirmata/kyverno/pkg/kyverno/version"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
|
@ -21,5 +22,6 @@ func NewKyvernoCommand(in io.Reader, out, errout io.Writer) *cobra.Command {
|
|||
}
|
||||
|
||||
cmds.AddCommand(apply.NewCmdApply(in, out, errout))
|
||||
cmds.AddCommand(version.NewCmdVersion(out))
|
||||
return cmds
|
||||
}
|
||||
|
|
29
pkg/kyverno/version/version.go
Normal file
29
pkg/kyverno/version/version.go
Normal file
|
@ -0,0 +1,29 @@
|
|||
package version
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
|
||||
"github.com/nirmata/kyverno/pkg/version"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
// NewCmdVersion is a command to display the build version
|
||||
func NewCmdVersion(cmdOut io.Writer) *cobra.Command {
|
||||
|
||||
versionCmd := &cobra.Command{
|
||||
Use: "version",
|
||||
Short: "",
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
showVersion()
|
||||
},
|
||||
}
|
||||
|
||||
return versionCmd
|
||||
}
|
||||
|
||||
func showVersion() {
|
||||
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
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…
Reference in a new issue