Display an external version of the object for --output

Use the version of the API the RESTMapper prefers (currently)
This commit is contained in:
Clayton Coleman
2014-11-01 18:44:03 -04:00
parent 179213f61c
commit a8ccb0f99f
4 changed files with 55 additions and 37 deletions

View File

@@ -84,7 +84,7 @@ Find more information at https://github.com/GoogleCloudPlatform/kubernetes.`,
cmds.PersistentFlags().StringP("server", "s", "", "Kubernetes apiserver to connect to")
cmds.PersistentFlags().StringP("auth-path", "a", os.Getenv("HOME")+"/.kubernetes_auth", "Path to the auth info file. If missing, prompt the user. Only used if using https.")
cmds.PersistentFlags().Bool("match-server-version", false, "Require server version to match client version")
cmds.PersistentFlags().String("api-version", latest.Version, "The version of the API to use against the server (used for viewing resources only)")
cmds.PersistentFlags().String("api-version", latest.Version, "The version of the API to use against the server")
cmds.PersistentFlags().String("certificate-authority", "", "Path to a certificate file for the certificate authority")
cmds.PersistentFlags().String("client-certificate", "", "Path to a client certificate for TLS.")
cmds.PersistentFlags().String("client-key", "", "Path to a client key file for TLS.")

View File

@@ -17,6 +17,7 @@ limitations under the License.
package cmd
import (
"fmt"
"io"
"github.com/GoogleCloudPlatform/kubernetes/pkg/kubectl"
@@ -33,7 +34,8 @@ func (f *Factory) NewCmdGet(out io.Writer) *cobra.Command {
Possible resources include pods (po), replication controllers (rc), services
(se) or minions (mi).
If you specify a Go template, you can use any field defined in pkg/api/types.go.
If you specify a Go template, you can use any fields defined for the API version
you are connecting to the server with.
Examples:
$ kubectl get pods
@@ -54,16 +56,27 @@ Examples:
client, err := f.Client(cmd, mapping)
checkErr(err)
obj, err := kubectl.NewRESTHelper(client, mapping).Get(namespace, name, labels)
checkErr(err)
outputFormat := getFlagString(cmd, "output")
templateFile := getFlagString(cmd, "template")
defaultPrinter, err := f.Printer(cmd, mapping, getFlagBool(cmd, "no-headers"))
checkErr(err)
err = kubectl.Print(out, obj, outputFormat, templateFile, defaultPrinter)
printer, versioned, err := kubectl.GetPrinter(outputFormat, templateFile, defaultPrinter)
checkErr(err)
obj, err := kubectl.NewRESTHelper(client, mapping).Get(namespace, name, labels)
checkErr(err)
if versioned {
// TODO Add an --output-version lock which can ensure that regardless of the
// server version, the client output stays the same.
obj, err = mapping.ObjectConvertor.ConvertToVersion(obj, mapping.APIVersion)
checkErr(err)
}
if err := printer.PrintObj(obj, out); err != nil {
checkErr(fmt.Errorf("Unable to output the provided object: %v", err))
}
},
}
cmd.Flags().StringP("output", "o", "", "Output format: json|yaml|template|templatefile")