From 2b25c48b1f91df5d6238d51f44af4417b552c076 Mon Sep 17 00:00:00 2001 From: deads2k Date: Fri, 20 Feb 2015 09:03:38 -0500 Subject: [PATCH 1/2] fix kubectl config view to respect serialization formats --- pkg/kubectl/cmd/config/view.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/pkg/kubectl/cmd/config/view.go b/pkg/kubectl/cmd/config/view.go index 95f13c6dcc6..a7f7b67e45c 100644 --- a/pkg/kubectl/cmd/config/view.go +++ b/pkg/kubectl/cmd/config/view.go @@ -26,6 +26,8 @@ import ( "github.com/GoogleCloudPlatform/kubernetes/pkg/client/clientcmd" clientcmdapi "github.com/GoogleCloudPlatform/kubernetes/pkg/client/clientcmd/api" + "github.com/GoogleCloudPlatform/kubernetes/pkg/client/clientcmd/api/latest" + "github.com/GoogleCloudPlatform/kubernetes/pkg/kubectl" cmdutil "github.com/GoogleCloudPlatform/kubernetes/pkg/kubectl/cmd/util" "github.com/GoogleCloudPlatform/kubernetes/pkg/util" ) @@ -51,14 +53,20 @@ Examples: Run: func(cmd *cobra.Command, args []string) { options.complete() - printer, _, err := cmdutil.PrinterForCommand(cmd) + printer, generic, err := cmdutil.PrinterForCommand(cmd) if err != nil { glog.FatalDepth(1, err) } + if generic { + version := cmdutil.OutputVersion(cmd, latest.Version) + printer = kubectl.NewVersionedPrinter(printer, clientcmdapi.Scheme, version) + } + config, err := options.loadConfig() if err != nil { glog.FatalDepth(1, err) } + err = printer.PrintObj(config, out) if err != nil { glog.FatalDepth(1, err) From 6358bf2e302fb18985a63779de255a4972a35dd1 Mon Sep 17 00:00:00 2001 From: deads2k Date: Tue, 24 Feb 2015 08:54:03 -0500 Subject: [PATCH 2/2] add example for default view serialization --- pkg/kubectl/cmd/config/config_test.go | 35 ++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/pkg/kubectl/cmd/config/config_test.go b/pkg/kubectl/cmd/config/config_test.go index 3be8f0ab1c0..75bfe1b8832 100644 --- a/pkg/kubectl/cmd/config/config_test.go +++ b/pkg/kubectl/cmd/config/config_test.go @@ -18,6 +18,7 @@ package config import ( "bytes" + "fmt" "io/ioutil" "os" "reflect" @@ -47,6 +48,36 @@ type configCommandTest struct { expectedOutputs []string } +func ExampleView() { + expectedConfig := newRedFederalCowHammerConfig() + test := configCommandTest{ + args: []string{"view"}, + startingConfig: newRedFederalCowHammerConfig(), + expectedConfig: expectedConfig, + } + + output := test.run(nil) + fmt.Printf("%v", output) + // Output: + // apiVersion: v1 + // clusters: + // - cluster: + // server: http://cow.org:8080 + // name: cow-cluster + // contexts: + // - context: + // cluster: cow-cluster + // user: red-user + // name: federal-context + // current-context: "" + // kind: Config + // preferences: {} + // users: + // - name: red-user + // user: + // token: red-token +} + func TestSetCurrentContext(t *testing.T) { expectedConfig := newRedFederalCowHammerConfig() expectedConfig.CurrentContext = "the-new-context" @@ -540,7 +571,7 @@ func testConfigCommand(args []string, startingConfig clientcmdapi.Config) (strin return buf.String(), *config } -func (test configCommandTest) run(t *testing.T) { +func (test configCommandTest) run(t *testing.T) string { out, actualConfig := testConfigCommand(test.args, test.startingConfig) testSetNilMapsToEmpties(reflect.ValueOf(&test.expectedConfig)) @@ -556,6 +587,8 @@ func (test configCommandTest) run(t *testing.T) { t.Errorf("expected '%s' in output, got '%s'", expectedOutput, out) } } + + return out } func testSetNilMapsToEmpties(curr reflect.Value) { actualCurrValue := curr