| Abhay Kumar | 40252eb | 2025-10-13 13:25:53 +0000 | [diff] [blame^] | 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 | |
| 15 | // Package version implements etcd version parsing and contains latest version |
| 16 | // information. |
| 17 | package version |
| 18 | |
| 19 | import ( |
| 20 | "fmt" |
| 21 | "strings" |
| 22 | |
| 23 | "github.com/coreos/go-semver/semver" |
| 24 | ) |
| 25 | |
| 26 | var ( |
| 27 | // MinClusterVersion is the min cluster version this etcd binary is compatible with. |
| 28 | MinClusterVersion = "3.0.0" |
| 29 | Version = "3.6.5" |
| 30 | APIVersion = "unknown" |
| 31 | |
| 32 | // Git SHA Value will be set during build |
| 33 | GitSHA = "Not provided (use ./build instead of go build)" |
| 34 | ) |
| 35 | |
| 36 | // Get all constant versions defined in a centralized place. |
| 37 | var ( |
| 38 | V3_0 = semver.Version{Major: 3, Minor: 0} |
| 39 | V3_1 = semver.Version{Major: 3, Minor: 1} |
| 40 | V3_2 = semver.Version{Major: 3, Minor: 2} |
| 41 | V3_3 = semver.Version{Major: 3, Minor: 3} |
| 42 | V3_4 = semver.Version{Major: 3, Minor: 4} |
| 43 | V3_5 = semver.Version{Major: 3, Minor: 5} |
| 44 | V3_6 = semver.Version{Major: 3, Minor: 6} |
| 45 | V3_7 = semver.Version{Major: 3, Minor: 7} |
| 46 | V4_0 = semver.Version{Major: 4, Minor: 0} |
| 47 | |
| 48 | // AllVersions keeps all the versions in ascending order. |
| 49 | AllVersions = []semver.Version{V3_0, V3_1, V3_2, V3_3, V3_4, V3_5, V3_6, V3_7, V4_0} |
| 50 | ) |
| 51 | |
| 52 | func init() { |
| 53 | ver, err := semver.NewVersion(Version) |
| 54 | if err == nil { |
| 55 | APIVersion = fmt.Sprintf("%d.%d", ver.Major, ver.Minor) |
| 56 | } |
| 57 | } |
| 58 | |
| 59 | type Versions struct { |
| 60 | Server string `json:"etcdserver"` |
| 61 | Cluster string `json:"etcdcluster"` |
| 62 | Storage string `json:"storage"` |
| 63 | // TODO: raft state machine version |
| 64 | } |
| 65 | |
| 66 | // Cluster only keeps the major.minor. |
| 67 | func Cluster(v string) string { |
| 68 | vs := strings.Split(v, ".") |
| 69 | if len(vs) <= 2 { |
| 70 | return v |
| 71 | } |
| 72 | return fmt.Sprintf("%s.%s", vs[0], vs[1]) |
| 73 | } |
| 74 | |
| 75 | func Compare(ver1, ver2 semver.Version) int { |
| 76 | return ver1.Compare(ver2) |
| 77 | } |
| 78 | |
| 79 | func LessThan(ver1, ver2 semver.Version) bool { |
| 80 | return ver1.LessThan(ver2) |
| 81 | } |
| 82 | |
| 83 | func Equal(ver1, ver2 semver.Version) bool { |
| 84 | return ver1.Equal(ver2) |
| 85 | } |