add version api (#2127)

add cluster validation api
This commit is contained in:
zryfish
2020-05-27 18:11:27 +08:00
committed by GitHub
parent e119fd8a36
commit 27ca024bb7
11 changed files with 308 additions and 14 deletions

View File

@@ -16,4 +16,43 @@ limitations under the License.
package version
var Version = "v0.0.0"
import (
"fmt"
"runtime"
apimachineryversion "k8s.io/apimachinery/pkg/version"
)
var (
version = "v0.0.0"
gitCommit = "unknown"
gitTreeState = "unknown"
buildDate = "unknown"
)
type Info struct {
Version string `json:"gitVersion"`
GitCommit string `json:"gitCommit"`
GitTreeState string `json:"gitTreeState"`
BuildDate string `json:"buildDate"`
GoVersion string `json:"goVersion"`
Compiler string `json:"compiler"`
Platform string `json:"platform"`
Kubernetes *apimachineryversion.Info `json:"kubernetes,omitempty"`
}
// Get returns the overall codebase version. It's for
// detecting what code a binary was built from.
func Get() Info {
// These variables typically come from -ldflags settings and
// in their absence fallback to the default settings
return Info{
Version: version,
GitCommit: gitCommit,
GitTreeState: gitTreeState,
BuildDate: buildDate,
GoVersion: runtime.Version(),
Compiler: runtime.Compiler,
Platform: fmt.Sprintf("%s/%s", runtime.GOOS, runtime.GOARCH),
}
}