Skip to content

Commit

Permalink
let kubectl api-versions use the discovery client
Browse files Browse the repository at this point in the history
  • Loading branch information
Chao Xu committed Oct 22, 2015
1 parent 236193a commit eb3a801
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 27 deletions.
4 changes: 2 additions & 2 deletions docs/man/man1/kubectl-api-versions.1
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

.SH NAME
.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
Expand All @@ -13,7 +13,7 @@ kubectl api\-versions \- Print available API versions.

.SH DESCRIPTION
.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
Expand Down
4 changes: 2 additions & 2 deletions docs/user-guide/kubectl/kubectl.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ kubectl
### SEE ALSO

* [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 attach](kubectl_attach.md) - Attach to a running container.
* [kubectl autoscale](kubectl_autoscale.md) - Auto-scale a replication controller
Expand Down Expand Up @@ -105,7 +105,7 @@ kubectl
* [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.

###### Auto generated by spf13/cobra on 16-Oct-2015
###### Auto generated by spf13/cobra on 21-Oct-2015

<!-- BEGIN MUNGE: GENERATED_ANALYTICS -->
[![Analytics](https://kubernetes-site.appspot.com/UA-36037335-10/GitHub/docs/user-guide/kubectl/kubectl.md?pixel)]()
Expand Down
6 changes: 3 additions & 3 deletions docs/user-guide/kubectl/kubectl_api-versions.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ Documentation for other releases can be found at

## kubectl api-versions

Print available API versions.
Print the supported API versions on the server, in the form of "group/version".

### Synopsis


Print available API versions.
Print the supported API versions on the server, in the form of "group/version".

```
kubectl api-versions
Expand Down Expand Up @@ -76,7 +76,7 @@ kubectl api-versions

* [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 -->
[![Analytics](https://kubernetes-site.appspot.com/UA-36037335-10/GitHub/docs/user-guide/kubectl/kubectl_api-versions.md?pixel)]()
Expand Down
2 changes: 1 addition & 1 deletion pkg/client/unversioned/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ func (c *Client) SwaggerSchema(groupVersion string) (*swagger.ApiDeclaration, er
if err != nil {
return nil, err
}
groupVersions := extractGroupVersions(groupList)
groupVersions := ExtractGroupVersions(groupList)
// This check also takes care the case that kubectl is newer than the running endpoint
if stringDoesntExistIn(groupVersion, groupVersions) {
return nil, fmt.Errorf("API version: %s is not supported by the server. Use one of: %v", groupVersion, groupVersions)
Expand Down
2 changes: 1 addition & 1 deletion pkg/client/unversioned/discovery_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ func (d *DiscoveryClient) ServerResources() (map[string]*unversioned.APIResource
if err != nil {
return nil, err
}
groupVersions := extractGroupVersions(apiGroups)
groupVersions := ExtractGroupVersions(apiGroups)
result := map[string]*unversioned.APIResourceList{}
for _, groupVersion := range groupVersions {
resources, err := d.ServerResourcesForGroupVersion(groupVersion)
Expand Down
4 changes: 2 additions & 2 deletions pkg/client/unversioned/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ func MatchesServerVersion(client *Client, c *Config) error {
return nil
}

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

return groupVersions, nil
}
Expand Down
22 changes: 9 additions & 13 deletions pkg/kubectl/cmd/apiversions.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,11 @@ import (
"fmt"
"io"
"os"
"sort"

"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"
)

Expand All @@ -32,7 +33,7 @@ func NewCmdApiVersions(f *cmdutil.Factory, out io.Writer) *cobra.Command {
Use: "api-versions",
// apiversions is deprecated.
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) {
err := RunApiVersions(f, out)
cmdutil.CheckErr(err)
Expand All @@ -51,19 +52,14 @@ func RunApiVersions(f *cmdutil.Factory, w io.Writer) error {
return err
}

apiVersions, err := client.ServerAPIVersions()
groupList, err := client.Discovery().ServerGroups()
if err != nil {
fmt.Printf("Couldn't get available api versions from server: %v\n", err)
os.Exit(1)
return fmt.Errorf("Couldn't get available api versions from server: %v\n", err)
}

var expAPIVersions *unversioned.APIVersions
expAPIVersions, err = client.Extensions().ServerAPIVersions()

fmt.Fprintf(w, "Available Server Api Versions: %#v\n", *apiVersions)
if err == nil {
fmt.Fprintf(w, "Available Server Experimental Api Versions: %#v\n", *expAPIVersions)
apiVersions := unversioned_client.ExtractGroupVersions(groupList)
sort.Strings(apiVersions)
for _, v := range apiVersions {
fmt.Fprintln(w, v)
}

return nil
}
3 changes: 0 additions & 3 deletions test/e2e/kubectl.go
Original file line number Diff line number Diff line change
Expand Up @@ -427,9 +427,6 @@ var _ = Describe("Kubectl client", func() {
It("should check if v1 is in available api versions [Conformance]", func() {
By("validating api verions")
output := runKubectl("api-versions")
if !strings.Contains(output, "Available Server Api Versions:") {
Failf("Missing caption in kubectl api-versions")
}
if !strings.Contains(output, "v1") {
Failf("No v1 in kubectl api-versions")
}
Expand Down

0 comments on commit eb3a801

Please sign in to comment.