version.go 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /*
  2. Copyright 2014 The Kubernetes Authors.
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. */
  13. package version
  14. import (
  15. "fmt"
  16. "runtime"
  17. )
  18. // Info contains versioning information.
  19. // TODO: Add []string of api versions supported? It's still unclear
  20. // how we'll want to distribute that information.
  21. type Info struct {
  22. Major string `json:"major"`
  23. Minor string `json:"minor"`
  24. GitVersion string `json:"gitVersion"`
  25. GitCommit string `json:"gitCommit"`
  26. GitTreeState string `json:"gitTreeState"`
  27. BuildDate string `json:"buildDate"`
  28. GoVersion string `json:"goVersion"`
  29. Compiler string `json:"compiler"`
  30. Platform string `json:"platform"`
  31. }
  32. // Get returns the overall codebase version. It's for detecting
  33. // what code a binary was built from.
  34. func Get() Info {
  35. // These variables typically come from -ldflags settings and in
  36. // their absence fallback to the settings in pkg/version/base.go
  37. return Info{
  38. Major: gitMajor,
  39. Minor: gitMinor,
  40. GitVersion: gitVersion,
  41. GitCommit: gitCommit,
  42. GitTreeState: gitTreeState,
  43. BuildDate: buildDate,
  44. GoVersion: runtime.Version(),
  45. Compiler: runtime.Compiler,
  46. Platform: fmt.Sprintf("%s/%s", runtime.GOOS, runtime.GOARCH),
  47. }
  48. }
  49. // String returns info as a human-friendly version string.
  50. func (info Info) String() string {
  51. return info.GitVersion
  52. }