Merge pull request #79530 from liggitt/remove-print-internal
Remove internal object printing from kubectl
This commit is contained in:
@@ -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",
|
||||
|
@@ -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",
|
||||
|
@@ -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
|
||||
|
@@ -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 <unknown>
|
||||
expected := `NAME AGE
|
||||
foo <unknown>
|
||||
`
|
||||
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 <unknown>
|
||||
expected := `NAME AGE
|
||||
pod/foo <unknown>
|
||||
`
|
||||
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 <unknown>
|
||||
pod/bar 0/0 0 <unknown>
|
||||
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
|
||||
service/baz ClusterIP <none> <none> <none> <unknown>
|
||||
expected := `NAME AGE
|
||||
pod/foo <unknown>
|
||||
pod/bar <unknown>
|
||||
NAME AGE
|
||||
service/baz <unknown>
|
||||
`
|
||||
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 <unknown> <none>
|
||||
expected := `NAME AGE LABELS
|
||||
foo <unknown> <none>
|
||||
`
|
||||
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 <unknown>
|
||||
b 0/0 0 <unknown>
|
||||
c 0/0 0 <unknown>
|
||||
expected := `NAME AGE
|
||||
a <unknown>
|
||||
b <unknown>
|
||||
c <unknown>
|
||||
`
|
||||
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 <unknown>
|
||||
expected := `NAME AGE
|
||||
foo <unknown>
|
||||
`
|
||||
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 <unknown>
|
||||
bar 0/0 0 <unknown>
|
||||
expected := `NAME AGE
|
||||
foo <unknown>
|
||||
bar <unknown>
|
||||
`
|
||||
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 <unknown>
|
||||
serverbad <unknown>
|
||||
serverunknown <unknown>
|
||||
`
|
||||
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 <unknown>
|
||||
pod/bar 0/0 0 <unknown>
|
||||
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
|
||||
service/baz ClusterIP <none> <none> <none> <unknown>
|
||||
expected := `NAME AGE
|
||||
pod/foo <unknown>
|
||||
pod/bar <unknown>
|
||||
NAME AGE
|
||||
service/baz <unknown>
|
||||
`
|
||||
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 <unknown>
|
||||
pod/bar 0/0 0 <unknown>
|
||||
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
|
||||
service/baz ClusterIP <none> <none> <none> <unknown>
|
||||
expected := `NAME AGE
|
||||
pod/foo <unknown>
|
||||
pod/bar <unknown>
|
||||
NAME AGE
|
||||
service/baz <unknown>
|
||||
`
|
||||
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 <unknown>
|
||||
pod/bar 0/0 0 <unknown>
|
||||
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
|
||||
service/baz ClusterIP <none> <none> <none> <unknown>
|
||||
expected := `NAME AGE
|
||||
pod/foo <unknown>
|
||||
pod/bar <unknown>
|
||||
NAME AGE
|
||||
service/baz <unknown>
|
||||
`
|
||||
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 <none> <none> <none> <unknown>
|
||||
NAME STATUS ROLES AGE VERSION
|
||||
node/foo Unknown <none> <unknown>
|
||||
expected := `NAME AGE
|
||||
service/baz <unknown>
|
||||
NAME AGE
|
||||
node/foo <unknown>
|
||||
`
|
||||
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 <unknown>
|
||||
foo 0/0 0 <unknown>
|
||||
foo 0/0 0 <unknown>
|
||||
foo 0/0 0 <unknown>
|
||||
expected := `NAME AGE
|
||||
bar <unknown>
|
||||
foo <unknown>
|
||||
foo <unknown>
|
||||
foo <unknown>
|
||||
`
|
||||
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 <unknown>
|
||||
foo 0/0 0 <unknown>
|
||||
foo 0/0 0 <unknown>
|
||||
foo 0/0 0 <unknown>
|
||||
expected := `NAME AGE
|
||||
bar <unknown>
|
||||
foo <unknown>
|
||||
foo <unknown>
|
||||
foo <unknown>
|
||||
`
|
||||
if e, a := expected, buf.String(); e != a {
|
||||
t.Errorf("expected\n%v\ngot\n%v", e, a)
|
||||
@@ -1845,10 +1845,57 @@ 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 <unknown>
|
||||
foo 0/0 0 <unknown>
|
||||
foo 0/0 0 <unknown>
|
||||
expected := `NAME AGE
|
||||
foo <unknown>
|
||||
foo <unknown>
|
||||
foo <unknown>
|
||||
`
|
||||
if e, a := expected, buf.String(); e != a {
|
||||
t.Errorf("expected\n%v\ngot\n%v", e, a)
|
||||
}
|
||||
}
|
||||
|
||||
func TestWatchStatus(t *testing.T) {
|
||||
pods, events := watchTestData()
|
||||
events = append(events, watch.Event{Type: "ERROR", Object: &metav1.Status{Status: "Failure", Reason: "InternalServerError", Message: "Something happened"}})
|
||||
|
||||
tf := cmdtesting.NewTestFactory().WithNamespace("test")
|
||||
defer tf.Cleanup()
|
||||
codec := scheme.Codecs.LegacyCodec(scheme.Scheme.PrioritizedVersionsAllGroups()...)
|
||||
|
||||
tf.UnstructuredClient = &fake.RESTClient{
|
||||
NegotiatedSerializer: resource.UnstructuredPlusDefaultContentConfig().NegotiatedSerializer,
|
||||
Client: fake.CreateHTTPClient(func(req *http.Request) (*http.Response, error) {
|
||||
switch req.URL.Path {
|
||||
case "/namespaces/test/pods/foo":
|
||||
return &http.Response{StatusCode: 200, Header: cmdtesting.DefaultHeader(), Body: cmdtesting.ObjBody(codec, &pods[1])}, nil
|
||||
case "/namespaces/test/pods":
|
||||
if req.URL.Query().Get("watch") == "true" && req.URL.Query().Get("fieldSelector") == "metadata.name=foo" {
|
||||
return &http.Response{StatusCode: 200, Header: cmdtesting.DefaultHeader(), Body: watchBody(codec, events[1:])}, nil
|
||||
}
|
||||
t.Fatalf("request url: %#v,and request: %#v", req.URL, req)
|
||||
return nil, nil
|
||||
default:
|
||||
t.Fatalf("request url: %#v,and request: %#v", req.URL, req)
|
||||
return nil, nil
|
||||
}
|
||||
}),
|
||||
}
|
||||
|
||||
streams, _, buf, _ := genericclioptions.NewTestIOStreams()
|
||||
cmd := NewCmdGet("kubectl", tf, streams)
|
||||
cmd.SetOutput(buf)
|
||||
|
||||
cmd.Flags().Set("watch", "true")
|
||||
cmd.Run(cmd, []string{"pods", "foo"})
|
||||
|
||||
expected := `NAME AGE
|
||||
foo <unknown>
|
||||
foo <unknown>
|
||||
foo <unknown>
|
||||
|
||||
STATUS REASON MESSAGE
|
||||
Failure InternalServerError Something happened
|
||||
`
|
||||
if e, a := expected, buf.String(); e != a {
|
||||
t.Errorf("expected\n%v\ngot\n%v", e, a)
|
||||
@@ -2039,10 +2086,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 <unknown>
|
||||
foo 0/0 0 <unknown>
|
||||
foo 0/0 0 <unknown>
|
||||
expected := `NAME AGE
|
||||
foo <unknown>
|
||||
foo <unknown>
|
||||
foo <unknown>
|
||||
`
|
||||
if e, a := expected, buf.String(); e != a {
|
||||
t.Errorf("expected\n%v\ngot\n%v", e, a)
|
||||
@@ -2082,9 +2129,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 <unknown>
|
||||
foo 0/0 0 <unknown>
|
||||
expected := `NAME AGE
|
||||
foo <unknown>
|
||||
foo <unknown>
|
||||
`
|
||||
if e, a := expected, buf.String(); e != a {
|
||||
t.Errorf("expected\n%v\ngot\n%v", e, a)
|
||||
@@ -2169,9 +2216,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 <unknown>
|
||||
foo 0/0 0 <unknown>
|
||||
expected := `NAME AGE
|
||||
foo <unknown>
|
||||
foo <unknown>
|
||||
`
|
||||
if e, a := expected, buf.String(); e != a {
|
||||
t.Errorf("expected\n%v\ngot\n%v", e, a)
|
||||
|
@@ -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
|
||||
|
||||
|
@@ -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), "<unknown>", "<none>", "<none>", "<none>", "<none>"},
|
||||
}},
|
||||
}
|
||||
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\\ +<unknown>\n",
|
||||
expectedOutput: "NAME\\ +AGE\nfoo\\ +<unknown>\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\\ +<unknown>\\ +<none>\\ +<none>\\ +<none>\\ +<none>\n",
|
||||
expectedOutput: "NAME\\ +AGE\nfoo\\ +<unknown>\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\\ +<unknown>\n",
|
||||
expectedOutput: "foo\\ +<unknown>\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\\ +<unknown>\\ +<none>\\ +<none>\\ +<none>\\ +<none>\n",
|
||||
expectedOutput: "foo\\ +<unknown>\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\\ +<unknown>\n",
|
||||
expectedOutput: "NAME\\ +AGE\npod/foo\\ +<unknown>\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\\ +<unknown>\\ +value\n",
|
||||
expectedOutput: "NAME\\ +AGE\\ +L1\nfoo\\ +<unknown>\\ +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\\ +<unknown>\n",
|
||||
expectedOutput: "NAMESPACE\\ +NAME\\ +AGE\nfoons\\ +foo\\ +<unknown>\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\\ +<unknown>\n",
|
||||
expectedOutput: "NAMESPACE\\ +NAME\\ +READY\\ +STATUS\\ +RESTARTS\\ +AGE\nfoons\\ +foo\\ +0/0\\ +0\\ +<unknown>\n",
|
||||
},
|
||||
{
|
||||
name: "no printer is matched on an invalid outputFormat",
|
||||
|
Reference in New Issue
Block a user