mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-29 22:46:12 +00:00
add get available versions commmand
This commit is contained in:
parent
5c99bc9e96
commit
97b647207e
@ -16,6 +16,10 @@ limitations under the License.
|
||||
|
||||
package api
|
||||
|
||||
import (
|
||||
"strings"
|
||||
)
|
||||
|
||||
// This file contains API types that are unversioned.
|
||||
|
||||
// APIVersions lists the api versions that are available, to allow
|
||||
@ -49,3 +53,12 @@ func FieldSelectorQueryParam(version string) string {
|
||||
}
|
||||
return "field-selector"
|
||||
}
|
||||
|
||||
// String returns available api versions as a human-friendly version string.
|
||||
func (apiVersions APIVersions) String() string {
|
||||
return strings.Join(apiVersions.Versions, ",")
|
||||
}
|
||||
|
||||
func (apiVersions APIVersions) GoString() string {
|
||||
return apiVersions.String()
|
||||
}
|
||||
|
48
pkg/kubectl/cmd/apiversions.go
Normal file
48
pkg/kubectl/cmd/apiversions.go
Normal 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
|
||||
}
|
@ -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))
|
||||
|
||||
|
@ -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)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user