Skip to content

Commit

Permalink
change variable name by codereview
Browse files Browse the repository at this point in the history
Signed-off-by: dongjiang <[email protected]>
  • Loading branch information
dongjiang1989 committed Feb 14, 2025
1 parent e13e2e7 commit 366033d
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 32 deletions.
4 changes: 2 additions & 2 deletions hack/util.sh
Original file line number Diff line number Diff line change
Expand Up @@ -715,7 +715,7 @@ function util::version_ldflags() {
# Git information
GIT_VERSION=$(util::get_version)
# Git revision
GIT_REVISION=$(util::get_revision)
GIT_ABBREVIATIVE_COMMIT=$(util::get_revision)
GIT_COMMIT_HASH=$(git rev-parse HEAD)
if git_status=$(git status --porcelain 2>/dev/null) && [[ -z ${git_status} ]]; then
GIT_TREESTATE="clean"
Expand All @@ -726,7 +726,7 @@ function util::version_ldflags() {
LDFLAGS="-X github.com/karmada-io/karmada/pkg/version.gitVersion=${GIT_VERSION} \
-X github.com/karmada-io/karmada/pkg/version.gitCommit=${GIT_COMMIT_HASH} \
-X github.com/karmada-io/karmada/pkg/version.gitTreeState=${GIT_TREESTATE} \
-X github.com/karmada-io/karmada/pkg/version.gitRevision=${GIT_REVISION} \
-X github.com/karmada-io/karmada/pkg/version.gitAbbreviativeCommit=${GIT_ABBREVIATIVE_COMMIT} \
-X github.com/karmada-io/karmada/pkg/version.buildDate=${BUILDDATE}"
echo $LDFLAGS
}
Expand Down
8 changes: 4 additions & 4 deletions pkg/version/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ package version
// version for ad-hoc builds (e.g. `go build`) that cannot get the version
// information from git.
var (
gitVersion = "v0.0.0-master"
gitCommit = "unknown" // sha1 from git, output of $(git rev-parse HEAD)
gitTreeState = "unknown" // state of git tree, either "clean" or "dirty"
gitRevision = "unknown" // short sha1 for git, output of $(git rev-parse --short HEAD)
gitVersion = "v0.0.0-master"
gitCommit = "unknown" // sha1 from git, output of $(git rev-parse HEAD)
gitTreeState = "unknown" // state of git tree, either "clean" or "dirty"
gitAbbreviativeCommit = "unknown" // short sha1 from git, output of $(git rev-parse --short HEAD)

buildDate = "unknown" // build date in ISO8601 format, output of $(date -u +'%Y-%m-%dT%H:%M:%SZ')
)
34 changes: 17 additions & 17 deletions pkg/version/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ import (

// Info contains versioning information.
type Info struct {
GitVersion string `json:"gitVersion"`
GitCommit string `json:"gitCommit"`
GitRevision string `json:"gitRevision"`
GitTreeState string `json:"gitTreeState"`
BuildDate string `json:"buildDate"`
GoVersion string `json:"goVersion"`
Compiler string `json:"compiler"`
Platform string `json:"platform"`
GitVersion string `json:"gitVersion"`
GitCommit string `json:"gitCommit"`
GitAbbreviativeCommit string `json:"gitAbbreviativeCommit"`
GitTreeState string `json:"gitTreeState"`
BuildDate string `json:"buildDate"`
GoVersion string `json:"goVersion"`
Compiler string `json:"compiler"`
Platform string `json:"platform"`
}

// String returns a Go-syntax representation of the Info.
Expand All @@ -44,14 +44,14 @@ func (info Info) String() string {
// what code a binary was built from.
func Get() Info {
return Info{
GitVersion: gitVersion,
GitRevision: gitRevision,
GitCommit: gitCommit,
GitTreeState: gitTreeState,
BuildDate: buildDate,
GoVersion: runtime.Version(),
Compiler: runtime.Compiler,
Platform: fmt.Sprintf("%s/%s", runtime.GOOS, runtime.GOARCH),
GitVersion: gitVersion,
GitAbbreviativeCommit: gitAbbreviativeCommit,
GitCommit: gitCommit,
GitTreeState: gitTreeState,
BuildDate: buildDate,
GoVersion: runtime.Version(),
Compiler: runtime.Compiler,
Platform: fmt.Sprintf("%s/%s", runtime.GOOS, runtime.GOARCH),
}
}

Expand All @@ -68,7 +68,7 @@ func NewCollector(program string) prometheus.Collector {
),
ConstLabels: prometheus.Labels{
"version": Get().GitVersion,
"revision": Get().GitRevision,
"revision": Get().GitAbbreviativeCommit,
"goversion": runtime.Version(),
"goos": runtime.GOOS,
"goarch": runtime.GOARCH,
Expand Down
18 changes: 9 additions & 9 deletions pkg/version/version_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,16 @@ func TestInfo_String(t *testing.T) {
{
name: "test1",
info: Info{
GitVersion: "1.3.0",
GitCommit: "da070e68f3318410c8c70ed8186a2bc4736dacbd",
GitTreeState: "clean",
GitRevision: "851c78564",
BuildDate: "2022-08-31T13:09:22Z",
GoVersion: "go1.18.3",
Compiler: "gc",
Platform: "linux/amd64",
GitVersion: "1.3.0",
GitCommit: "da070e68f3318410c8c70ed8186a2bc4736dacbd",
GitTreeState: "clean",
GitAbbreviativeCommit: "851c78564",
BuildDate: "2022-08-31T13:09:22Z",
GoVersion: "go1.18.3",
Compiler: "gc",
Platform: "linux/amd64",
},
want: `version.Info{GitVersion:"1.3.0", GitCommit:"da070e68f3318410c8c70ed8186a2bc4736dacbd", GitRevision:"851c78564", GitTreeState:"clean", BuildDate:"2022-08-31T13:09:22Z", GoVersion:"go1.18.3", Compiler:"gc", Platform:"linux/amd64"}`,
want: `version.Info{GitVersion:"1.3.0", GitCommit:"da070e68f3318410c8c70ed8186a2bc4736dacbd", GitAbbreviativeCommit:"851c78564", GitTreeState:"clean", BuildDate:"2022-08-31T13:09:22Z", GoVersion:"go1.18.3", Compiler:"gc", Platform:"linux/amd64"}`,
},
}
for _, tt := range tests {
Expand Down

0 comments on commit 366033d

Please sign in to comment.