mirror of
https://github.com/kyverno/kyverno.git
synced 2025-04-15 08:46:36 +00:00
fix: use golang builtin version management (#7654)
* fix: use golang builtin version management Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com> * fix Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com> --------- Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com>
This commit is contained in:
parent
5ea387e372
commit
43a7c26768
7 changed files with 51 additions and 20 deletions
|
@ -11,7 +11,7 @@ builds:
|
|||
env:
|
||||
- CGO_ENABLED=0
|
||||
ldflags:
|
||||
- -s -w -X github.com/kyverno/kyverno/pkg/version.BuildVersion={{.Version}} -X github.com/kyverno/kyverno/pkg/version.BuildHash={{ .FullCommit }} -X github.com/kyverno/kyverno/pkg/version.BuildTime={{ .Date }}
|
||||
- -s -w -X github.com/kyverno/kyverno/pkg/version.BuildVersion={{.Version}}
|
||||
goos:
|
||||
- linux
|
||||
- darwin
|
||||
|
|
5
Makefile
5
Makefile
|
@ -5,7 +5,6 @@
|
|||
############
|
||||
|
||||
GIT_SHA := $(shell git rev-parse HEAD)
|
||||
TIMESTAMP := $(shell date '+%Y-%m-%d_%I:%M:%S%p')
|
||||
REGISTRY ?= ghcr.io
|
||||
REPO ?= kyverno
|
||||
KIND_IMAGE ?= kindest/node:v1.26.3
|
||||
|
@ -144,9 +143,9 @@ BACKGROUND_BIN := $(BACKGROUND_DIR)/background-controller
|
|||
PACKAGE ?= github.com/kyverno/kyverno
|
||||
CGO_ENABLED ?= 0
|
||||
ifdef VERSION
|
||||
LD_FLAGS := "-s -w -X $(PACKAGE)/pkg/version.BuildVersion=$(VERSION) -X $(PACKAGE)/pkg/version.BuildHash=$(GIT_SHA) -X $(PACKAGE)/pkg/version.BuildTime=$(TIMESTAMP)"
|
||||
LD_FLAGS := "-s -w -X $(PACKAGE)/pkg/version.BuildVersion=$(VERSION)"
|
||||
else
|
||||
LD_FLAGS := "-s -w -X $(PACKAGE)/pkg/version.BuildVersion=$(GIT_SHA) -X $(PACKAGE)/pkg/version.BuildHash=$(GIT_SHA) -X $(PACKAGE)/pkg/version.BuildTime=$(TIMESTAMP)"
|
||||
LD_FLAGS := "-s -w"
|
||||
endif
|
||||
|
||||
.PHONY: fmt
|
||||
|
|
|
@ -14,7 +14,7 @@ import (
|
|||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
const EnableExperimentalEnv = "KYVERNO_EXPERIMENTAL"
|
||||
const enableExperimentalEnv = "KYVERNO_EXPERIMENTAL"
|
||||
|
||||
func main() {
|
||||
cli := &cobra.Command{
|
||||
|
@ -41,7 +41,7 @@ func configureLogs(cli *cobra.Command) {
|
|||
}
|
||||
|
||||
func enableExperimental() bool {
|
||||
if b, err := strconv.ParseBool(os.Getenv(EnableExperimentalEnv)); err == nil {
|
||||
if b, err := strconv.ParseBool(os.Getenv(enableExperimentalEnv)); err == nil {
|
||||
return b
|
||||
}
|
||||
return false
|
||||
|
|
|
@ -13,9 +13,9 @@ func Command() *cobra.Command {
|
|||
Use: "version",
|
||||
Short: "Shows current version of kyverno.",
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
fmt.Printf("Version: %s\n", version.BuildVersion)
|
||||
fmt.Printf("Time: %s\n", version.BuildTime)
|
||||
fmt.Printf("Git commit ID: %s\n", version.BuildHash)
|
||||
fmt.Printf("Version: %s\n", version.Version())
|
||||
fmt.Printf("Time: %s\n", version.Time())
|
||||
fmt.Printf("Git commit ID: %s\n", version.Hash())
|
||||
return nil
|
||||
},
|
||||
}
|
||||
|
|
|
@ -130,7 +130,7 @@ func NewOTLPGRPCConfig(
|
|||
resource.NewWithAttributes(
|
||||
semconv.SchemaURL,
|
||||
semconv.ServiceNameKey.String(MeterName),
|
||||
semconv.ServiceVersionKey.String(version.BuildVersion),
|
||||
semconv.ServiceVersionKey.String(version.Version()),
|
||||
),
|
||||
)
|
||||
if err != nil {
|
||||
|
@ -159,7 +159,7 @@ func NewPrometheusConfig(
|
|||
semconv.SchemaURL,
|
||||
semconv.ServiceNameKey.String("kyverno-svc-metrics"),
|
||||
semconv.ServiceNamespaceKey.String(kconfig.KyvernoNamespace()),
|
||||
semconv.ServiceVersionKey.String(version.BuildVersion),
|
||||
semconv.ServiceVersionKey.String(version.Version()),
|
||||
),
|
||||
)
|
||||
if err != nil {
|
||||
|
|
|
@ -49,7 +49,7 @@ func NewTraceConfig(log logr.Logger, tracerName, address, certs string, kubeClie
|
|||
resource.WithTelemetrySDK(),
|
||||
resource.WithAttributes(
|
||||
semconv.ServiceNameKey.String(tracerName),
|
||||
semconv.ServiceVersionKey.String(version.BuildVersion),
|
||||
semconv.ServiceVersionKey.String(version.Version()),
|
||||
),
|
||||
resource.WithFromEnv(),
|
||||
)
|
||||
|
|
|
@ -1,18 +1,50 @@
|
|||
package version
|
||||
|
||||
import (
|
||||
"runtime/debug"
|
||||
|
||||
"github.com/go-logr/logr"
|
||||
)
|
||||
|
||||
// These fields are set during an official build
|
||||
// Global vars set from command-line arguments
|
||||
var (
|
||||
BuildVersion = "--"
|
||||
BuildHash = "--"
|
||||
BuildTime = "--"
|
||||
)
|
||||
// BuildVersion is provided by govvv at compile-time
|
||||
var BuildVersion string
|
||||
|
||||
func Version() string {
|
||||
if BuildVersion == "" {
|
||||
bi, ok := debug.ReadBuildInfo()
|
||||
if !ok {
|
||||
return "---"
|
||||
}
|
||||
BuildVersion = bi.Main.Version
|
||||
}
|
||||
return BuildVersion
|
||||
}
|
||||
|
||||
func Time() string {
|
||||
bi, ok := debug.ReadBuildInfo()
|
||||
if ok {
|
||||
for _, setting := range bi.Settings {
|
||||
if setting.Key == "vcs.time" {
|
||||
return setting.Value
|
||||
}
|
||||
}
|
||||
}
|
||||
return "---"
|
||||
}
|
||||
|
||||
func Hash() string {
|
||||
bi, ok := debug.ReadBuildInfo()
|
||||
if ok {
|
||||
for _, setting := range bi.Settings {
|
||||
if setting.Key == "vcs.revision" {
|
||||
return setting.Value
|
||||
}
|
||||
}
|
||||
}
|
||||
return "---"
|
||||
}
|
||||
|
||||
// PrintVersionInfo displays the kyverno version - git version
|
||||
func PrintVersionInfo(log logr.Logger) {
|
||||
log.Info("version", "version", BuildVersion, "hash", BuildHash, "time", BuildTime)
|
||||
log.Info("version", "version", Version(), "hash", Hash(), "time", Time())
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue