mirror of
https://github.com/kyverno/kyverno.git
synced 2024-12-14 11:57:48 +00:00
43a7c26768
* 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>
50 lines
893 B
Go
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())
|
|
}
|