forked from openshift/origin
/
version.go
44 lines (36 loc) · 1023 Bytes
/
version.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package openshift
import (
"fmt"
etcdversion "github.com/coreos/etcd/version"
"github.com/openshift/origin/pkg/version"
kubeversion "k8s.io/kubernetes/pkg/version"
)
// Info contains versioning information.
// TODO: Add []string of api versions supported? It's still unclear
// how we'll want to distribute that information.
type Info struct {
version.Info
EtcdVersion string
KubeVersion string
}
// Get returns the overall codebase version. It's for detecting
// what code a binary was built from.
func Get() Info {
return Info{
Info: version.Get(),
KubeVersion: kubeversion.Get().String(),
EtcdVersion: etcdversion.Version,
}
}
// String returns info as a human-friendly version string.
func (info Info) String() string {
kubeVersion := info.KubeVersion
if len(kubeVersion) == 0 {
kubeVersion = "unknown"
}
etcdVersion := info.EtcdVersion
if len(etcdVersion) == 0 {
etcdVersion = "unknown"
}
return fmt.Sprintf("%s\nkubernetes %s\netcd %s", info.Info, kubeVersion, etcdVersion)
}