Skip to content

Commit c6c08b3

Browse files
committed
fix: add 'version' package
1 parent f6e11f3 commit c6c08b3

File tree

4 files changed

+59
-6
lines changed

4 files changed

+59
-6
lines changed

.github/workflows/release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ jobs:
7575
labels: ${{ steps.meta.outputs.labels }}
7676
no-cache: true
7777
build-args: |
78-
GO_LDFLAGS=-X 'main.CurrentVersion=${{ github.event_name == 'workflow_dispatch' && steps.set_tag.outputs.tag || needs.release.outputs.version }}'
78+
GO_LDFLAGS=-X 'github.com/NexusGPU/tensor-fusion/internal/version.BuildVersion=${{ needs.release.outputs.version }}'
7979
8080
publish_node_discovery_image:
8181
needs:

cmd/main.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,14 @@ import (
4747
"github.com/NexusGPU/tensor-fusion/internal/gpuallocator"
4848
"github.com/NexusGPU/tensor-fusion/internal/server"
4949
"github.com/NexusGPU/tensor-fusion/internal/server/router"
50+
"github.com/NexusGPU/tensor-fusion/internal/version"
5051
webhookcorev1 "github.com/NexusGPU/tensor-fusion/internal/webhook/v1"
5152
// +kubebuilder:scaffold:imports
5253
)
5354

5455
var (
55-
scheme = runtime.NewScheme()
56-
setupLog = ctrl.Log.WithName("setup")
57-
CurrentVersion = "dev"
56+
scheme = runtime.NewScheme()
57+
setupLog = ctrl.Log.WithName("setup")
5858
)
5959

6060
func init() {
@@ -93,8 +93,8 @@ func main() {
9393

9494
ctrl.SetLogger(zap.New(zap.UseFlagOptions(&opts)))
9595

96-
// print version
97-
setupLog.Info("got operator basic info.", "version", CurrentVersion)
96+
// print version info
97+
setupLog.Info("got operator version info.", "version", version.Version(), "hash", version.Hash(), "time", version.Time())
9898

9999
// if the enable-http2 flag is false (the default), http/2 should be disabled
100100
// due to its vulnerabilities. More specifically, disabling http/2 will

dockerfile/operator.Dockerfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ RUN go mod download
1616
COPY cmd/ cmd/
1717
COPY api/ api/
1818
COPY internal/ internal/
19+
# Copy .git directory to enable VCS info in build
20+
COPY .git/ .git/
1921

2022

2123
# Build

internal/version/version.go

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
package version
2+
3+
import (
4+
"fmt"
5+
"runtime/debug"
6+
"time"
7+
)
8+
9+
var (
10+
BuildVersion string
11+
)
12+
13+
func Version() string {
14+
return BuildVersion
15+
}
16+
17+
func Time() string {
18+
bi, ok := debug.ReadBuildInfo()
19+
if ok {
20+
for _, setting := range bi.Settings {
21+
// - vcs.time: the modification time associated with vcs.revision, in RFC3339 format
22+
if setting.Key == "vcs.time" {
23+
return setting.Value
24+
}
25+
}
26+
}
27+
return time.Now().Format(time.RFC3339)
28+
}
29+
30+
func Hash() string {
31+
var (
32+
hash string
33+
)
34+
bi, ok := debug.ReadBuildInfo()
35+
if ok {
36+
for _, setting := range bi.Settings {
37+
// - vcs.revision: the revision identifier for the current commit or checkout
38+
if setting.Key == "vcs.revision" {
39+
hash = setting.Value
40+
}
41+
if setting.Key == "vcs.modified" {
42+
hash = fmt.Sprintf("%s+dirty", hash)
43+
}
44+
}
45+
}
46+
return hash
47+
}
48+
49+
func EncodeVersionInfo() string {
50+
return fmt.Sprintf("version: %s, hash: %s, time: %s", Version(), Hash(), Time())
51+
}

0 commit comments

Comments
 (0)