let kubectl api-versions use the discovery client

pull/6/head
Chao Xu 2015-10-16 14:36:49 -07:00
parent 236193a26d
commit eb3a80156a
8 changed files with 20 additions and 27 deletions

View File

@ -3,7 +3,7 @@
.SH NAME .SH NAME
.PP .PP
kubectl api\-versions \- Print available API versions. kubectl api\-versions \- Print the supported API versions on the server, in the form of "group/version".
.SH SYNOPSIS .SH SYNOPSIS
@ -13,7 +13,7 @@ kubectl api\-versions \- Print available API versions.
.SH DESCRIPTION .SH DESCRIPTION
.PP .PP
Print available API versions. Print the supported API versions on the server, in the form of "group/version".
.SH OPTIONS INHERITED FROM PARENT COMMANDS .SH OPTIONS INHERITED FROM PARENT COMMANDS

View File

@ -77,7 +77,7 @@ kubectl
### SEE ALSO ### SEE ALSO
* [kubectl annotate](kubectl_annotate.md) - Update the annotations on a resource * [kubectl annotate](kubectl_annotate.md) - Update the annotations on a resource
* [kubectl api-versions](kubectl_api-versions.md) - Print available API versions. * [kubectl api-versions](kubectl_api-versions.md) - Print the supported API versions on the server, in the form of "group/version".
* [kubectl apply](kubectl_apply.md) - Apply a configuration to a resource by filename or stdin * [kubectl apply](kubectl_apply.md) - Apply a configuration to a resource by filename or stdin
* [kubectl attach](kubectl_attach.md) - Attach to a running container. * [kubectl attach](kubectl_attach.md) - Attach to a running container.
* [kubectl autoscale](kubectl_autoscale.md) - Auto-scale a replication controller * [kubectl autoscale](kubectl_autoscale.md) - Auto-scale a replication controller
@ -105,7 +105,7 @@ kubectl
* [kubectl stop](kubectl_stop.md) - Deprecated: Gracefully shut down a resource by name or filename. * [kubectl stop](kubectl_stop.md) - Deprecated: Gracefully shut down a resource by name or filename.
* [kubectl version](kubectl_version.md) - Print the client and server version information. * [kubectl version](kubectl_version.md) - Print the client and server version information.
###### Auto generated by spf13/cobra on 16-Oct-2015 ###### Auto generated by spf13/cobra on 21-Oct-2015
<!-- BEGIN MUNGE: GENERATED_ANALYTICS --> <!-- BEGIN MUNGE: GENERATED_ANALYTICS -->
[![Analytics](https://kubernetes-site.appspot.com/UA-36037335-10/GitHub/docs/user-guide/kubectl/kubectl.md?pixel)]() [![Analytics](https://kubernetes-site.appspot.com/UA-36037335-10/GitHub/docs/user-guide/kubectl/kubectl.md?pixel)]()

View File

@ -33,12 +33,12 @@ Documentation for other releases can be found at
## kubectl api-versions ## kubectl api-versions
Print available API versions. Print the supported API versions on the server, in the form of "group/version".
### Synopsis ### Synopsis
Print available API versions. Print the supported API versions on the server, in the form of "group/version".
``` ```
kubectl api-versions kubectl api-versions
@ -76,7 +76,7 @@ kubectl api-versions
* [kubectl](kubectl.md) - kubectl controls the Kubernetes cluster manager * [kubectl](kubectl.md) - kubectl controls the Kubernetes cluster manager
###### Auto generated by spf13/cobra at 2015-09-22 12:53:42.294634813 +0000 UTC ###### Auto generated by spf13/cobra on 20-Oct-2015
<!-- BEGIN MUNGE: GENERATED_ANALYTICS --> <!-- BEGIN MUNGE: GENERATED_ANALYTICS -->
[![Analytics](https://kubernetes-site.appspot.com/UA-36037335-10/GitHub/docs/user-guide/kubectl/kubectl_api-versions.md?pixel)]() [![Analytics](https://kubernetes-site.appspot.com/UA-36037335-10/GitHub/docs/user-guide/kubectl/kubectl_api-versions.md?pixel)]()

View File

@ -196,7 +196,7 @@ func (c *Client) SwaggerSchema(groupVersion string) (*swagger.ApiDeclaration, er
if err != nil { if err != nil {
return nil, err return nil, err
} }
groupVersions := extractGroupVersions(groupList) groupVersions := ExtractGroupVersions(groupList)
// This check also takes care the case that kubectl is newer than the running endpoint // This check also takes care the case that kubectl is newer than the running endpoint
if stringDoesntExistIn(groupVersion, groupVersions) { if stringDoesntExistIn(groupVersion, groupVersions) {
return nil, fmt.Errorf("API version: %s is not supported by the server. Use one of: %v", groupVersion, groupVersions) return nil, fmt.Errorf("API version: %s is not supported by the server. Use one of: %v", groupVersion, groupVersions)

View File

@ -140,7 +140,7 @@ func (d *DiscoveryClient) ServerResources() (map[string]*unversioned.APIResource
if err != nil { if err != nil {
return nil, err return nil, err
} }
groupVersions := extractGroupVersions(apiGroups) groupVersions := ExtractGroupVersions(apiGroups)
result := map[string]*unversioned.APIResourceList{} result := map[string]*unversioned.APIResourceList{}
for _, groupVersion := range groupVersions { for _, groupVersion := range groupVersions {
resources, err := d.ServerResourcesForGroupVersion(groupVersion) resources, err := d.ServerResourcesForGroupVersion(groupVersion)

View File

@ -187,7 +187,7 @@ func MatchesServerVersion(client *Client, c *Config) error {
return nil return nil
} }
func extractGroupVersions(l *unversioned.APIGroupList) []string { func ExtractGroupVersions(l *unversioned.APIGroupList) []string {
var groupVersions []string var groupVersions []string
for _, g := range l.Groups { for _, g := range l.Groups {
for _, gv := range g.Versions { for _, gv := range g.Versions {
@ -241,7 +241,7 @@ func ServerAPIVersions(c *Config) (groupVersions []string, err error) {
if err != nil { if err != nil {
return nil, fmt.Errorf("unexpected error: %v", err) return nil, fmt.Errorf("unexpected error: %v", err)
} }
groupVersions = append(groupVersions, extractGroupVersions(&apiGroupList)...) groupVersions = append(groupVersions, ExtractGroupVersions(&apiGroupList)...)
return groupVersions, nil return groupVersions, nil
} }

View File

@ -20,10 +20,11 @@ import (
"fmt" "fmt"
"io" "io"
"os" "os"
"sort"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"k8s.io/kubernetes/pkg/api/unversioned" unversioned_client "k8s.io/kubernetes/pkg/client/unversioned"
cmdutil "k8s.io/kubernetes/pkg/kubectl/cmd/util" cmdutil "k8s.io/kubernetes/pkg/kubectl/cmd/util"
) )
@ -32,7 +33,7 @@ func NewCmdApiVersions(f *cmdutil.Factory, out io.Writer) *cobra.Command {
Use: "api-versions", Use: "api-versions",
// apiversions is deprecated. // apiversions is deprecated.
Aliases: []string{"apiversions"}, Aliases: []string{"apiversions"},
Short: "Print available API versions.", Short: "Print the supported API versions on the server, in the form of \"group/version\".",
Run: func(cmd *cobra.Command, args []string) { Run: func(cmd *cobra.Command, args []string) {
err := RunApiVersions(f, out) err := RunApiVersions(f, out)
cmdutil.CheckErr(err) cmdutil.CheckErr(err)
@ -51,19 +52,14 @@ func RunApiVersions(f *cmdutil.Factory, w io.Writer) error {
return err return err
} }
apiVersions, err := client.ServerAPIVersions() groupList, err := client.Discovery().ServerGroups()
if err != nil { if err != nil {
fmt.Printf("Couldn't get available api versions from server: %v\n", err) return fmt.Errorf("Couldn't get available api versions from server: %v\n", err)
os.Exit(1)
} }
apiVersions := unversioned_client.ExtractGroupVersions(groupList)
var expAPIVersions *unversioned.APIVersions sort.Strings(apiVersions)
expAPIVersions, err = client.Extensions().ServerAPIVersions() for _, v := range apiVersions {
fmt.Fprintln(w, v)
fmt.Fprintf(w, "Available Server Api Versions: %#v\n", *apiVersions)
if err == nil {
fmt.Fprintf(w, "Available Server Experimental Api Versions: %#v\n", *expAPIVersions)
} }
return nil return nil
} }

View File

@ -427,9 +427,6 @@ var _ = Describe("Kubectl client", func() {
It("should check if v1 is in available api versions [Conformance]", func() { It("should check if v1 is in available api versions [Conformance]", func() {
By("validating api verions") By("validating api verions")
output := runKubectl("api-versions") output := runKubectl("api-versions")
if !strings.Contains(output, "Available Server Api Versions:") {
Failf("Missing caption in kubectl api-versions")
}
if !strings.Contains(output, "v1") { if !strings.Contains(output, "v1") {
Failf("No v1 in kubectl api-versions") Failf("No v1 in kubectl api-versions")
} }