From 7faca77e19a842ab300cbdf1270b4c4e7bbe771d Mon Sep 17 00:00:00 2001 From: Tiger Kaovilai Date: Tue, 12 Nov 2024 16:00:13 -0500 Subject: [PATCH] Add go buildinfo to velero to assist with #8397 ``` make container && docker run --rm velero/velero:main /velero version --client-only [+] Building 60.0s (18/18) FINISHED docker-container:colima-multiplat => [internal] load build definition from Dockerfile 0.0s => => transferring dockerfile: 2.37kB 0.0s => [internal] load metadata for docker.io/paketobuildpacks/run-jammy-tiny:0.2.52 3.6s => [internal] load metadata for docker.io/library/golang:1.22.8-bookworm 3.4s => [auth] paketobuildpacks/run-jammy-tiny:pull token for registry-1.docker.io 0.0s => [auth] library/golang:pull token for registry-1.docker.io 0.0s => [internal] load .dockerignore 0.0s => => transferring context: 60B 0.0s => CACHED [stage-2 1/3] FROM docker.io/paketobuildpacks/run-jammy-tiny:0.2.52@sha256:402b925a81a4c6985438fd37d0b22022ca688e528bbd46a38831a3702067cced 0.0s => => resolve docker.io/paketobuildpacks/run-jammy-tiny:0.2.52@sha256:402b925a81a4c6985438fd37d0b22022ca688e528bbd46a38831a3702067cced 0.0s => CACHED [restic-builder 1/3] FROM docker.io/library/golang:1.22.8-bookworm@sha256:3f0457a0a56a926d93c2baf4cf0057a645e8ff69ff31314080fcc62389643b8e 0.0s => => resolve docker.io/library/golang:1.22.8-bookworm@sha256:3f0457a0a56a926d93c2baf4cf0057a645e8ff69ff31314080fcc62389643b8e 0.0s => [internal] load build context 0.2s => => transferring context: 883.86kB 0.2s => CACHED [velero-builder 2/4] WORKDIR /go/src/github.com/vmware-tanzu/velero 0.0s => [velero-builder 3/4] COPY . /go/src/github.com/vmware-tanzu/velero 1.6s => [restic-builder 2/3] COPY . /go/src/github.com/vmware-tanzu/velero 1.6s => [velero-builder 4/4] RUN mkdir -p /output/usr/bin && export GOARM=$( echo "" | cut -c2-) && go build -o /output/velero -ldflags "-X github.com/vmware 49.7s => [restic-builder 3/3] RUN mkdir -p /output/usr/bin && export GOARM=$(echo "" | cut -c2-) && /go/src/github.com/vmware-tanzu/velero/hack/build-restic.sh && 34.6s => [stage-2 2/3] COPY --from=velero-builder /output / 0.2s => [stage-2 3/3] COPY --from=restic-builder /output / 0.1s => exporting to docker image format 4.1s => => exporting layers 2.7s => => exporting manifest sha256:5387d1a59b10970f9d0800ba960c4eb0f008e0d2bba5a9498b009ac478e5f4d4 0.0s => => exporting config sha256:f29cee5131777c8dc47571fc475f1abb2984ff1657b51c3a720c8aa453b195f2 0.0s => => sending tarball 1.4s => importing to docker 0.5s => => loading layer 4e2166c05ab9 491.52kB / 45.94MB 0.5s => => loading layer dd8fc23784d7 98.30kB / 8.82MB 0.1s 1 warning found (use --debug to expand): - UndefinedVar: Usage of undefined variable '$GOPROXY' (line 58) container: velero/velero:main WARNING: The requested image's platform (linux/amd64) does not match the detected host platform (linux/arm64/v8) and no specific platform was requested Client: Version: main Git commit: 303d239819259b54ecd264eef176b9dc55db3871-dirty Go version: go1.22.8 ``` --- changelogs/unreleased/8399-kaovilai | 1 + go.mod | 6 +++++- pkg/buildinfo/buildinfo.go | 19 ++++++++++++++++++- pkg/cmd/cli/version/version.go | 1 + pkg/cmd/server/server.go | 2 +- 5 files changed, 26 insertions(+), 3 deletions(-) create mode 100644 changelogs/unreleased/8399-kaovilai diff --git a/changelogs/unreleased/8399-kaovilai b/changelogs/unreleased/8399-kaovilai new file mode 100644 index 00000000000..e44c039c940 --- /dev/null +++ b/changelogs/unreleased/8399-kaovilai @@ -0,0 +1 @@ +Add golang buildinfo to velero to check toolchain used. Reduce minimum go toolchain in go.mod diff --git a/go.mod b/go.mod index 330ece7e5cb..67c3affd7d7 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,10 @@ module github.com/vmware-tanzu/velero -go 1.22.8 +// Do not pin patch version here. Leave patch at X.Y.0 +// Use env GOTOOLCHAIN=auto to use newer of go cli used to build Velero. +// or GOTOOLCHAIN=goX.Y.Z to use a specific toolchain version +// See: https://go.dev/doc/toolchain#select and https://github.com/vmware-tanzu/velero/issues/8397 +go 1.22.0 require ( cloud.google.com/go/storage v1.40.0 diff --git a/pkg/buildinfo/buildinfo.go b/pkg/buildinfo/buildinfo.go index b0533d0dbfd..1e41f3e6f82 100644 --- a/pkg/buildinfo/buildinfo.go +++ b/pkg/buildinfo/buildinfo.go @@ -19,12 +19,18 @@ limitations under the License. // worrying about introducing circular dependencies. package buildinfo -import "fmt" +import ( + "fmt" + "runtime/debug" +) var ( // Version is the current version of Velero, set by the go linker's -X flag at build time. Version string + // goVersion is the version of Go that was used to build Velero + goBuildInfo *debug.BuildInfo + // GitSHA is the actual commit that is being built, set by the go linker's -X flag at build time. GitSHA string @@ -44,3 +50,14 @@ func FormattedGitSHA() string { } return GitSHA } + +func GoVersion() string { + if goBuildInfo == nil { + var ok bool + goBuildInfo, ok = debug.ReadBuildInfo() + if !ok { + return "cannot read Go BuildInfo" + } + } + return goBuildInfo.GoVersion +} \ No newline at end of file diff --git a/pkg/cmd/cli/version/version.go b/pkg/cmd/cli/version/version.go index f8d26111619..a208bcc1d90 100644 --- a/pkg/cmd/cli/version/version.go +++ b/pkg/cmd/cli/version/version.go @@ -69,6 +69,7 @@ func printVersion(w io.Writer, clientOnly bool, kbClient kbclient.Client, server fmt.Fprintln(w, "Client:") fmt.Fprintf(w, "\tVersion: %s\n", buildinfo.Version) fmt.Fprintf(w, "\tGit commit: %s\n", buildinfo.FormattedGitSHA()) + fmt.Fprintf(w, "\tGo version: %s\n", buildinfo.GoVersion()) if clientOnly { return diff --git a/pkg/cmd/server/server.go b/pkg/cmd/server/server.go index a697e4d01bf..333c5fcb81f 100644 --- a/pkg/cmd/server/server.go +++ b/pkg/cmd/server/server.go @@ -109,7 +109,7 @@ func NewCommand(f client.Factory) *cobra.Command { logger.Infof("setting log-level to %s", strings.ToUpper(logLevel.String())) - logger.Infof("Starting Velero server %s (%s)", buildinfo.Version, buildinfo.FormattedGitSHA()) + logger.Infof("Starting Velero server %s (%s) go-version: %s", buildinfo.Version, buildinfo.FormattedGitSHA(), buildinfo.GoVersion()) if len(features.All()) > 0 { logger.Infof("%d feature flags enabled %s", len(features.All()), features.All()) } else {