1
0
Fork 0
mirror of https://github.com/kyverno/kyverno.git synced 2024-12-15 17:51:20 +00:00
kyverno/pkg/version/version.go
Charles-Edouard Brétéché 43a7c26768
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>
2023-06-30 23:27:06 +00:00

50 lines
893 B
Go

package version
import (
"runtime/debug"
"github.com/go-logr/logr"
)
// 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", Version(), "hash", Hash(), "time", Time())
}