File tree Expand file tree Collapse file tree 4 files changed +25
-21
lines changed Expand file tree Collapse file tree 4 files changed +25
-21
lines changed Original file line number Diff line number Diff line change @@ -174,7 +174,7 @@ release-binary: $(RELEASE_DIR)
174174 -v " $$ (pwd):/workspace$( DOCKER_VOL_OPTS) " \
175175 -w /workspace/tools/setup-envtest \
176176 golang:$(GO_VERSION ) \
177- go build -a -trimpath -ldflags " -X 'main.BranchVersion =$( RELEASE_TAG) ' -extldflags '-static'" \
177+ go build -a -trimpath -ldflags " -X 'sigs.k8s.io/controller-runtime/tools/setup-envtest/version.version =$( RELEASE_TAG) ' -extldflags '-static'" \
178178 -o ./out/$(RELEASE_BINARY ) ./
179179
180180# # --------------------------------------
Original file line number Diff line number Diff line change 5151 "directory to store binary assets (default: $OS_SPECIFIC_DATA_DIR/envtest-binaries)" )
5252
5353 index = flag .String ("index" , remote .DefaultIndexURL , "index to discover envtest binaries" )
54-
55- // BranchVersion is the current setup-envtest branch that is used for the binary version of setup-envtest.
56- BranchVersion = ""
5754)
5855
5956// TODO(directxman12): handle interrupts?
@@ -277,9 +274,7 @@ Environment Variables:
277274 PrintFormat : printFormat ,
278275 }.Do (env )
279276 case "version" :
280- workflows.Version {
281- BinaryVersion : BranchVersion ,
282- }.Do (env )
277+ workflows.Version {}.Do (env )
283278 default :
284279 flag .Usage ()
285280 envp .Exit (2 , "unknown action %q" , action )
Original file line number Diff line number Diff line change 1+ package version
2+
3+ import "runtime/debug"
4+
5+ // Version to be set using ldflags:
6+ // -ldflags "-X sigs.k8s.io/controller-tools/pkg/version.version=v1.0.0"
7+ // falls back to module information is unse
8+ var version = ""
9+
10+ func Version () string {
11+ if version != "" {
12+ return version
13+ }
14+ info , ok := debug .ReadBuildInfo ()
15+ if ! ok || info == nil || info .Main .Version == "" {
16+ // binary has not been built with module support or doesn't contain a version.
17+ return "(unknown)"
18+ }
19+ return info .Main .Version
20+ }
Original file line number Diff line number Diff line change @@ -7,11 +7,11 @@ import (
77 "context"
88 "fmt"
99 "io"
10- "runtime/debug"
1110
1211 "github.com/go-logr/logr"
1312
1413 envp "sigs.k8s.io/controller-runtime/tools/setup-envtest/env"
14+ "sigs.k8s.io/controller-runtime/tools/setup-envtest/version"
1515)
1616
1717// Use is a workflow that prints out information about stored
@@ -90,20 +90,9 @@ func (f Sideload) Do(env *envp.Env) {
9090
9191// Version is the workflow that shows the current binary version
9292// of setup-envtest.
93- type Version struct {
94- BinaryVersion string
95- }
93+ type Version struct {}
9694
9795// Do executes the workflow.
9896func (v Version ) Do (env * envp.Env ) {
99- version := "(unknown)"
100- if v .BinaryVersion == "" {
101- info , ok := debug .ReadBuildInfo ()
102- if ok && info != nil && info .Main .Version != "" {
103- // binary has been built with module support.
104- version = info .Main .Version
105- }
106- v .BinaryVersion = version
107- }
108- fmt .Fprintf (env .Out , "setup-envtest version: %s\n " , v .BinaryVersion )
97+ fmt .Fprintf (env .Out , "setup-envtest version: %s\n " , version .Version ())
10998}
You can’t perform that action at this time.
0 commit comments