Skip to content

Commit d5e9460

Browse files
authored
Merge pull request #638 from jichenjc/add_version_1
Add version into log
2 parents e6cf33f + 3acf281 commit d5e9460

File tree

2 files changed

+64
-1
lines changed

2 files changed

+64
-1
lines changed

main.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import (
3131
infrav1 "sigs.k8s.io/cluster-api-provider-openstack/api/v1alpha3"
3232
"sigs.k8s.io/cluster-api-provider-openstack/controllers"
3333
"sigs.k8s.io/cluster-api-provider-openstack/pkg/record"
34+
"sigs.k8s.io/cluster-api-provider-openstack/version"
3435
clusterv1 "sigs.k8s.io/cluster-api/api/v1alpha3"
3536
ctrl "sigs.k8s.io/controller-runtime"
3637
"sigs.k8s.io/controller-runtime/pkg/client/config"
@@ -232,7 +233,7 @@ func main() {
232233
os.Exit(1)
233234
}
234235

235-
setupLog.Info("starting manager")
236+
setupLog.Info("starting manager", "version", version.Get().String())
236237
if err := mgr.Start(ctrl.SetupSignalHandler()); err != nil {
237238
setupLog.Error(err, "problem running manager")
238239
os.Exit(1)

version/version.go

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/*
2+
Copyright 2020 The Kubernetes Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package version
18+
19+
import (
20+
"fmt"
21+
"runtime"
22+
)
23+
24+
var (
25+
gitMajor string // major version, always numeric
26+
gitMinor string // minor version, numeric possibly followed by "+"
27+
gitVersion string // semantic version, derived by build scripts
28+
gitCommit string // sha1 from git, output of $(git rev-parse HEAD)
29+
gitTreeState string // state of git tree, either "clean" or "dirty"
30+
buildDate string // build date in ISO8601 format, output of $(date -u +'%Y-%m-%dT%H:%M:%SZ')
31+
)
32+
33+
type Info struct {
34+
Major string `json:"major,omitempty"`
35+
Minor string `json:"minor,omitempty"`
36+
GitVersion string `json:"gitVersion,omitempty"`
37+
GitCommit string `json:"gitCommit,omitempty"`
38+
GitTreeState string `json:"gitTreeState,omitempty"`
39+
BuildDate string `json:"buildDate,omitempty"`
40+
GoVersion string `json:"goVersion,omitempty"`
41+
Compiler string `json:"compiler,omitempty"`
42+
Platform string `json:"platform,omitempty"`
43+
}
44+
45+
func Get() Info {
46+
return Info{
47+
Major: gitMajor,
48+
Minor: gitMinor,
49+
GitVersion: gitVersion,
50+
GitCommit: gitCommit,
51+
GitTreeState: gitTreeState,
52+
BuildDate: buildDate,
53+
GoVersion: runtime.Version(),
54+
Compiler: runtime.Compiler,
55+
Platform: fmt.Sprintf("%s/%s", runtime.GOOS, runtime.GOARCH),
56+
}
57+
}
58+
59+
// String returns info as a human-friendly version string.
60+
func (info Info) String() string {
61+
return info.GitVersion
62+
}

0 commit comments

Comments
 (0)