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.
17package version
18
19import (
20	"fmt"
21	"strings"
22
23	"github.com/coreos/go-semver/semver"
24)
25
26var (
27	// MinClusterVersion is the min cluster version this etcd binary is compatible with.
28	MinClusterVersion = "3.0.0"
29	Version           = "3.3.0+git"
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
36func init() {
37	ver, err := semver.NewVersion(Version)
38	if err == nil {
39		APIVersion = fmt.Sprintf("%d.%d", ver.Major, ver.Minor)
40	}
41}
42
43type Versions struct {
44	Server  string `json:"etcdserver"`
45	Cluster string `json:"etcdcluster"`
46	// TODO: raft state machine version
47}
48
49// Cluster only keeps the major.minor.
50func Cluster(v string) string {
51	vs := strings.Split(v, ".")
52	if len(vs) <= 2 {
53		return v
54	}
55	return fmt.Sprintf("%s.%s", vs[0], vs[1])
56}
57