mirror of
https://github.com/k3s-io/kubernetes.git
synced 2026-01-05 15:37:24 +00:00
let kubectl api-versions use the discovery client
This commit is contained in:
@@ -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"
|
||||
)
|
||||
|
||||
@@ -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)
|
||||
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user