Skip to content

Commit bbb7ded

Browse files
authored
Fix the version printing (#55)
1 parent 359ac11 commit bbb7ded

File tree

1 file changed

+34
-2
lines changed

1 file changed

+34
-2
lines changed

pkg/version/version.go

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package version
22

33
import (
4+
"runtime/debug"
5+
46
"github.com/go-logr/logr"
57
)
68

@@ -10,15 +12,45 @@ var (
1012
AppName = "dynatrace-bootsrapper"
1113

1214
// Version contains the version of the Bootstrapper. Assigned externally.
13-
Version = "snapshot"
15+
Version = ""
1416

1517
// Commit indicates the Git commit hash the binary was build from. Assigned externally.
1618
Commit = ""
1719

1820
// BuildDate is the date when the binary was build. Assigned externally.
1921
BuildDate = ""
22+
23+
ModuleSum = ""
2024
)
2125

26+
func init() {
27+
i, ok := debug.ReadBuildInfo()
28+
if !ok {
29+
return
30+
}
31+
32+
if Version == "" {
33+
Version = i.Main.Version
34+
}
35+
36+
ModuleSum = i.Main.Sum
37+
38+
}
39+
2240
func Print(log logr.Logger) {
23-
log.Info("version info", "name", AppName, "version", Version, "commit", Commit, "build_date", BuildDate)
41+
keyValues := []any{"name", AppName, "version", Version}
42+
43+
if ModuleSum != "" {
44+
keyValues = append(keyValues, "module-sum", ModuleSum)
45+
}
46+
47+
if Commit != "" {
48+
keyValues = append(keyValues, "commit", Commit)
49+
}
50+
51+
if BuildDate != "" {
52+
keyValues = append(keyValues, "build_date", BuildDate)
53+
}
54+
55+
log.Info("version info", keyValues...)
2456
}

0 commit comments

Comments
 (0)