version.go 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. // Copyright 2015 The etcd Authors
  2. //
  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. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. // Package version implements etcd version parsing and contains latest version
  15. // information.
  16. package version
  17. import (
  18. "fmt"
  19. "strings"
  20. "github.com/coreos/go-semver/semver"
  21. )
  22. var (
  23. // MinClusterVersion is the min cluster version this etcd binary is compatible with.
  24. MinClusterVersion = "3.0.0"
  25. Version = "3.3.15"
  26. APIVersion = "unknown"
  27. // Git SHA Value will be set during build
  28. GitSHA = "Not provided (use ./build instead of go build)"
  29. )
  30. func init() {
  31. ver, err := semver.NewVersion(Version)
  32. if err == nil {
  33. APIVersion = fmt.Sprintf("%d.%d", ver.Major, ver.Minor)
  34. }
  35. }
  36. type Versions struct {
  37. Server string `json:"etcdserver"`
  38. Cluster string `json:"etcdcluster"`
  39. // TODO: raft state machine version
  40. }
  41. // Cluster only keeps the major.minor.
  42. func Cluster(v string) string {
  43. vs := strings.Split(v, ".")
  44. if len(vs) <= 2 {
  45. return v
  46. }
  47. return fmt.Sprintf("%s.%s", vs[0], vs[1])
  48. }