Merge pull request #5543 from you-n-g/master

add get available versions commmand
This commit is contained in:
Jeff Lowdermilk
2015-03-17 17:34:33 -07:00
8 changed files with 253 additions and 1 deletions

View File

@@ -0,0 +1,48 @@
/*
Copyright 2014 Google Inc. All rights reserved.
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 cmd
import (
"io"
"github.com/spf13/cobra"
"github.com/GoogleCloudPlatform/kubernetes/pkg/kubectl"
"github.com/GoogleCloudPlatform/kubernetes/pkg/kubectl/cmd/util"
)
func (f *Factory) NewCmdApiVersions(out io.Writer) *cobra.Command {
cmd := &cobra.Command{
Use: "apiversions",
Short: "Print available API versions.",
Run: func(cmd *cobra.Command, args []string) {
err := RunApiVersions(f, out, cmd)
util.CheckErr(err)
},
}
return cmd
}
func RunApiVersions(f *Factory, out io.Writer, cmd *cobra.Command) error {
client, err := f.Client(cmd)
if err != nil {
return err
}
kubectl.GetApiVersions(out, client)
return nil
}

View File

@@ -196,6 +196,7 @@ Find more information at https://github.com/GoogleCloudPlatform/kubernetes.`,
f.BindFlags(cmds.PersistentFlags())
cmds.AddCommand(f.NewCmdVersion(out))
cmds.AddCommand(f.NewCmdApiVersions(out))
cmds.AddCommand(f.NewCmdClusterInfo(out))
cmds.AddCommand(f.NewCmdProxy(out))

View File

@@ -40,3 +40,13 @@ func GetVersion(w io.Writer, kubeClient client.Interface) {
func GetClientVersion(w io.Writer) {
fmt.Fprintf(w, "Client Version: %#v\n", version.Get())
}
func GetApiVersions(w io.Writer, kubeClient client.Interface) {
apiVersions, err := kubeClient.ServerAPIVersions()
if err != nil {
fmt.Printf("Couldn't get available api versions from server: %v\n", err)
os.Exit(1)
}
fmt.Fprintf(w, "Available Server Api Versions: %#v\n", *apiVersions)
}