mirror of https://github.com/k3s-io/k3s
Merge pull request #35543 from philips/improve-version
Automatic merge from submit-queue kubectl: add less verbose version The kubectl version output is very complex and makes it hard for users and vendors to give actionable information. For example during the recent Kubernetes 1.4.3 TLS security scramble I had to write a one-liner for users to get out the version number to give to figure out if they are vulnerable: ``` $ kubectl version | grep -i Server | sed -n 's%.*GitVersion:"\([^"]*\).*%\1%p' ``` Instead this patch outputs simply output by default ``` ./kubectl version Client Version: v1.4.3 Server Version: v1.4.3 ``` Adding the `--verbose` flag will output the old format.pull/6/head
commit
79fc0a95a0
|
@ -151,6 +151,9 @@ generation, etc., and display the output
|
|||
|
||||
* `--output-version=...`: Convert the output to a different API group/version
|
||||
|
||||
* `--short`: Output a compact summary of normal output; the format is subject
|
||||
to change and is optimizied for reading not parsing.
|
||||
|
||||
* `--validate`: Validate the resource schema
|
||||
|
||||
## Output conventions
|
||||
|
|
|
@ -46,7 +46,6 @@ go_library(
|
|||
"sorted_resource_name_list.go",
|
||||
"sorting_printer.go",
|
||||
"stop.go",
|
||||
"version.go",
|
||||
],
|
||||
tags = ["automanaged"],
|
||||
deps = [
|
||||
|
@ -102,7 +101,6 @@ go_library(
|
|||
"//pkg/util/uuid:go_default_library",
|
||||
"//pkg/util/validation:go_default_library",
|
||||
"//pkg/util/wait:go_default_library",
|
||||
"//pkg/version:go_default_library",
|
||||
"//pkg/watch:go_default_library",
|
||||
"//vendor:github.com/emicklei/go-restful/swagger",
|
||||
"//vendor:github.com/ghodss/yaml",
|
||||
|
|
|
@ -107,6 +107,7 @@ go_library(
|
|||
"//pkg/util/validation/field:go_default_library",
|
||||
"//pkg/util/wait:go_default_library",
|
||||
"//pkg/util/yaml:go_default_library",
|
||||
"//pkg/version:go_default_library",
|
||||
"//pkg/watch:go_default_library",
|
||||
"//vendor:github.com/daviddengcn/go-colortext",
|
||||
"//vendor:github.com/docker/distribution/reference",
|
||||
|
|
|
@ -22,8 +22,8 @@ import (
|
|||
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
"k8s.io/kubernetes/pkg/kubectl"
|
||||
cmdutil "k8s.io/kubernetes/pkg/kubectl/cmd/util"
|
||||
"k8s.io/kubernetes/pkg/version"
|
||||
)
|
||||
|
||||
func NewCmdVersion(f cmdutil.Factory, out io.Writer) *cobra.Command {
|
||||
|
@ -36,12 +36,18 @@ func NewCmdVersion(f cmdutil.Factory, out io.Writer) *cobra.Command {
|
|||
},
|
||||
}
|
||||
cmd.Flags().BoolP("client", "c", false, "Client version only (no server required).")
|
||||
cmd.Flags().BoolP("short", "", false, "Print just the version number.")
|
||||
cmd.Flags().MarkShorthandDeprecated("client", "please use --client instead.")
|
||||
return cmd
|
||||
}
|
||||
|
||||
func RunVersion(f cmdutil.Factory, out io.Writer, cmd *cobra.Command) error {
|
||||
kubectl.GetClientVersion(out)
|
||||
v := fmt.Sprintf("%#v", version.Get())
|
||||
if cmdutil.GetFlagBool(cmd, "short") {
|
||||
v = version.Get().GitVersion
|
||||
}
|
||||
|
||||
fmt.Fprintf(out, "Client Version: %s\n", v)
|
||||
if cmdutil.GetFlagBool(cmd, "client") {
|
||||
return nil
|
||||
}
|
||||
|
@ -56,6 +62,11 @@ func RunVersion(f cmdutil.Factory, out io.Writer, cmd *cobra.Command) error {
|
|||
return err
|
||||
}
|
||||
|
||||
fmt.Fprintf(out, "Server Version: %#v\n", *serverVersion)
|
||||
v = fmt.Sprintf("%#v", *serverVersion)
|
||||
if cmdutil.GetFlagBool(cmd, "short") {
|
||||
v = serverVersion.GitVersion
|
||||
}
|
||||
|
||||
fmt.Fprintf(out, "Server Version: %s\n", v)
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -1,28 +0,0 @@
|
|||
/*
|
||||
Copyright 2014 The Kubernetes Authors.
|
||||
|
||||
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"
|
||||
|
||||
"k8s.io/kubernetes/pkg/version"
|
||||
)
|
||||
|
||||
func GetClientVersion(w io.Writer) {
|
||||
fmt.Fprintf(w, "Client Version: %#v\n", version.Get())
|
||||
}
|
Loading…
Reference in New Issue