Skip to content

Commit 6376353

Browse files
committed
SOLTYSH: oc printing
1 parent fff221f commit 6376353

File tree

3 files changed

+25
-25
lines changed

3 files changed

+25
-25
lines changed

pkg/bulk/cmd.go

+16-12
Original file line numberDiff line numberDiff line change
@@ -232,42 +232,46 @@ func PreferredSerializationOrder(client discovery.DiscoveryInterface) []schema.G
232232
return ret
233233
}
234234

235-
func NewPrintNameOrErrorAfterIndent(mapper meta.RESTMapper, short bool, operation string, out, errs io.Writer, dryRun bool, indent string, prefixForError PrefixForError) AfterFunc {
235+
func NewPrintNameOrErrorAfterIndent(short bool, operation string, out, errs io.Writer, dryRun bool, indent string, prefixForError PrefixForError) AfterFunc {
236236
return func(info *resource.Info, err error) bool {
237237
if err == nil {
238238
fmt.Fprintf(out, indent)
239-
printSuccess(mapper, short, out, info.Mapping.Resource, info.Name, dryRun, operation)
239+
printSuccess(short, out, info.Mapping.GroupVersionKind, info.Name, dryRun, operation)
240240
} else {
241241
fmt.Fprintf(errs, "%s%s: %v\n", indent, prefixForError(err), err)
242242
}
243243
return false
244244
}
245245
}
246246

247-
func printSuccess(mapper meta.RESTMapper, shortOutput bool, out io.Writer, resource, name string, dryRun bool, operation string) {
248-
resource, _ = mapper.ResourceSingularizer(resource)
247+
func printSuccess(shortOutput bool, out io.Writer, gvk schema.GroupVersionKind, name string, dryRun bool, operation string) {
248+
kindString := gvk.Kind
249+
if len(gvk.Group) > 0 {
250+
kindString = gvk.Kind + "." + gvk.Group
251+
}
252+
249253
dryRunMsg := ""
250254
if dryRun {
251255
dryRunMsg = " (dry run)"
252256
}
253257
if shortOutput {
254258
// -o name: prints resource/name
255-
if len(resource) > 0 {
256-
fmt.Fprintf(out, "%s/%s\n", resource, name)
259+
if len(kindString) > 0 {
260+
fmt.Fprintf(out, "%s/%s\n", kindString, name)
257261
} else {
258262
fmt.Fprintf(out, "%s\n", name)
259263
}
260264
} else {
261265
// understandable output by default
262-
if len(resource) > 0 {
263-
fmt.Fprintf(out, "%s \"%s\" %s%s\n", resource, name, operation, dryRunMsg)
266+
if len(kindString) > 0 {
267+
fmt.Fprintf(out, "%s \"%s\" %s%s\n", kindString, name, operation, dryRunMsg)
264268
} else {
265269
fmt.Fprintf(out, "\"%s\" %s%s\n", name, operation, dryRunMsg)
266270
}
267271
}
268272
}
269273

270-
func NewPrintErrorAfter(mapper meta.RESTMapper, errs io.Writer, prefixForError PrefixForError) func(*resource.Info, error) bool {
274+
func NewPrintErrorAfter(errs io.Writer, prefixForError PrefixForError) func(*resource.Info, error) bool {
271275
return func(info *resource.Info, err error) bool {
272276
if err != nil {
273277
fmt.Fprintf(errs, "%s: %v\n", prefixForError(err), err)
@@ -390,12 +394,12 @@ func (b BulkAction) WithMessageAndPrefix(action, individual string, prefixForErr
390394
switch {
391395
// TODO: this should be b printer
392396
case b.Output == "":
393-
b.Bulk.After = NewPrintNameOrErrorAfterIndent(b.Bulk.Mapper, false, individual, b.Out, b.ErrOut, b.DryRun, b.DefaultIndent(), prefixForError)
397+
b.Bulk.After = NewPrintNameOrErrorAfterIndent(false, individual, b.Out, b.ErrOut, b.DryRun, b.DefaultIndent(), prefixForError)
394398
// TODO: needs to be unified with the name printer (incremental vs exact execution), possibly by creating b synthetic printer?
395399
case b.Output == "name":
396-
b.Bulk.After = NewPrintNameOrErrorAfterIndent(b.Bulk.Mapper, true, individual, b.Out, b.ErrOut, b.DryRun, b.DefaultIndent(), prefixForError)
400+
b.Bulk.After = NewPrintNameOrErrorAfterIndent(true, individual, b.Out, b.ErrOut, b.DryRun, b.DefaultIndent(), prefixForError)
397401
default:
398-
b.Bulk.After = NewPrintErrorAfter(b.Bulk.Mapper, b.ErrOut, prefixForError)
402+
b.Bulk.After = NewPrintErrorAfter(b.ErrOut, prefixForError)
399403
if b.StopOnError {
400404
b.Bulk.After = HaltOnError(b.Bulk.After)
401405
}

pkg/cmd/server/admin/create_bootstrappolicy_file.go

+4-5
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,15 @@ import (
1515
"k8s.io/kubernetes/pkg/api/legacyscheme"
1616
kapi "k8s.io/kubernetes/pkg/apis/core"
1717
kcmdutil "k8s.io/kubernetes/pkg/kubectl/cmd/util"
18-
kprinters "k8s.io/kubernetes/pkg/printers"
18+
"k8s.io/kubernetes/pkg/kubectl/genericclioptions/printers"
1919

2020
"github.com/openshift/origin/pkg/api/latest"
2121
"github.com/openshift/origin/pkg/cmd/server/bootstrappolicy"
2222
)
2323

2424
const (
25-
DefaultPolicyFile = "openshift.local.config/master/policy.json"
26-
CreateBootstrapPolicyFileCommand = "create-bootstrap-policy-file"
27-
CreateBootstrapPolicyFileFullCommand = "oc adm " + CreateBootstrapPolicyFileCommand
25+
DefaultPolicyFile = "openshift.local.config/master/policy.json"
26+
CreateBootstrapPolicyFileCommand = "create-bootstrap-policy-file"
2827
)
2928

3029
type CreateBootstrapPolicyFileOptions struct {
@@ -123,7 +122,7 @@ func (o CreateBootstrapPolicyFileOptions) CreateBootstrapPolicyFile() error {
123122
}
124123

125124
buffer := &bytes.Buffer{}
126-
(&kprinters.JSONPrinter{}).PrintObj(versionedPolicyList, buffer)
125+
(&printers.JSONPrinter{}).PrintObj(versionedPolicyList, buffer)
127126

128127
if err := ioutil.WriteFile(o.File, buffer.Bytes(), 0644); err != nil {
129128
return err

pkg/cmd/util/print/print.go

+5-8
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77

88
"k8s.io/apimachinery/pkg/api/meta"
99
"k8s.io/apimachinery/pkg/runtime"
10+
kcmdutil "k8s.io/kubernetes/pkg/kubectl/cmd/util"
1011
)
1112

1213
// VersionedPrintObject handles printing an object in the appropriate version by looking at 'output-version'
@@ -16,19 +17,15 @@ func VersionedPrintObject(scheme *runtime.Scheme, fn func(*cobra.Command, runtim
1617
// TODO: fold into the core printer functionality (preferred output version)
1718

1819
if items, err := meta.ExtractList(obj); err == nil {
19-
items, err = convertItemsForDisplayFromDefaultCommand(scheme, c, items)
20-
if err != nil {
21-
return err
20+
for i := range items {
21+
items[i] = kcmdutil.AsDefaultVersionedOrOriginal(items[i], nil)
2222
}
2323
if err := meta.SetList(obj, items); err != nil {
2424
return err
2525
}
26+
2627
} else {
27-
result, err := convertItemsForDisplayFromDefaultCommand(scheme, c, []runtime.Object{obj})
28-
if err != nil {
29-
return err
30-
}
31-
obj = result[0]
28+
obj = kcmdutil.AsDefaultVersionedOrOriginal(obj, nil)
3229
}
3330
return fn(c, obj, out)
3431
}

0 commit comments

Comments
 (0)