diff --git a/staging/src/k8s.io/cli-runtime/pkg/printers/kyaml.go b/staging/src/k8s.io/cli-runtime/pkg/printers/kyaml.go index 285da2037dc..8b1d69b45f5 100644 --- a/staging/src/k8s.io/cli-runtime/pkg/printers/kyaml.go +++ b/staging/src/k8s.io/cli-runtime/pkg/printers/kyaml.go @@ -54,6 +54,8 @@ func (p *KYAMLPrinter) PrintObj(obj runtime.Object, w io.Writer) error { if InternalObjectPreventer.IsForbidden(reflect.Indirect(reflect.ValueOf(obj.Object.Object)).Type().PkgPath()) { return errors.New(InternalObjectPrinterErr) } + return p.encoder.FromObject(obj, w) + case *runtime.Unknown: return p.encoder.FromYAML(bytes.NewReader(obj.Raw), w) } diff --git a/staging/src/k8s.io/kubectl/pkg/cmd/get/get_test.go b/staging/src/k8s.io/kubectl/pkg/cmd/get/get_test.go index b2822921ca3..ac705c81772 100644 --- a/staging/src/k8s.io/kubectl/pkg/cmd/get/get_test.go +++ b/staging/src/k8s.io/kubectl/pkg/cmd/get/get_test.go @@ -2584,6 +2584,98 @@ object: terminationGracePeriodSeconds: 30 status: {} type: DELETED +`, + }, + { + format: "kyaml", + expected: `--- +{ + type: "ADDED", + object: { + apiVersion: "v1", + kind: "Pod", + metadata: { + name: "bar", + namespace: "test", + resourceVersion: "9", + }, + spec: { + containers: null, + dnsPolicy: "ClusterFirst", + enableServiceLinks: true, + restartPolicy: "Always", + securityContext: {}, + terminationGracePeriodSeconds: 30, + }, + status: {}, + }, +} +--- +{ + type: "ADDED", + object: { + apiVersion: "v1", + kind: "Pod", + metadata: { + name: "foo", + namespace: "test", + resourceVersion: "10", + }, + spec: { + containers: null, + dnsPolicy: "ClusterFirst", + enableServiceLinks: true, + restartPolicy: "Always", + securityContext: {}, + terminationGracePeriodSeconds: 30, + }, + status: {}, + }, +} +--- +{ + type: "MODIFIED", + object: { + apiVersion: "v1", + kind: "Pod", + metadata: { + name: "foo", + namespace: "test", + resourceVersion: "11", + }, + spec: { + containers: null, + dnsPolicy: "ClusterFirst", + enableServiceLinks: true, + restartPolicy: "Always", + securityContext: {}, + terminationGracePeriodSeconds: 30, + }, + status: {}, + }, +} +--- +{ + type: "DELETED", + object: { + apiVersion: "v1", + kind: "Pod", + metadata: { + name: "foo", + namespace: "test", + resourceVersion: "12", + }, + spec: { + containers: null, + dnsPolicy: "ClusterFirst", + enableServiceLinks: true, + restartPolicy: "Always", + securityContext: {}, + terminationGracePeriodSeconds: 30, + }, + status: {}, + }, +} `, }, {