2014-10-06 01:24:19 +00:00
|
|
|
/*
|
2016-06-03 00:25:58 +00:00
|
|
|
Copyright 2014 The Kubernetes Authors.
|
2014-10-06 01:24:19 +00:00
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
package kubectl
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"io"
|
|
|
|
"os"
|
|
|
|
|
2015-08-13 19:01:50 +00:00
|
|
|
client "k8s.io/kubernetes/pkg/client/unversioned"
|
2015-08-05 22:03:47 +00:00
|
|
|
"k8s.io/kubernetes/pkg/version"
|
2014-10-06 01:24:19 +00:00
|
|
|
)
|
|
|
|
|
2015-08-26 07:00:28 +00:00
|
|
|
func GetServerVersion(w io.Writer, kubeClient client.Interface) {
|
2016-01-05 19:55:34 +00:00
|
|
|
serverVersion, err := kubeClient.Discovery().ServerVersion()
|
2014-10-06 01:24:19 +00:00
|
|
|
if err != nil {
|
2015-08-26 07:00:28 +00:00
|
|
|
fmt.Printf("Couldn't read server version from server: %v\n", err)
|
2014-10-06 01:24:19 +00:00
|
|
|
os.Exit(1)
|
|
|
|
}
|
|
|
|
|
Fix kubectl version to match client and server version output
Before this fix, the server version was printed from a pointer, making
the Go formatter prefix it with a &.
Before this patch:
$ kubectl version
Client Version: version.Info{Major:"0", Minor:"8+", GitVersion:"v0.8.0-509-g8537a73264b836", GitCommit:"8537a73264b836226cfca745ed37d65916e3b16f", GitTreeState:"clean"}
Server Version: &version.Info{Major:"0", Minor:"8+", GitVersion:"v0.8.0-509-g8537a73264b836", GitCommit:"8537a73264b836226cfca745ed37d65916e3b16f", GitTreeState:"clean"}
After this patch:
$ kubectl version
Client Version: version.Info{Major:"0", Minor:"8+", GitVersion:"v0.8.0-509-g8537a73264b836-dirty", GitCommit:"8537a73264b836226cfca745ed37d65916e3b16f", GitTreeState:"dirty"}
Server Version: version.Info{Major:"0", Minor:"8+", GitVersion:"v0.8.0-509-g8537a73264b836", GitCommit:"8537a73264b836226cfca745ed37d65916e3b16f", GitTreeState:"clean"}
2015-01-21 16:44:53 +00:00
|
|
|
fmt.Fprintf(w, "Server Version: %#v\n", *serverVersion)
|
2014-10-06 01:24:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func GetClientVersion(w io.Writer) {
|
|
|
|
fmt.Fprintf(w, "Client Version: %#v\n", version.Get())
|
|
|
|
}
|