From cf3e75de706187e270b7adf54f246d18e996b962 Mon Sep 17 00:00:00 2001 From: Jordan Liggitt Date: Fri, 28 Jun 2019 08:58:04 -0700 Subject: [PATCH] Remove internal object printing from kubectl --- build/visible_to/BUILD | 1 - pkg/kubectl/.import-restrictions | 1 - pkg/kubectl/cmd/get/BUILD | 5 +- pkg/kubectl/cmd/get/get.go | 42 +----- pkg/kubectl/cmd/get/get_test.go | 134 ++++++++--------- pkg/kubectl/cmd/get/humanreadable_flags.go | 2 - .../cmd/get/humanreadable_flags_test.go | 24 +-- test/cmd/legacy-script.sh | 2 - test/cmd/old-print.sh | 140 ------------------ 9 files changed, 84 insertions(+), 267 deletions(-) delete mode 100755 test/cmd/old-print.sh diff --git a/build/visible_to/BUILD b/build/visible_to/BUILD index 02d5f80657a..c446cc37915 100644 --- a/build/visible_to/BUILD +++ b/build/visible_to/BUILD @@ -384,7 +384,6 @@ package_group( name = "pkg_kubectl_testing_CONSUMERS", packages = [ "//pkg/kubectl", - "//pkg/printers/internalversion", ], ) diff --git a/pkg/kubectl/.import-restrictions b/pkg/kubectl/.import-restrictions index cd0644cc109..22a68dc03ac 100644 --- a/pkg/kubectl/.import-restrictions +++ b/pkg/kubectl/.import-restrictions @@ -59,7 +59,6 @@ "k8s.io/kubernetes/pkg/features", "k8s.io/kubernetes/pkg/kubectl", "k8s.io/kubernetes/pkg/printers", - "k8s.io/kubernetes/pkg/printers/internalversion", "k8s.io/kubernetes/pkg/registry/rbac/reconciliation", "k8s.io/kubernetes/pkg/registry/rbac/validation", "k8s.io/kubernetes/pkg/util/interrupt", diff --git a/pkg/kubectl/cmd/get/BUILD b/pkg/kubectl/cmd/get/BUILD index c62cf65b3c6..f1e4d1a64bd 100644 --- a/pkg/kubectl/cmd/get/BUILD +++ b/pkg/kubectl/cmd/get/BUILD @@ -29,17 +29,14 @@ go_library( importpath = "k8s.io/kubernetes/pkg/kubectl/cmd/get", visibility = ["//visibility:public"], deps = [ - "//pkg/api/legacyscheme:go_default_library", "//pkg/kubectl/cmd/util:go_default_library", "//pkg/kubectl/cmd/util/openapi:go_default_library", "//pkg/kubectl/scheme:go_default_library", "//pkg/kubectl/util/i18n:go_default_library", "//pkg/printers:go_default_library", - "//pkg/printers/internalversion:go_default_library", "//staging/src/k8s.io/api/core/v1:go_default_library", "//staging/src/k8s.io/apimachinery/pkg/api/errors:go_default_library", "//staging/src/k8s.io/apimachinery/pkg/api/meta:go_default_library", - "//staging/src/k8s.io/apimachinery/pkg/apis/meta/internalversion:go_default_library", "//staging/src/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library", "//staging/src/k8s.io/apimachinery/pkg/apis/meta/v1/unstructured:go_default_library", "//staging/src/k8s.io/apimachinery/pkg/apis/meta/v1beta1:go_default_library", @@ -51,6 +48,7 @@ go_library( "//staging/src/k8s.io/cli-runtime/pkg/genericclioptions:go_default_library", "//staging/src/k8s.io/cli-runtime/pkg/printers:go_default_library", "//staging/src/k8s.io/cli-runtime/pkg/resource:go_default_library", + "//staging/src/k8s.io/client-go/kubernetes/scheme:go_default_library", "//staging/src/k8s.io/client-go/rest:go_default_library", "//staging/src/k8s.io/client-go/tools/watch:go_default_library", "//staging/src/k8s.io/client-go/util/jsonpath:go_default_library", @@ -82,7 +80,6 @@ go_test( ], embed = [":go_default_library"], deps = [ - "//pkg/apis/core:go_default_library", "//pkg/kubectl/cmd/testing:go_default_library", "//pkg/kubectl/cmd/util/openapi:go_default_library", "//pkg/kubectl/cmd/util/openapi/testing:go_default_library", diff --git a/pkg/kubectl/cmd/get/get.go b/pkg/kubectl/cmd/get/get.go index d92937a0eff..c0dd9f332d6 100644 --- a/pkg/kubectl/cmd/get/get.go +++ b/pkg/kubectl/cmd/get/get.go @@ -24,29 +24,26 @@ import ( "net/url" "github.com/spf13/cobra" - "k8s.io/klog" corev1 "k8s.io/api/core/v1" kapierrors "k8s.io/apimachinery/pkg/api/errors" "k8s.io/apimachinery/pkg/api/meta" - metainternal "k8s.io/apimachinery/pkg/apis/meta/internalversion" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" metav1beta1 "k8s.io/apimachinery/pkg/apis/meta/v1beta1" "k8s.io/apimachinery/pkg/runtime" - "k8s.io/apimachinery/pkg/runtime/schema" utilerrors "k8s.io/apimachinery/pkg/util/errors" "k8s.io/apimachinery/pkg/util/sets" "k8s.io/apimachinery/pkg/watch" "k8s.io/cli-runtime/pkg/genericclioptions" "k8s.io/cli-runtime/pkg/printers" "k8s.io/cli-runtime/pkg/resource" + kubernetesscheme "k8s.io/client-go/kubernetes/scheme" "k8s.io/client-go/rest" watchtools "k8s.io/client-go/tools/watch" "k8s.io/kubectl/pkg/util/interrupt" utilprinters "k8s.io/kubectl/pkg/util/printers" "k8s.io/kubectl/pkg/util/templates" - "k8s.io/kubernetes/pkg/api/legacyscheme" cmdutil "k8s.io/kubernetes/pkg/kubectl/cmd/util" "k8s.io/kubernetes/pkg/kubectl/util/i18n" utilpointer "k8s.io/utils/pointer" @@ -412,7 +409,7 @@ func NewRuntimeSorter(objects []runtime.Object, sortBy string) *RuntimeSorter { return &RuntimeSorter{ field: parsedField, - decoder: legacyscheme.Codecs.UniversalDecoder(), + decoder: kubernetesscheme.Codecs.UniversalDecoder(), objects: objects, } } @@ -562,14 +559,7 @@ func (o *GetOptions) Run(f cmdutil.Factory, cmd *cobra.Command, args []string) e continue } - internalObj, err := legacyscheme.Scheme.ConvertToVersion(info.Object, info.Mapping.GroupVersionKind.GroupKind().WithVersion(runtime.APIVersionInternal).GroupVersion()) - if err != nil { - // if there's an error, try to print what you have (mirrors old behavior). - klog.V(1).Info(err) - printer.PrintObj(info.Object, w) - } else { - printer.PrintObj(internalObj, w) - } + printer.PrintObj(info.Object, w) } w.Flush() if trackingWriter.Written == 0 && !o.IgnoreNotFound && len(allErrs) == 0 { @@ -666,8 +656,6 @@ func (o *GetOptions) watch(f cmdutil.Factory, cmd *cobra.Command, args []string) writer := utilprinters.GetNewTabWriter(o.Out) - tableGK := metainternal.SchemeGroupVersion.WithKind("Table").GroupKind() - // print the current object var objsToPrint []runtime.Object if isList { @@ -676,11 +664,6 @@ func (o *GetOptions) watch(f cmdutil.Factory, cmd *cobra.Command, args []string) objsToPrint = append(objsToPrint, obj) } for _, objToPrint := range objsToPrint { - if o.IsHumanReadablePrinter && objToPrint.GetObjectKind().GroupVersionKind().GroupKind() != tableGK { - // printing anything other than tables always takes the internal version, but the watch event uses externals - internalGV := mapping.GroupVersionKind.GroupKind().WithVersion(runtime.APIVersionInternal).GroupVersion() - objToPrint = attemptToConvertToInternal(objToPrint, legacyscheme.Scheme, internalGV) - } if err := printer.PrintObj(objToPrint, writer); err != nil { return fmt.Errorf("unable to output the provided object: %v", err) } @@ -705,14 +688,7 @@ func (o *GetOptions) watch(f cmdutil.Factory, cmd *cobra.Command, args []string) intr := interrupt.New(nil, cancel) intr.Run(func() error { _, err := watchtools.UntilWithoutRetry(ctx, w, func(e watch.Event) (bool, error) { - // printing always takes the internal version, but the watch event uses externals - // TODO fix printing to use server-side or be version agnostic - objToPrint := e.Object - if o.IsHumanReadablePrinter && objToPrint.GetObjectKind().GroupVersionKind().GroupKind() != tableGK { - internalGV := mapping.GroupVersionKind.GroupKind().WithVersion(runtime.APIVersionInternal).GroupVersion() - objToPrint = attemptToConvertToInternal(e.Object, legacyscheme.Scheme, internalGV) - } - if err := printer.PrintObj(objToPrint, writer); err != nil { + if err := printer.PrintObj(e.Object, writer); err != nil { return false, err } writer.Flush() @@ -725,16 +701,6 @@ func (o *GetOptions) watch(f cmdutil.Factory, cmd *cobra.Command, args []string) return nil } -// attemptToConvertToInternal tries to convert to an internal type, but returns the original if it can't -func attemptToConvertToInternal(obj runtime.Object, converter runtime.ObjectConvertor, targetVersion schema.GroupVersion) runtime.Object { - internalObject, err := converter.ConvertToVersion(obj, targetVersion) - if err != nil { - klog.V(1).Infof("Unable to convert %T to %v: %v", obj, targetVersion, err) - return obj - } - return internalObject -} - func (o *GetOptions) printGeneric(r *resource.Result) error { // we flattened the data from the builder, so we have individual items, but now we'd like to either: // 1. if there is more than one item, combine them all into a single list diff --git a/pkg/kubectl/cmd/get/get_test.go b/pkg/kubectl/cmd/get/get_test.go index 456e8fd307e..58fa55e1c52 100644 --- a/pkg/kubectl/cmd/get/get_test.go +++ b/pkg/kubectl/cmd/get/get_test.go @@ -235,8 +235,8 @@ func TestGetObjects(t *testing.T) { cmd.SetOutput(buf) cmd.Run(cmd, []string{"pods", "foo"}) - expected := `NAME READY STATUS RESTARTS AGE -foo 0/0 0 + expected := `NAME AGE +foo ` if e, a := expected, buf.String(); e != a { t.Errorf("expected\n%v\ngot\n%v", e, a) @@ -286,8 +286,8 @@ func TestGetObjectsShowKind(t *testing.T) { cmd.Flags().Set("show-kind", "true") cmd.Run(cmd, []string{"pods", "foo"}) - expected := `NAME READY STATUS RESTARTS AGE -pod/foo 0/0 0 + expected := `NAME AGE +pod/foo ` if e, a := expected, buf.String(); e != a { t.Errorf("expected\n%v\ngot\n%v", e, a) @@ -364,11 +364,11 @@ func TestGetMultipleResourceTypesShowKinds(t *testing.T) { cmd.SetOutput(buf) cmd.Run(cmd, []string{"all"}) - expected := `NAME READY STATUS RESTARTS AGE -pod/foo 0/0 0 -pod/bar 0/0 0 -NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE -service/baz ClusterIP + expected := `NAME AGE +pod/foo +pod/bar +NAME AGE +service/baz ` if e, a := expected, buf.String(); e != a { t.Errorf("expected\n%v\ngot\n%v", e, a) @@ -448,8 +448,8 @@ func TestGetObjectsShowLabels(t *testing.T) { cmd.Flags().Set("show-labels", "true") cmd.Run(cmd, []string{"pods", "foo"}) - expected := `NAME READY STATUS RESTARTS AGE LABELS -foo 0/0 0 + expected := `NAME AGE LABELS +foo ` if e, a := expected, buf.String(); e != a { t.Errorf("expected\n%v\ngot\n%v", e, a) @@ -623,10 +623,10 @@ func TestGetSortedObjects(t *testing.T) { cmd.Flags().Set("sort-by", ".metadata.name") cmd.Run(cmd, []string{"pods"}) - expected := `NAME READY STATUS RESTARTS AGE -a 0/0 0 -b 0/0 0 -c 0/0 0 + expected := `NAME AGE +a +b +c ` if e, a := expected, buf.String(); e != a { t.Errorf("expected\n%v\ngot\n%v", e, a) @@ -892,8 +892,8 @@ func TestGetObjectsIdentifiedByFile(t *testing.T) { cmd.Flags().Set("filename", "../../../../test/e2e/testing-manifests/statefulset/cassandra/controller.yaml") cmd.Run(cmd, []string{}) - expected := `NAME READY STATUS RESTARTS AGE -foo 0/0 0 + expected := `NAME AGE +foo ` if e, a := expected, buf.String(); e != a { t.Errorf("expected\n%v\ngot\n%v", e, a) @@ -943,9 +943,9 @@ func TestGetListObjects(t *testing.T) { cmd.SetOutput(buf) cmd.Run(cmd, []string{"pods"}) - expected := `NAME READY STATUS RESTARTS AGE -foo 0/0 0 -bar 0/0 0 + expected := `NAME AGE +foo +bar ` if e, a := expected, buf.String(); e != a { t.Errorf("expected\n%v\ngot\n%v", e, a) @@ -995,10 +995,10 @@ func TestGetListComponentStatus(t *testing.T) { cmd.SetOutput(buf) cmd.Run(cmd, []string{"componentstatuses"}) - expected := `NAME STATUS MESSAGE ERROR -servergood Healthy ok -serverbad Unhealthy bad status: 500 -serverunknown Unhealthy fizzbuzz error + expected := `NAME AGE +servergood +serverbad +serverunknown ` if e, a := expected, buf.String(); e != a { t.Errorf("expected\n%v\ngot\n%v", e, a) @@ -1094,11 +1094,11 @@ func TestGetMultipleTypeObjects(t *testing.T) { cmd.SetOutput(buf) cmd.Run(cmd, []string{"pods,services"}) - expected := `NAME READY STATUS RESTARTS AGE -pod/foo 0/0 0 -pod/bar 0/0 0 -NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE -service/baz ClusterIP + expected := `NAME AGE +pod/foo +pod/bar +NAME AGE +service/baz ` if e, a := expected, buf.String(); e != a { t.Errorf("expected\n%v\ngot\n%v", e, a) @@ -1276,11 +1276,11 @@ func TestGetMultipleTypeObjectsWithLabelSelector(t *testing.T) { cmd.Flags().Set("selector", "a=b") cmd.Run(cmd, []string{"pods,services"}) - expected := `NAME READY STATUS RESTARTS AGE -pod/foo 0/0 0 -pod/bar 0/0 0 -NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE -service/baz ClusterIP + expected := `NAME AGE +pod/foo +pod/bar +NAME AGE +service/baz ` if e, a := expected, buf.String(); e != a { t.Errorf("expected\n%v\ngot\n%v", e, a) @@ -1362,11 +1362,11 @@ func TestGetMultipleTypeObjectsWithFieldSelector(t *testing.T) { cmd.Flags().Set("field-selector", "a=b") cmd.Run(cmd, []string{"pods,services"}) - expected := `NAME READY STATUS RESTARTS AGE -pod/foo 0/0 0 -pod/bar 0/0 0 -NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE -service/baz ClusterIP + expected := `NAME AGE +pod/foo +pod/bar +NAME AGE +service/baz ` if e, a := expected, buf.String(); e != a { t.Errorf("expected\n%v\ngot\n%v", e, a) @@ -1449,10 +1449,10 @@ func TestGetMultipleTypeObjectsWithDirectReference(t *testing.T) { cmd.Run(cmd, []string{"services/bar", "node/foo"}) - expected := `NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE -service/baz ClusterIP -NAME STATUS ROLES AGE VERSION -node/foo Unknown + expected := `NAME AGE +service/baz +NAME AGE +node/foo ` if e, a := expected, buf.String(); e != a { t.Errorf("expected\n%v\ngot\n%v", e, a) @@ -1648,11 +1648,11 @@ func TestWatchLabelSelector(t *testing.T) { cmd.Flags().Set("selector", "a=b") cmd.Run(cmd, []string{"pods"}) - expected := `NAME READY STATUS RESTARTS AGE -bar 0/0 0 -foo 0/0 0 -foo 0/0 0 -foo 0/0 0 + expected := `NAME AGE +bar +foo +foo +foo ` if e, a := expected, buf.String(); e != a { t.Errorf("expected\n%v\ngot\n%v", e, a) @@ -1750,11 +1750,11 @@ func TestWatchFieldSelector(t *testing.T) { cmd.Flags().Set("field-selector", "a=b") cmd.Run(cmd, []string{"pods"}) - expected := `NAME READY STATUS RESTARTS AGE -bar 0/0 0 -foo 0/0 0 -foo 0/0 0 -foo 0/0 0 + expected := `NAME AGE +bar +foo +foo +foo ` if e, a := expected, buf.String(); e != a { t.Errorf("expected\n%v\ngot\n%v", e, a) @@ -1845,10 +1845,10 @@ func TestWatchResource(t *testing.T) { cmd.Flags().Set("watch", "true") cmd.Run(cmd, []string{"pods", "foo"}) - expected := `NAME READY STATUS RESTARTS AGE -foo 0/0 0 -foo 0/0 0 -foo 0/0 0 + expected := `NAME AGE +foo +foo +foo ` if e, a := expected, buf.String(); e != a { t.Errorf("expected\n%v\ngot\n%v", e, a) @@ -2039,10 +2039,10 @@ func TestWatchResourceIdentifiedByFile(t *testing.T) { cmd.Flags().Set("filename", "../../../../test/e2e/testing-manifests/statefulset/cassandra/controller.yaml") cmd.Run(cmd, []string{}) - expected := `NAME READY STATUS RESTARTS AGE -foo 0/0 0 -foo 0/0 0 -foo 0/0 0 + expected := `NAME AGE +foo +foo +foo ` if e, a := expected, buf.String(); e != a { t.Errorf("expected\n%v\ngot\n%v", e, a) @@ -2082,9 +2082,9 @@ func TestWatchOnlyResource(t *testing.T) { cmd.Flags().Set("watch-only", "true") cmd.Run(cmd, []string{"pods", "foo"}) - expected := `NAME READY STATUS RESTARTS AGE -foo 0/0 0 -foo 0/0 0 + expected := `NAME AGE +foo +foo ` if e, a := expected, buf.String(); e != a { t.Errorf("expected\n%v\ngot\n%v", e, a) @@ -2169,9 +2169,9 @@ func TestWatchOnlyList(t *testing.T) { cmd.Flags().Set("watch-only", "true") cmd.Run(cmd, []string{"pods"}) - expected := `NAME READY STATUS RESTARTS AGE -foo 0/0 0 -foo 0/0 0 + expected := `NAME AGE +foo +foo ` if e, a := expected, buf.String(); e != a { t.Errorf("expected\n%v\ngot\n%v", e, a) diff --git a/pkg/kubectl/cmd/get/humanreadable_flags.go b/pkg/kubectl/cmd/get/humanreadable_flags.go index 7d2cfc4aad2..8a6afeca33a 100644 --- a/pkg/kubectl/cmd/get/humanreadable_flags.go +++ b/pkg/kubectl/cmd/get/humanreadable_flags.go @@ -22,7 +22,6 @@ import ( "k8s.io/apimachinery/pkg/runtime/schema" "k8s.io/kubernetes/pkg/printers" - printersinternal "k8s.io/kubernetes/pkg/printers/internalversion" ) // HumanPrintFlags provides default flags necessary for printing. @@ -96,7 +95,6 @@ func (f *HumanPrintFlags) ToPrinter(outputFormat string) (printers.ResourcePrint ColumnLabels: columnLabels, ShowLabels: showLabels, }) - printersinternal.AddHandlers(p) // TODO(juanvallejo): handle sorting here diff --git a/pkg/kubectl/cmd/get/humanreadable_flags_test.go b/pkg/kubectl/cmd/get/humanreadable_flags_test.go index ce90d18daac..8646c3fb5a3 100644 --- a/pkg/kubectl/cmd/get/humanreadable_flags_test.go +++ b/pkg/kubectl/cmd/get/humanreadable_flags_test.go @@ -28,7 +28,6 @@ import ( "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/runtime/schema" "k8s.io/cli-runtime/pkg/genericclioptions" - api "k8s.io/kubernetes/pkg/apis/core" ) func TestHumanReadablePrinterSupportsExpectedOptions(t *testing.T) { @@ -48,19 +47,20 @@ func TestHumanReadablePrinterSupportsExpectedOptions(t *testing.T) { Object: runtime.RawExtension{ Object: &corev1.Pod{ TypeMeta: metav1.TypeMeta{APIVersion: "v1", Kind: "Pod"}, - ObjectMeta: metav1.ObjectMeta{Name: "foo", Labels: map[string]string{"l1": "value"}}, + ObjectMeta: metav1.ObjectMeta{Name: "foo", Namespace: "foons", Labels: map[string]string{"l1": "value"}}, }, }, Cells: []interface{}{"foo", "0/0", "", int64(0), "", "", "", "", ""}, }}, } - testPod := &api.Pod{ + testPod := &corev1.Pod{ TypeMeta: metav1.TypeMeta{ APIVersion: "v1", Kind: "Pod", }, ObjectMeta: metav1.ObjectMeta{ - Name: "foo", + Name: "foo", + Namespace: "foons", Labels: map[string]string{ "l1": "value", }, @@ -89,7 +89,7 @@ func TestHumanReadablePrinterSupportsExpectedOptions(t *testing.T) { { name: "empty output format matches a humanreadable printer", testObject: testPod.DeepCopy(), - expectedOutput: "NAME\\ +READY\\ +STATUS\\ +RESTARTS\\ +AGE\nfoo\\ +0/0\\ +0\\ +\n", + expectedOutput: "NAME\\ +AGE\nfoo\\ +\n", }, { name: "empty output format matches a humanreadable printer", @@ -100,7 +100,7 @@ func TestHumanReadablePrinterSupportsExpectedOptions(t *testing.T) { name: "\"wide\" output format prints", testObject: testPod.DeepCopy(), outputFormat: "wide", - expectedOutput: "NAME\\ +READY\\ +STATUS\\ +RESTARTS\\ +AGE\\ +IP\\ +NODE\\ +NOMINATED NODE\\ +READINESS GATES\nfoo\\ +0/0\\ +0\\ +\\ +\\ +\\ +\\ +\n", + expectedOutput: "NAME\\ +AGE\nfoo\\ +\n", }, { name: "\"wide\" output format prints", @@ -112,7 +112,7 @@ func TestHumanReadablePrinterSupportsExpectedOptions(t *testing.T) { name: "no-headers prints output with no headers", testObject: testPod.DeepCopy(), noHeaders: true, - expectedOutput: "foo\\ +0/0\\ +0\\ +\n", + expectedOutput: "foo\\ +\n", }, { name: "no-headers prints output with no headers", @@ -125,7 +125,7 @@ func TestHumanReadablePrinterSupportsExpectedOptions(t *testing.T) { testObject: testPod.DeepCopy(), outputFormat: "wide", noHeaders: true, - expectedOutput: "foo\\ +0/0\\ +0\\ +\\ +\\ +\\ +\\ +\n", + expectedOutput: "foo\\ +\n", }, { name: "no-headers and a \"wide\" output format prints output with no headers and additional columns", @@ -138,7 +138,7 @@ func TestHumanReadablePrinterSupportsExpectedOptions(t *testing.T) { name: "show-kind displays the resource's kind, even when printing a single type of resource", testObject: testPod.DeepCopy(), showKind: true, - expectedOutput: "NAME\\ +READY\\ +STATUS\\ +RESTARTS\\ +AGE\npod/foo\\ +0/0\\ +0\\ +\n", + expectedOutput: "NAME\\ +AGE\npod/foo\\ +\n", }, { name: "show-kind displays the resource's kind, even when printing a single type of resource", @@ -150,7 +150,7 @@ func TestHumanReadablePrinterSupportsExpectedOptions(t *testing.T) { name: "label-columns prints specified label values in new column", testObject: testPod.DeepCopy(), columnLabels: []string{"l1"}, - expectedOutput: "NAME\\ +READY\\ +STATUS\\ +RESTARTS\\ +AGE\\ +L1\nfoo\\ +0/0\\ +0\\ +\\ +value\n", + expectedOutput: "NAME\\ +AGE\\ +L1\nfoo\\ +\\ +value\n", }, { name: "label-columns prints specified label values in new column", @@ -162,13 +162,13 @@ func TestHumanReadablePrinterSupportsExpectedOptions(t *testing.T) { name: "withNamespace displays an additional NAMESPACE column", testObject: testPod.DeepCopy(), withNamespace: true, - expectedOutput: "NAMESPACE\\ +NAME\\ +READY\\ +STATUS\\ +RESTARTS\\ +AGE\n\\ +foo\\ +0/0\\ +0\\ +\n", + expectedOutput: "NAMESPACE\\ +NAME\\ +AGE\nfoons\\ +foo\\ +\n", }, { name: "withNamespace displays an additional NAMESPACE column", testObject: testTable.DeepCopy(), withNamespace: true, - expectedOutput: "NAMESPACE\\ +NAME\\ +READY\\ +STATUS\\ +RESTARTS\\ +AGE\n\\ +foo\\ +0/0\\ +0\\ +\n", + expectedOutput: "NAMESPACE\\ +NAME\\ +READY\\ +STATUS\\ +RESTARTS\\ +AGE\nfoons\\ +foo\\ +0/0\\ +0\\ +\n", }, { name: "no printer is matched on an invalid outputFormat", diff --git a/test/cmd/legacy-script.sh b/test/cmd/legacy-script.sh index 846dfbb8026..f2219f4491d 100755 --- a/test/cmd/legacy-script.sh +++ b/test/cmd/legacy-script.sh @@ -44,7 +44,6 @@ source "${KUBE_ROOT}/test/cmd/get.sh" source "${KUBE_ROOT}/test/cmd/kubeadm.sh" source "${KUBE_ROOT}/test/cmd/kubeconfig.sh" source "${KUBE_ROOT}/test/cmd/node-management.sh" -source "${KUBE_ROOT}/test/cmd/old-print.sh" source "${KUBE_ROOT}/test/cmd/plugins.sh" source "${KUBE_ROOT}/test/cmd/proxy.sh" source "${KUBE_ROOT}/test/cmd/rbac.sh" @@ -503,7 +502,6 @@ runTests() { if kube::test::if_supports_resource "${pods}" ; then record_command run_kubectl_get_tests - record_command run_kubectl_old_print_tests fi ################ diff --git a/test/cmd/old-print.sh b/test/cmd/old-print.sh deleted file mode 100755 index 6bdcbe9db91..00000000000 --- a/test/cmd/old-print.sh +++ /dev/null @@ -1,140 +0,0 @@ -#!/usr/bin/env bash - -# Copyright 2018 The Kubernetes Authors. -# -# 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. - -set -o errexit -set -o nounset -set -o pipefail - -run_kubectl_old_print_tests() { - set -o nounset - set -o errexit - - create_and_use_new_namespace - kube::log::status "Testing kubectl get --server-print=false" - ### Test retrieval of all types in discovery - # Pre-condition: no resources exist - output_message=$(kubectl get pods --server-print=false 2>&1 "${kube_flags[@]:?}") - # Post-condition: Expect text indicating no resources were found - kube::test::if_has_string "${output_message}" 'No resources found.' - - ### Test retrieval of pods against server-side printing - kubectl create -f test/fixtures/doc-yaml/admin/limitrange/valid-pod.yaml "${kube_flags[@]}" - # Post-condition: valid-pod POD is created - kube::test::get_object_assert pods "{{range.items}}{{${id_field:?}}}:{{end}}" 'valid-pod:' - # Compare "old" output with experimental output and ensure both are the same - # remove the last column, as it contains the object's AGE, which could cause a mismatch. - expected_output=$(kubectl get pod "${kube_flags[@]}" | awk 'NF{NF--};1') - actual_output=$(kubectl get pod --server-print=false "${kube_flags[@]}" | awk 'NF{NF--};1') - kube::test::if_has_string "${actual_output}" "${expected_output}" - - # Test printing objects with --use-openapi-print-columns - actual_output=$(kubectl get namespaces --use-openapi-print-columns --v=7 "${kube_flags[@]}" 2>&1) - # it should request full objects (not server-side printing) - kube::test::if_has_not_string "${actual_output}" 'application/json;as=Table' - kube::test::if_has_string "${actual_output}" 'application/json' - - ### Test retrieval of daemonsets against server-side printing - kubectl apply -f hack/testdata/rollingupdate-daemonset.yaml "${kube_flags[@]}" - # Post-condition: daemonset is created - kube::test::get_object_assert ds "{{range.items}}{{$id_field}}:{{end}}" 'bind:' - # Compare "old" output with experimental output and ensure both are the same - # remove the last column, as it contains the object's AGE, which could cause a mismatch. - expected_output=$(kubectl get ds "${kube_flags[@]}" | awk 'NF{NF--};1') - actual_output=$(kubectl get ds --server-print=false "${kube_flags[@]}" | awk 'NF{NF--};1') - kube::test::if_has_string "${actual_output}" "${expected_output}" - - ### Test retrieval of replicationcontrollers against server-side printing - kubectl create -f hack/testdata/frontend-controller.yaml "${kube_flags[@]}" - # Post-condition: frontend replication controller is created - kube::test::get_object_assert rc "{{range.items}}{{$id_field}}:{{end}}" 'frontend:' - # Compare "old" output with experimental output and ensure both are the same - # remove the last column, as it contains the object's AGE, which could cause a mismatch. - expected_output=$(kubectl get rc "${kube_flags[@]}" | awk 'NF{NF--};1') - actual_output=$(kubectl get rc --server-print=false "${kube_flags[@]}" | awk 'NF{NF--};1') - kube::test::if_has_string "${actual_output}" "${expected_output}" - - ### Test retrieval of replicasets against server-side printing - kubectl create -f hack/testdata/frontend-replicaset.yaml "${kube_flags[@]}" - # Post-condition: frontend replica set is created - kube::test::get_object_assert rs "{{range.items}}{{$id_field}}:{{end}}" 'frontend:' - # Compare "old" output with experimental output and ensure both are the same - # remove the last column, as it contains the object's AGE, which could cause a mismatch. - expected_output=$(kubectl get rs "${kube_flags[@]}" | awk 'NF{NF--};1') - actual_output=$(kubectl get rs --server-print=false "${kube_flags[@]}" | awk 'NF{NF--};1') - kube::test::if_has_string "${actual_output}" "${expected_output}" - - ### Test retrieval of jobs against server-side printing - kubectl run pi --generator=job/v1 "--image=$IMAGE_PERL" --restart=OnFailure -- perl -Mbignum=bpi -wle 'print bpi(20)' "${kube_flags[@]}" - # Post-Condition: assertion object exists - kube::test::get_object_assert jobs "{{range.items}}{{$id_field}}:{{end}}" 'pi:' - # Compare "old" output with experimental output and ensure both are the same - # remove the last column, as it contains the object's AGE, which could cause a mismatch. - expected_output=$(kubectl get jobs/pi "${kube_flags[@]}" | awk 'NF{NF--};1') - actual_output=$(kubectl get jobs/pi --server-print=false "${kube_flags[@]}" | awk 'NF{NF--};1') - kube::test::if_has_string "${actual_output}" "${expected_output}" - - ### Test retrieval of clusterroles against server-side printing - kubectl create "${kube_flags[@]}" clusterrole sample-role --verb=* --resource=pods - # Post-Condition: assertion object exists - kube::test::get_object_assert clusterrole/sample-role "{{range.rules}}{{range.resources}}{{.}}:{{end}}{{end}}" 'pods:' - # Compare "old" output with experimental output and ensure both are the same - # remove the last column, as it contains the object's AGE, which could cause a mismatch. - expected_output=$(kubectl get clusterroles/sample-role "${kube_flags[@]}" | awk 'NF{NF--};1') - actual_output=$(kubectl get clusterroles/sample-role --server-print=false "${kube_flags[@]}" | awk 'NF{NF--};1') - kube::test::if_has_string "${actual_output}" "${expected_output}" - - ### Test retrieval of crds against server-side printing - kubectl "${kube_flags_with_token[@]:?}" create -f - << __EOF__ -{ - "kind": "CustomResourceDefinition", - "apiVersion": "apiextensions.k8s.io/v1beta1", - "metadata": { - "name": "foos.company.com" - }, - "spec": { - "group": "company.com", - "version": "v1", - "scope": "Namespaced", - "names": { - "plural": "foos", - "kind": "Foo" - } - } -} -__EOF__ - - # Post-Condition: assertion object exists - kube::test::get_object_assert customresourcedefinitions "{{range.items}}{{if eq $id_field \\\"foos.company.com\\\"}}{{$id_field}}:{{end}}{{end}}" 'foos.company.com:' - - # Test that we can list this new CustomResource - kube::test::get_object_assert foos "{{range.items}}{{$id_field}}:{{end}}" '' - # Compare "old" output with experimental output and ensure both are the same - expected_output=$(kubectl get foos "${kube_flags[@]}" | awk 'NF{NF--};1') - actual_output=$(kubectl get foos --server-print=false "${kube_flags[@]}" | awk 'NF{NF--};1') - kube::test::if_has_string "${actual_output}" "${expected_output}" - - # teardown - kubectl delete customresourcedefinitions/foos.company.com "${kube_flags_with_token[@]}" - kubectl delete clusterroles/sample-role "${kube_flags_with_token[@]}" - kubectl delete jobs pi "${kube_flags[@]}" - kubectl delete rs frontend "${kube_flags[@]}" - kubectl delete rc frontend "${kube_flags[@]}" - kubectl delete ds bind "${kube_flags[@]}" - kubectl delete pod valid-pod "${kube_flags[@]}" - - set +o nounset - set +o errexit -}