Skip to content

Commit 2f18481

Browse files
committed
Removes deprecated kubectl openapi column printing
1 parent 7e97b4b commit 2f18481

File tree

4 files changed

+1
-160
lines changed

4 files changed

+1
-160
lines changed

staging/src/k8s.io/kubectl/pkg/cmd/get/get.go

Lines changed: 1 addition & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ type GetOptions struct {
5757
PrintFlags *PrintFlags
5858
ToPrinter func(*meta.RESTMapping, *bool, bool, bool) (printers.ResourcePrinterFunc, error)
5959
IsHumanReadablePrinter bool
60-
PrintWithOpenAPICols bool
6160

6261
CmdParent string
6362

@@ -137,8 +136,7 @@ var (
137136
)
138137

139138
const (
140-
useOpenAPIPrintColumnFlagLabel = "use-openapi-print-columns"
141-
useServerPrintColumns = "server-print"
139+
useServerPrintColumns = "server-print"
142140
)
143141

144142
var supportedSubresources = []string{"status", "scale"}
@@ -184,7 +182,6 @@ func NewCmdGet(parent string, f cmdutil.Factory, streams genericclioptions.IOStr
184182
cmd.Flags().BoolVar(&o.IgnoreNotFound, "ignore-not-found", o.IgnoreNotFound, "If the requested object does not exist the command will return exit code 0.")
185183
cmd.Flags().StringVar(&o.FieldSelector, "field-selector", o.FieldSelector, "Selector (field query) to filter on, supports '=', '==', and '!='.(e.g. --field-selector key1=value1,key2=value2). The server only supports a limited number of field queries per type.")
186184
cmd.Flags().BoolVarP(&o.AllNamespaces, "all-namespaces", "A", o.AllNamespaces, "If present, list the requested object(s) across all namespaces. Namespace in current context is ignored even if specified with --namespace.")
187-
addOpenAPIPrintColumnFlags(cmd, o)
188185
addServerPrintColumnFlags(cmd, o)
189186
cmdutil.AddFilenameOptionFlags(cmd, &o.FilenameOptions, "identifying the resource to get from a server.")
190187
cmdutil.AddChunkSizeFlag(cmd, &o.ChunkSize)
@@ -241,11 +238,6 @@ func (o *GetOptions) Complete(f cmdutil.Factory, cmd *cobra.Command, args []stri
241238
printFlags := o.PrintFlags.Copy()
242239

243240
if mapping != nil {
244-
if !cmdSpecifiesOutputFmt(cmd) && o.PrintWithOpenAPICols {
245-
if apiSchema, err := f.OpenAPISchema(); err == nil {
246-
printFlags.UseOpenAPIColumns(apiSchema, mapping)
247-
}
248-
}
249241
printFlags.SetKind(mapping.GroupVersionKind.GroupKind())
250242
}
251243
if withNamespace {
@@ -294,11 +286,6 @@ func (o *GetOptions) Complete(f cmdutil.Factory, cmd *cobra.Command, args []stri
294286
}
295287
}
296288

297-
// openapi printing is mutually exclusive with server side printing
298-
if o.PrintWithOpenAPICols && o.ServerPrint {
299-
fmt.Fprintf(o.IOStreams.ErrOut, "warning: --%s requested, --%s will be ignored\n", useOpenAPIPrintColumnFlagLabel, useServerPrintColumns)
300-
}
301-
302289
return nil
303290
}
304291

@@ -433,10 +420,6 @@ func NewRuntimeSorter(objects []runtime.Object, sortBy string) *RuntimeSorter {
433420
}
434421

435422
func (o *GetOptions) transformRequests(req *rest.Request) {
436-
// We need full objects if printing with openapi columns
437-
if o.PrintWithOpenAPICols {
438-
return
439-
}
440423
if !o.ServerPrint || !o.IsHumanReadablePrinter {
441424
return
442425
}
@@ -580,13 +563,6 @@ func (o *GetOptions) Run(f cmdutil.Factory, cmd *cobra.Command, args []string) e
580563
lastMapping = mapping
581564
}
582565

583-
// ensure a versioned object is passed to the custom-columns printer
584-
// if we are using OpenAPI columns to print
585-
if o.PrintWithOpenAPICols {
586-
printer.PrintObj(info.Object, w)
587-
continue
588-
}
589-
590566
printer.PrintObj(info.Object, w)
591567
}
592568
w.Flush()
@@ -830,11 +806,6 @@ func (o *GetOptions) printGeneric(r *resource.Result) error {
830806
return utilerrors.Reduce(utilerrors.Flatten(utilerrors.NewAggregate(errs)))
831807
}
832808

833-
func addOpenAPIPrintColumnFlags(cmd *cobra.Command, opt *GetOptions) {
834-
cmd.Flags().BoolVar(&opt.PrintWithOpenAPICols, useOpenAPIPrintColumnFlagLabel, opt.PrintWithOpenAPICols, "If true, use x-kubernetes-print-column metadata (if present) from the OpenAPI schema for displaying a resource.")
835-
cmd.Flags().MarkDeprecated(useOpenAPIPrintColumnFlagLabel, "deprecated in favor of server-side printing")
836-
}
837-
838809
func addServerPrintColumnFlags(cmd *cobra.Command, opt *GetOptions) {
839810
cmd.Flags().BoolVar(&opt.ServerPrint, useServerPrintColumns, opt.ServerPrint, "If true, have the server return the appropriate table output. Supports extension APIs and CRDs.")
840811
}
@@ -843,10 +814,6 @@ func shouldGetNewPrinterForMapping(printer printers.ResourcePrinter, lastMapping
843814
return printer == nil || lastMapping == nil || mapping == nil || mapping.Resource != lastMapping.Resource
844815
}
845816

846-
func cmdSpecifiesOutputFmt(cmd *cobra.Command) bool {
847-
return cmdutil.GetFlagString(cmd, "output") != ""
848-
}
849-
850817
func multipleGVKsRequested(infos []*resource.Info) bool {
851818
if len(infos) < 2 {
852819
return false

staging/src/k8s.io/kubectl/pkg/cmd/get/get_flags.go

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,10 @@ import (
2222

2323
"github.com/spf13/cobra"
2424

25-
"k8s.io/apimachinery/pkg/api/meta"
2625
"k8s.io/apimachinery/pkg/runtime/schema"
2726
"k8s.io/cli-runtime/pkg/genericclioptions"
2827
"k8s.io/cli-runtime/pkg/printers"
2928
"k8s.io/kubectl/pkg/cmd/util"
30-
"k8s.io/kubectl/pkg/util/openapi"
3129
)
3230

3331
// PrintFlags composes common printer flag structs
@@ -76,35 +74,6 @@ func (f *PrintFlags) AllowedFormats() []string {
7674
return formats
7775
}
7876

79-
// UseOpenAPIColumns modifies the output format, as well as the
80-
// "allowMissingKeys" option for template printers, to values
81-
// defined in the OpenAPI schema of a resource.
82-
func (f *PrintFlags) UseOpenAPIColumns(api openapi.Resources, mapping *meta.RESTMapping) error {
83-
// Found openapi metadata for this resource
84-
schema := api.LookupResource(mapping.GroupVersionKind)
85-
if schema == nil {
86-
// Schema not found, return empty columns
87-
return nil
88-
}
89-
90-
columns, found := openapi.GetPrintColumns(schema.GetExtensions())
91-
if !found {
92-
// Extension not found, return empty columns
93-
return nil
94-
}
95-
96-
parts := strings.SplitN(columns, "=", 2)
97-
if len(parts) < 2 {
98-
return nil
99-
}
100-
101-
allowMissingKeys := true
102-
f.OutputFormat = &parts[0]
103-
f.TemplateFlags.TemplateArgument = &parts[1]
104-
f.TemplateFlags.AllowMissingKeys = &allowMissingKeys
105-
return nil
106-
}
107-
10877
// ToPrinter attempts to find a composed set of PrintFlags suitable for
10978
// returning a printer based on current flag values.
11079
func (f *PrintFlags) ToPrinter() (printers.ResourcePrinter, error) {

staging/src/k8s.io/kubectl/pkg/cmd/get/get_test.go

Lines changed: 0 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import (
2222
"fmt"
2323
"io"
2424
"net/http"
25-
"path/filepath"
2625
"reflect"
2726
"strings"
2827
"testing"
@@ -36,7 +35,6 @@ import (
3635
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
3736
metav1beta1 "k8s.io/apimachinery/pkg/apis/meta/v1beta1"
3837
"k8s.io/apimachinery/pkg/runtime"
39-
"k8s.io/apimachinery/pkg/runtime/schema"
4038
"k8s.io/apimachinery/pkg/runtime/serializer/streaming"
4139
"k8s.io/apimachinery/pkg/util/diff"
4240
"k8s.io/apimachinery/pkg/watch"
@@ -45,11 +43,8 @@ import (
4543
restclient "k8s.io/client-go/rest"
4644
"k8s.io/client-go/rest/fake"
4745
restclientwatch "k8s.io/client-go/rest/watch"
48-
"k8s.io/kube-openapi/pkg/util/proto"
4946
cmdtesting "k8s.io/kubectl/pkg/cmd/testing"
5047
"k8s.io/kubectl/pkg/scheme"
51-
"k8s.io/kubectl/pkg/util/openapi"
52-
openapitesting "k8s.io/kubectl/pkg/util/openapi/testing"
5348
)
5449

5550
var (
@@ -87,11 +82,9 @@ func testComponentStatusData() *corev1.ComponentStatusList {
8782
// Verifies that schemas that are not in the master tree of Kubernetes can be retrieved via Get.
8883
func TestGetUnknownSchemaObject(t *testing.T) {
8984
t.Skip("This test is completely broken. The first thing it does is add the object to the scheme!")
90-
var openapiSchemaPath = filepath.Join("..", "..", "..", "testdata", "openapi", "swagger.json")
9185
tf := cmdtesting.NewTestFactory().WithNamespace("test")
9286
defer tf.Cleanup()
9387
_, _, codec := cmdtesting.NewExternalScheme()
94-
tf.OpenAPISchemaFunc = openapitesting.CreateOpenAPISchemaFunc(openapiSchemaPath)
9588

9689
obj := &cmdtesting.ExternalType{
9790
Kind: "Type",
@@ -161,67 +154,6 @@ func TestGetSchemaObject(t *testing.T) {
161154
}
162155
}
163156

164-
func TestGetObjectsWithOpenAPIOutputFormatPresent(t *testing.T) {
165-
pods, _, _ := cmdtesting.TestData()
166-
167-
tf := cmdtesting.NewTestFactory().WithNamespace("test")
168-
defer tf.Cleanup()
169-
codec := scheme.Codecs.LegacyCodec(scheme.Scheme.PrioritizedVersionsAllGroups()...)
170-
171-
// override the openAPISchema function to return custom output
172-
// for Pod type.
173-
tf.OpenAPISchemaFunc = testOpenAPISchemaData
174-
tf.UnstructuredClient = &fake.RESTClient{
175-
NegotiatedSerializer: resource.UnstructuredPlusDefaultContentConfig().NegotiatedSerializer,
176-
Resp: &http.Response{StatusCode: http.StatusOK, Header: cmdtesting.DefaultHeader(), Body: cmdtesting.ObjBody(codec, &pods.Items[0])},
177-
}
178-
179-
streams, _, buf, _ := genericclioptions.NewTestIOStreams()
180-
cmd := NewCmdGet("kubectl", tf, streams)
181-
cmd.SetOut(buf)
182-
cmd.SetErr(buf)
183-
cmd.Flags().Set(useOpenAPIPrintColumnFlagLabel, "true")
184-
cmd.Run(cmd, []string{"pods", "foo"})
185-
186-
expected := `NAME RSRC
187-
foo 10
188-
`
189-
if e, a := expected, buf.String(); e != a {
190-
t.Errorf("expected\n%v\ngot\n%v", e, a)
191-
}
192-
}
193-
194-
type FakeResources struct {
195-
resources map[schema.GroupVersionKind]proto.Schema
196-
}
197-
198-
func (f FakeResources) LookupResource(s schema.GroupVersionKind) proto.Schema {
199-
return f.resources[s]
200-
}
201-
202-
func (f FakeResources) GetConsumes(gvk schema.GroupVersionKind, operation string) []string {
203-
return nil
204-
}
205-
206-
var _ openapi.Resources = &FakeResources{}
207-
208-
func testOpenAPISchemaData() (openapi.Resources, error) {
209-
return &FakeResources{
210-
resources: map[schema.GroupVersionKind]proto.Schema{
211-
{
212-
Version: "v1",
213-
Kind: "Pod",
214-
}: &proto.Primitive{
215-
BaseSchema: proto.BaseSchema{
216-
Extensions: map[string]interface{}{
217-
"x-kubernetes-print-columns": "custom-columns=NAME:.metadata.name,RSRC:.metadata.resourceVersion",
218-
},
219-
},
220-
},
221-
},
222-
}, nil
223-
}
224-
225157
func TestGetObjects(t *testing.T) {
226158
pods, _, _ := cmdtesting.TestData()
227159

staging/src/k8s.io/kubectl/pkg/util/openapi/extensions.go

Lines changed: 0 additions & 27 deletions
This file was deleted.

0 commit comments

Comments
 (0)