forked from openshift/origin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
printer.go
759 lines (668 loc) · 28.7 KB
/
printer.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
package describe
import (
"fmt"
"io"
"regexp"
"sort"
"strings"
"text/tabwriter"
"time"
"k8s.io/kubernetes/pkg/api/unversioned"
kctl "k8s.io/kubernetes/pkg/kubectl"
"k8s.io/kubernetes/pkg/labels"
"k8s.io/kubernetes/pkg/util/sets"
authorizationapi "github.com/openshift/origin/pkg/authorization/api"
buildapi "github.com/openshift/origin/pkg/build/api"
deployapi "github.com/openshift/origin/pkg/deploy/api"
imageapi "github.com/openshift/origin/pkg/image/api"
oauthapi "github.com/openshift/origin/pkg/oauth/api"
projectapi "github.com/openshift/origin/pkg/project/api"
routeapi "github.com/openshift/origin/pkg/route/api"
sdnapi "github.com/openshift/origin/pkg/sdn/api"
templateapi "github.com/openshift/origin/pkg/template/api"
userapi "github.com/openshift/origin/pkg/user/api"
)
var (
buildColumns = []string{"NAME", "TYPE", "FROM", "STATUS", "STARTED", "DURATION"}
buildConfigColumns = []string{"NAME", "TYPE", "FROM", "LATEST"}
imageColumns = []string{"NAME", "DOCKER REF"}
imageStreamTagColumns = []string{"NAME", "DOCKER REF", "UPDATED", "IMAGENAME"}
imageStreamImageColumns = []string{"NAME", "DOCKER REF", "UPDATED", "IMAGENAME"}
imageStreamColumns = []string{"NAME", "DOCKER REPO", "TAGS", "UPDATED"}
projectColumns = []string{"NAME", "DISPLAY NAME", "STATUS"}
routeColumns = []string{"NAME", "HOST/PORT", "PATH", "SERVICE", "LABELS", "INSECURE POLICY", "TLS TERMINATION"}
deploymentColumns = []string{"NAME", "STATUS", "CAUSE"}
deploymentConfigColumns = []string{"NAME", "TRIGGERS", "LATEST"}
templateColumns = []string{"NAME", "DESCRIPTION", "PARAMETERS", "OBJECTS"}
policyColumns = []string{"NAME", "ROLES", "LAST MODIFIED"}
policyBindingColumns = []string{"NAME", "ROLE BINDINGS", "LAST MODIFIED"}
roleBindingColumns = []string{"NAME", "ROLE", "USERS", "GROUPS", "SERVICE ACCOUNTS", "SUBJECTS"}
roleColumns = []string{"NAME"}
oauthClientColumns = []string{"NAME", "SECRET", "WWW-CHALLENGE", "REDIRECT URIS"}
oauthClientAuthorizationColumns = []string{"NAME", "USER NAME", "CLIENT NAME", "SCOPES"}
oauthAccessTokenColumns = []string{"NAME", "USER NAME", "CLIENT NAME", "CREATED", "EXPIRES", "REDIRECT URI", "SCOPES"}
oauthAuthorizeTokenColumns = []string{"NAME", "USER NAME", "CLIENT NAME", "CREATED", "EXPIRES", "REDIRECT URI", "SCOPES"}
userColumns = []string{"NAME", "UID", "FULL NAME", "IDENTITIES"}
identityColumns = []string{"NAME", "IDP NAME", "IDP USER NAME", "USER NAME", "USER UID"}
userIdentityMappingColumns = []string{"NAME", "IDENTITY", "USER NAME", "USER UID"}
groupColumns = []string{"NAME", "USERS"}
// IsPersonalSubjectAccessReviewColumns contains known custom role extensions
IsPersonalSubjectAccessReviewColumns = []string{"NAME"}
hostSubnetColumns = []string{"NAME", "HOST", "HOST IP", "SUBNET"}
netNamespaceColumns = []string{"NAME", "NETID"}
clusterNetworkColumns = []string{"NAME", "NETWORK", "HOST SUBNET LENGTH", "SERVICE NETWORK"}
)
// NewHumanReadablePrinter returns a new HumanReadablePrinter
func NewHumanReadablePrinter(noHeaders, withNamespace, wide bool, showAll bool, columnLabels []string) *kctl.HumanReadablePrinter {
// TODO: support cross namespace listing
p := kctl.NewHumanReadablePrinter(noHeaders, withNamespace, wide, showAll, columnLabels)
p.Handler(buildColumns, printBuild)
p.Handler(buildColumns, printBuildList)
p.Handler(buildConfigColumns, printBuildConfig)
p.Handler(buildConfigColumns, printBuildConfigList)
p.Handler(imageColumns, printImage)
p.Handler(imageStreamTagColumns, printImageStreamTag)
p.Handler(imageStreamTagColumns, printImageStreamTagList)
p.Handler(imageStreamImageColumns, printImageStreamImage)
p.Handler(imageColumns, printImageList)
p.Handler(imageStreamColumns, printImageStream)
p.Handler(imageStreamColumns, printImageStreamList)
p.Handler(projectColumns, printProject)
p.Handler(projectColumns, printProjectList)
p.Handler(routeColumns, printRoute)
p.Handler(routeColumns, printRouteList)
p.Handler(deploymentConfigColumns, printDeploymentConfig)
p.Handler(deploymentConfigColumns, printDeploymentConfigList)
p.Handler(templateColumns, printTemplate)
p.Handler(templateColumns, printTemplateList)
p.Handler(policyColumns, printPolicy)
p.Handler(policyColumns, printPolicyList)
p.Handler(policyBindingColumns, printPolicyBinding)
p.Handler(policyBindingColumns, printPolicyBindingList)
p.Handler(roleBindingColumns, printRoleBinding)
p.Handler(roleBindingColumns, printRoleBindingList)
p.Handler(roleColumns, printRole)
p.Handler(roleColumns, printRoleList)
p.Handler(policyColumns, printClusterPolicy)
p.Handler(policyColumns, printClusterPolicyList)
p.Handler(policyBindingColumns, printClusterPolicyBinding)
p.Handler(policyBindingColumns, printClusterPolicyBindingList)
p.Handler(roleColumns, printClusterRole)
p.Handler(roleColumns, printClusterRoleList)
p.Handler(roleBindingColumns, printClusterRoleBinding)
p.Handler(roleBindingColumns, printClusterRoleBindingList)
p.Handler(oauthClientColumns, printOAuthClient)
p.Handler(oauthClientColumns, printOAuthClientList)
p.Handler(oauthClientAuthorizationColumns, printOAuthClientAuthorization)
p.Handler(oauthClientAuthorizationColumns, printOAuthClientAuthorizationList)
p.Handler(oauthAccessTokenColumns, printOAuthAccessToken)
p.Handler(oauthAccessTokenColumns, printOAuthAccessTokenList)
p.Handler(oauthAuthorizeTokenColumns, printOAuthAuthorizeToken)
p.Handler(oauthAuthorizeTokenColumns, printOAuthAuthorizeTokenList)
p.Handler(userColumns, printUser)
p.Handler(userColumns, printUserList)
p.Handler(identityColumns, printIdentity)
p.Handler(identityColumns, printIdentityList)
p.Handler(userIdentityMappingColumns, printUserIdentityMapping)
p.Handler(groupColumns, printGroup)
p.Handler(groupColumns, printGroupList)
p.Handler(IsPersonalSubjectAccessReviewColumns, printIsPersonalSubjectAccessReview)
p.Handler(hostSubnetColumns, printHostSubnet)
p.Handler(hostSubnetColumns, printHostSubnetList)
p.Handler(netNamespaceColumns, printNetNamespaceList)
p.Handler(netNamespaceColumns, printNetNamespace)
p.Handler(clusterNetworkColumns, printClusterNetwork)
p.Handler(clusterNetworkColumns, printClusterNetworkList)
return p
}
const templateDescriptionLen = 80
// PrintTemplateParameters the Template parameters with their default values
func PrintTemplateParameters(params []templateapi.Parameter, output io.Writer) error {
w := tabwriter.NewWriter(output, 20, 5, 3, ' ', 0)
defer w.Flush()
parameterColumns := []string{"NAME", "DESCRIPTION", "GENERATOR", "VALUE"}
fmt.Fprintf(w, "%s\n", strings.Join(parameterColumns, "\t"))
for _, p := range params {
value := p.Value
if len(p.Generate) != 0 {
value = p.From
}
_, err := fmt.Fprintf(w, "%s\t%s\t%s\t%s\n", p.Name, p.Description, p.Generate, value)
if err != nil {
return err
}
}
return nil
}
func printTemplate(t *templateapi.Template, w io.Writer, withNamespace, wide, showAll bool, columnLabels []string) error {
description := ""
if t.Annotations != nil {
description = t.Annotations["description"]
}
if len(description) > templateDescriptionLen {
description = strings.TrimSpace(description[:templateDescriptionLen-3]) + "..."
}
empty, generated, total := 0, 0, len(t.Parameters)
for _, p := range t.Parameters {
if len(p.Value) > 0 {
continue
}
if len(p.Generate) > 0 {
generated++
continue
}
empty++
}
params := ""
switch {
case empty > 0:
params = fmt.Sprintf("%d (%d blank)", total, empty)
case generated > 0:
params = fmt.Sprintf("%d (%d generated)", total, generated)
default:
params = fmt.Sprintf("%d (all set)", total)
}
if withNamespace {
if _, err := fmt.Fprintf(w, "%s\t", t.Namespace); err != nil {
return err
}
}
_, err := fmt.Fprintf(w, "%s\t%s\t%s\t%d\n", t.Name, description, params, len(t.Objects))
return err
}
func printTemplateList(list *templateapi.TemplateList, w io.Writer, withNamespace, wide, showAll bool, columnLabels []string) error {
for _, t := range list.Items {
if err := printTemplate(&t, w, withNamespace, wide, showAll, columnLabels); err != nil {
return err
}
}
return nil
}
func printBuild(build *buildapi.Build, w io.Writer, withNamespace, wide, showAll bool, columnLabels []string) error {
if withNamespace {
if _, err := fmt.Fprintf(w, "%s\t", build.Namespace); err != nil {
return err
}
}
var created string
if build.Status.StartTimestamp != nil {
created = fmt.Sprintf("%s ago", formatRelativeTime(build.Status.StartTimestamp.Time))
}
var duration string
if build.Status.Duration > 0 {
duration = build.Status.Duration.String()
}
from := describeSourceShort(build.Spec)
status := string(build.Status.Phase)
if len(build.Status.Reason) > 0 {
status = fmt.Sprintf("%s (%s)", status, build.Status.Reason)
}
_, err := fmt.Fprintf(w, "%s\t%s\t%s\t%s\t%s\t%s\n", build.Name, buildapi.StrategyType(build.Spec.Strategy), from, status, created, duration)
return err
}
func describeSourceShort(spec buildapi.BuildSpec) string {
var from string
switch source := spec.Source; {
case source.Binary != nil:
from = "Binary"
if rev := describeSourceGitRevision(spec); len(rev) != 0 {
from = fmt.Sprintf("%s@%s", from, rev)
}
case source.Dockerfile != nil && source.Git != nil:
from = "Dockerfile,Git"
if rev := describeSourceGitRevision(spec); len(rev) != 0 {
from = fmt.Sprintf("%s@%s", from, rev)
}
case source.Dockerfile != nil:
from = "Dockerfile"
case source.Git != nil:
from = "Git"
if rev := describeSourceGitRevision(spec); len(rev) != 0 {
from = fmt.Sprintf("%s@%s", from, rev)
}
default:
from = buildapi.SourceType(source)
}
return from
}
var nonCommitRev = regexp.MustCompile("[^a-fA-F0-9]")
func describeSourceGitRevision(spec buildapi.BuildSpec) string {
var rev string
if spec.Revision != nil && spec.Revision.Git != nil {
rev = spec.Revision.Git.Commit
}
if len(rev) == 0 && spec.Source.Git != nil {
rev = spec.Source.Git.Ref
}
// if this appears to be a full Git commit hash, shorten it to 7 characters for brevity
if !nonCommitRev.MatchString(rev) && len(rev) > 20 {
rev = rev[:7]
}
return rev
}
func printBuildList(buildList *buildapi.BuildList, w io.Writer, withNamespace, wide, showAll bool, columnLabels []string) error {
builds := buildList.Items
sort.Sort(buildapi.BuildSliceByCreationTimestamp(builds))
for _, build := range builds {
if err := printBuild(&build, w, withNamespace, wide, showAll, columnLabels); err != nil {
return err
}
}
return nil
}
func printBuildConfig(bc *buildapi.BuildConfig, w io.Writer, withNamespace, wide, showAll bool, columnLabels []string) error {
if bc.Spec.Strategy.CustomStrategy != nil {
_, err := fmt.Fprintf(w, "%s\t%v\t%s\t%d\n", bc.Name, buildapi.StrategyType(bc.Spec.Strategy), bc.Spec.Strategy.CustomStrategy.From.Name, bc.Status.LastVersion)
return err
}
from := describeSourceShort(bc.Spec.BuildSpec)
if withNamespace {
if _, err := fmt.Fprintf(w, "%s\t", bc.Namespace); err != nil {
return err
}
}
_, err := fmt.Fprintf(w, "%s\t%v\t%s\t%d\n", bc.Name, buildapi.StrategyType(bc.Spec.Strategy), from, bc.Status.LastVersion)
return err
}
func printBuildConfigList(buildList *buildapi.BuildConfigList, w io.Writer, withNamespace, wide, showAll bool, columnLabels []string) error {
for _, buildConfig := range buildList.Items {
if err := printBuildConfig(&buildConfig, w, withNamespace, wide, showAll, columnLabels); err != nil {
return err
}
}
return nil
}
func printImage(image *imageapi.Image, w io.Writer, withNamespace, wide, showAll bool, columnLabels []string) error {
_, err := fmt.Fprintf(w, "%s\t%s\n", image.Name, image.DockerImageReference)
return err
}
func printImageStreamTag(ist *imageapi.ImageStreamTag, w io.Writer, withNamespace, wide, showAll bool, columnLabels []string) error {
created := fmt.Sprintf("%s ago", formatRelativeTime(ist.CreationTimestamp.Time))
if withNamespace {
if _, err := fmt.Fprintf(w, "%s\t", ist.Namespace); err != nil {
return err
}
}
_, err := fmt.Fprintf(w, "%s\t%s\t%s\t%s\n", ist.Name, ist.Image.DockerImageReference, created, ist.Image.Name)
return err
}
func printImageStreamTagList(list *imageapi.ImageStreamTagList, w io.Writer, withNamespace, wide, showAll bool, columnLabels []string) error {
for _, ist := range list.Items {
if err := printImageStreamTag(&ist, w, withNamespace, wide, showAll, columnLabels); err != nil {
return err
}
}
return nil
}
func printImageStreamImage(isi *imageapi.ImageStreamImage, w io.Writer, withNamespace, wide, showAll bool, columnLabels []string) error {
created := fmt.Sprintf("%s ago", formatRelativeTime(isi.CreationTimestamp.Time))
if withNamespace {
if _, err := fmt.Fprintf(w, "%s\t", isi.Namespace); err != nil {
return err
}
}
_, err := fmt.Fprintf(w, "%s\t%s\t%s\t%s\n", isi.Name, isi.Image.DockerImageReference, created, isi.Image.Name)
return err
}
func printImageList(images *imageapi.ImageList, w io.Writer, withNamespace, wide, showAll bool, columnLabels []string) error {
for _, image := range images.Items {
if err := printImage(&image, w, withNamespace, wide, showAll, columnLabels); err != nil {
return err
}
}
return nil
}
func printImageStream(stream *imageapi.ImageStream, w io.Writer, withNamespace, wide, showAll bool, columnLabels []string) error {
tags := ""
const numOfTagsShown = 3
var latest unversioned.Time
for _, list := range stream.Status.Tags {
if len(list.Items) > 0 {
if list.Items[0].Created.After(latest.Time) {
latest = list.Items[0].Created
}
}
}
latestTime := ""
if !latest.IsZero() {
latestTime = fmt.Sprintf("%s ago", formatRelativeTime(latest.Time))
}
list := imageapi.SortStatusTags(stream.Status.Tags)
more := false
if len(list) > numOfTagsShown {
list = list[:numOfTagsShown]
more = true
}
tags = strings.Join(list, ",")
if more {
tags = fmt.Sprintf("%s + %d more...", tags, len(stream.Status.Tags)-numOfTagsShown)
}
if withNamespace {
if _, err := fmt.Fprintf(w, "%s\t", stream.Namespace); err != nil {
return err
}
}
repo := stream.Spec.DockerImageRepository
if len(repo) == 0 {
repo = stream.Status.DockerImageRepository
}
_, err := fmt.Fprintf(w, "%s\t%s\t%s\t%s\n", stream.Name, repo, tags, latestTime)
return err
}
func printImageStreamList(streams *imageapi.ImageStreamList, w io.Writer, withNamespace, wide, showAll bool, columnLabels []string) error {
for _, stream := range streams.Items {
if err := printImageStream(&stream, w, withNamespace, wide, showAll, columnLabels); err != nil {
return err
}
}
return nil
}
func printProject(project *projectapi.Project, w io.Writer, withNamespace, wide, showAll bool, columnLabels []string) error {
_, err := fmt.Fprintf(w, "%s\t%s\t%s\n", project.Name, project.Annotations[projectapi.ProjectDisplayName], project.Status.Phase)
return err
}
// SortableProjects is a list of projects that can be sorted
type SortableProjects []projectapi.Project
func (list SortableProjects) Len() int {
return len(list)
}
func (list SortableProjects) Swap(i, j int) {
list[i], list[j] = list[j], list[i]
}
func (list SortableProjects) Less(i, j int) bool {
return list[i].ObjectMeta.Name < list[j].ObjectMeta.Name
}
func printProjectList(projects *projectapi.ProjectList, w io.Writer, withNamespace, wide, showAll bool, columnLabels []string) error {
sort.Sort(SortableProjects(projects.Items))
for _, project := range projects.Items {
if err := printProject(&project, w, withNamespace, wide, showAll, columnLabels); err != nil {
return err
}
}
return nil
}
func printRoute(route *routeapi.Route, w io.Writer, withNamespace, wide, showAll bool, columnLabels []string) error {
tlsTerm := ""
insecurePolicy := ""
if route.Spec.TLS != nil {
tlsTerm = string(route.Spec.TLS.Termination)
insecurePolicy = string(route.Spec.TLS.InsecureEdgeTerminationPolicy)
}
if withNamespace {
if _, err := fmt.Fprintf(w, "%s\t", route.Namespace); err != nil {
return err
}
}
_, err := fmt.Fprintf(w, "%s\t%s\t%s\t%s\t%s\t%s\t%s\n",
route.Name, route.Spec.Host, route.Spec.Path, route.Spec.To.Name, labels.Set(route.Labels), insecurePolicy, tlsTerm)
return err
}
func printRouteList(routeList *routeapi.RouteList, w io.Writer, withNamespace, wide, showAll bool, columnLabels []string) error {
for _, route := range routeList.Items {
if err := printRoute(&route, w, withNamespace, wide, showAll, columnLabels); err != nil {
return err
}
}
return nil
}
func printDeploymentConfig(dc *deployapi.DeploymentConfig, w io.Writer, withNamespace, wide, showAll bool, columnLabels []string) error {
triggers := sets.String{}
for _, trigger := range dc.Spec.Triggers {
triggers.Insert(string(trigger.Type))
}
tStr := strings.Join(triggers.List(), ", ")
if withNamespace {
if _, err := fmt.Fprintf(w, "%s\t", dc.Namespace); err != nil {
return err
}
}
_, err := fmt.Fprintf(w, "%s\t%s\t%v\n", dc.Name, tStr, dc.Status.LatestVersion)
return err
}
func printDeploymentConfigList(list *deployapi.DeploymentConfigList, w io.Writer, withNamespace, wide, showAll bool, columnLabels []string) error {
for _, dc := range list.Items {
if err := printDeploymentConfig(&dc, w, withNamespace, wide, showAll, columnLabels); err != nil {
return err
}
}
return nil
}
func printPolicy(policy *authorizationapi.Policy, w io.Writer, withNamespace, wide, showAll bool, columnLabels []string) error {
roleNames := sets.String{}
for key := range policy.Roles {
roleNames.Insert(key)
}
rolesString := strings.Join(roleNames.List(), ", ")
if withNamespace {
if _, err := fmt.Fprintf(w, "%s\t", policy.Namespace); err != nil {
return err
}
}
_, err := fmt.Fprintf(w, "%s\t%s\t%v\n", policy.Name, rolesString, policy.LastModified)
return err
}
func printPolicyList(list *authorizationapi.PolicyList, w io.Writer, withNamespace, wide, showAll bool, columnLabels []string) error {
for _, policy := range list.Items {
if err := printPolicy(&policy, w, withNamespace, wide, showAll, columnLabels); err != nil {
return err
}
}
return nil
}
func printPolicyBinding(policyBinding *authorizationapi.PolicyBinding, w io.Writer, withNamespace, wide, showAll bool, columnLabels []string) error {
roleBindingNames := sets.String{}
for key := range policyBinding.RoleBindings {
roleBindingNames.Insert(key)
}
roleBindingsString := strings.Join(roleBindingNames.List(), ", ")
if withNamespace {
if _, err := fmt.Fprintf(w, "%s\t", policyBinding.Namespace); err != nil {
return err
}
}
_, err := fmt.Fprintf(w, "%s\t%s\t%v\n", policyBinding.Name, roleBindingsString, policyBinding.LastModified)
return err
}
func printPolicyBindingList(list *authorizationapi.PolicyBindingList, w io.Writer, withNamespace, wide, showAll bool, columnLabels []string) error {
for _, policyBinding := range list.Items {
if err := printPolicyBinding(&policyBinding, w, withNamespace, wide, showAll, columnLabels); err != nil {
return err
}
}
return nil
}
func printClusterPolicy(policy *authorizationapi.ClusterPolicy, w io.Writer, withNamespace, wide, showAll bool, columnLabels []string) error {
return printPolicy(authorizationapi.ToPolicy(policy), w, withNamespace, wide, showAll, columnLabels)
}
func printClusterPolicyList(list *authorizationapi.ClusterPolicyList, w io.Writer, withNamespace, wide, showAll bool, columnLabels []string) error {
return printPolicyList(authorizationapi.ToPolicyList(list), w, withNamespace, wide, showAll, columnLabels)
}
func printClusterPolicyBinding(policyBinding *authorizationapi.ClusterPolicyBinding, w io.Writer, withNamespace, wide, showAll bool, columnLabels []string) error {
return printPolicyBinding(authorizationapi.ToPolicyBinding(policyBinding), w, withNamespace, wide, showAll, columnLabels)
}
func printClusterPolicyBindingList(list *authorizationapi.ClusterPolicyBindingList, w io.Writer, withNamespace, wide, showAll bool, columnLabels []string) error {
return printPolicyBindingList(authorizationapi.ToPolicyBindingList(list), w, withNamespace, wide, showAll, columnLabels)
}
func printClusterRole(role *authorizationapi.ClusterRole, w io.Writer, withNamespace, wide, showAll bool, columnLabels []string) error {
return printRole(authorizationapi.ToRole(role), w, withNamespace, wide, showAll, columnLabels)
}
func printClusterRoleList(list *authorizationapi.ClusterRoleList, w io.Writer, withNamespace, wide, showAll bool, columnLabels []string) error {
return printRoleList(authorizationapi.ToRoleList(list), w, withNamespace, wide, showAll, columnLabels)
}
func printClusterRoleBinding(roleBinding *authorizationapi.ClusterRoleBinding, w io.Writer, withNamespace, wide, showAll bool, columnLabels []string) error {
return printRoleBinding(authorizationapi.ToRoleBinding(roleBinding), w, withNamespace, wide, showAll, columnLabels)
}
func printClusterRoleBindingList(list *authorizationapi.ClusterRoleBindingList, w io.Writer, withNamespace, wide, showAll bool, columnLabels []string) error {
return printRoleBindingList(authorizationapi.ToRoleBindingList(list), w, withNamespace, wide, showAll, columnLabels)
}
func printIsPersonalSubjectAccessReview(a *authorizationapi.IsPersonalSubjectAccessReview, w io.Writer, withNamespace, wide, showAll bool, columnLabels []string) error {
_, err := fmt.Fprintf(w, "IsPersonalSubjectAccessReview\n")
return err
}
func printRole(role *authorizationapi.Role, w io.Writer, withNamespace, wide, showAll bool, columnLabels []string) error {
if withNamespace {
if _, err := fmt.Fprintf(w, "%s\t", role.Namespace); err != nil {
return err
}
}
_, err := fmt.Fprintf(w, "%s\n", role.Name)
return err
}
func printRoleList(list *authorizationapi.RoleList, w io.Writer, withNamespace, wide, showAll bool, columnLabels []string) error {
for _, role := range list.Items {
if err := printRole(&role, w, withNamespace, wide, showAll, columnLabels); err != nil {
return err
}
}
return nil
}
func printRoleBinding(roleBinding *authorizationapi.RoleBinding, w io.Writer, withNamespace, wide, showAll bool, columnLabels []string) error {
if withNamespace {
if _, err := fmt.Fprintf(w, "%s\t", roleBinding.Namespace); err != nil {
return err
}
}
users, groups, sas, others := authorizationapi.SubjectsStrings(roleBinding.Namespace, roleBinding.Subjects)
_, err := fmt.Fprintf(w, "%s\t%s\t%v\t%v\t%v\t%v\n", roleBinding.Name, roleBinding.RoleRef.Namespace+"/"+roleBinding.RoleRef.Name, strings.Join(users, ", "), strings.Join(groups, ", "), strings.Join(sas, ", "), strings.Join(others, ", "))
return err
}
func printRoleBindingList(list *authorizationapi.RoleBindingList, w io.Writer, withNamespace, wide, showAll bool, columnLabels []string) error {
for _, roleBinding := range list.Items {
if err := printRoleBinding(&roleBinding, w, withNamespace, wide, showAll, columnLabels); err != nil {
return err
}
}
return nil
}
func printOAuthClient(client *oauthapi.OAuthClient, w io.Writer, withNamespace, wide, showAll bool, columnLabels []string) error {
challenge := "FALSE"
if client.RespondWithChallenges {
challenge = "TRUE"
}
_, err := fmt.Fprintf(w, "%s\t%s\t%s\t%v\n", client.Name, client.Secret, challenge, strings.Join(client.RedirectURIs, ","))
return err
}
func printOAuthClientList(list *oauthapi.OAuthClientList, w io.Writer, withNamespace, wide, showAll bool, columnLabels []string) error {
for _, item := range list.Items {
if err := printOAuthClient(&item, w, withNamespace, wide, showAll, columnLabels); err != nil {
return err
}
}
return nil
}
func printOAuthClientAuthorization(auth *oauthapi.OAuthClientAuthorization, w io.Writer, withNamespace, wide, showAll bool, columnLabels []string) error {
_, err := fmt.Fprintf(w, "%s\t%s\t%s\t%v\n", auth.Name, auth.UserName, auth.ClientName, strings.Join(auth.Scopes, ","))
return err
}
func printOAuthClientAuthorizationList(list *oauthapi.OAuthClientAuthorizationList, w io.Writer, withNamespace, wide, showAll bool, columnLabels []string) error {
for _, item := range list.Items {
if err := printOAuthClientAuthorization(&item, w, withNamespace, wide, showAll, columnLabels); err != nil {
return err
}
}
return nil
}
func printOAuthAccessToken(token *oauthapi.OAuthAccessToken, w io.Writer, withNamespace, wide, showAll bool, columnLabels []string) error {
created := token.CreationTimestamp
expires := created.Add(time.Duration(token.ExpiresIn) * time.Second)
_, err := fmt.Fprintf(w, "%s\t%s\t%s\t%s\t%s\t%s\t%s\n", token.Name, token.UserName, token.ClientName, created, expires, token.RedirectURI, strings.Join(token.Scopes, ","))
return err
}
func printOAuthAccessTokenList(list *oauthapi.OAuthAccessTokenList, w io.Writer, withNamespace, wide, showAll bool, columnLabels []string) error {
for _, item := range list.Items {
if err := printOAuthAccessToken(&item, w, withNamespace, wide, showAll, columnLabels); err != nil {
return err
}
}
return nil
}
func printOAuthAuthorizeToken(token *oauthapi.OAuthAuthorizeToken, w io.Writer, withNamespace, wide, showAll bool, columnLabels []string) error {
created := token.CreationTimestamp
expires := created.Add(time.Duration(token.ExpiresIn) * time.Second)
_, err := fmt.Fprintf(w, "%s\t%s\t%s\t%s\t%s\t%s\t%s\n", token.Name, token.UserName, token.ClientName, created, expires, token.RedirectURI, strings.Join(token.Scopes, ","))
return err
}
func printOAuthAuthorizeTokenList(list *oauthapi.OAuthAuthorizeTokenList, w io.Writer, withNamespace, wide, showAll bool, columnLabels []string) error {
for _, item := range list.Items {
if err := printOAuthAuthorizeToken(&item, w, withNamespace, wide, showAll, columnLabels); err != nil {
return err
}
}
return nil
}
func printUser(user *userapi.User, w io.Writer, withNamespace, wide, showAll bool, columnLabels []string) error {
_, err := fmt.Fprintf(w, "%s\t%s\t%s\t%s\n", user.Name, user.UID, user.FullName, strings.Join(user.Identities, ", "))
return err
}
func printUserList(list *userapi.UserList, w io.Writer, withNamespace, wide, showAll bool, columnLabels []string) error {
for _, item := range list.Items {
if err := printUser(&item, w, withNamespace, wide, showAll, columnLabels); err != nil {
return err
}
}
return nil
}
func printIdentity(identity *userapi.Identity, w io.Writer, withNamespace, wide, showAll bool, columnLabels []string) error {
_, err := fmt.Fprintf(w, "%s\t%s\t%s\t%s\t%s\n", identity.Name, identity.ProviderName, identity.ProviderUserName, identity.User.Name, identity.User.UID)
return err
}
func printIdentityList(list *userapi.IdentityList, w io.Writer, withNamespace, wide, showAll bool, columnLabels []string) error {
for _, item := range list.Items {
if err := printIdentity(&item, w, withNamespace, wide, showAll, columnLabels); err != nil {
return err
}
}
return nil
}
func printUserIdentityMapping(mapping *userapi.UserIdentityMapping, w io.Writer, withNamespace, wide, showAll bool, columnLabels []string) error {
_, err := fmt.Fprintf(w, "%s\t%s\t%s\t%s\n", mapping.Name, mapping.Identity.Name, mapping.User.Name, mapping.User.UID)
return err
}
func printGroup(group *userapi.Group, w io.Writer, withNamespace, wide, showAll bool, columnLabels []string) error {
_, err := fmt.Fprintf(w, "%s\t%s\n", group.Name, strings.Join(group.Users, ", "))
return err
}
func printGroupList(list *userapi.GroupList, w io.Writer, withNamespace, wide, showAll bool, columnLabels []string) error {
for _, item := range list.Items {
if err := printGroup(&item, w, withNamespace, wide, showAll, columnLabels); err != nil {
return err
}
}
return nil
}
func printHostSubnet(h *sdnapi.HostSubnet, w io.Writer, withNamespace, wide, showAll bool, columnLabels []string) error {
_, err := fmt.Fprintf(w, "%s\t%s\t%s\t%s\n", h.Name, h.Host, h.HostIP, h.Subnet)
return err
}
func printHostSubnetList(list *sdnapi.HostSubnetList, w io.Writer, withNamespace, wide, showAll bool, columnLabels []string) error {
for _, item := range list.Items {
if err := printHostSubnet(&item, w, withNamespace, wide, showAll, columnLabels); err != nil {
return err
}
}
return nil
}
func printNetNamespace(h *sdnapi.NetNamespace, w io.Writer, withNamespace, wide, showAll bool, columnLabels []string) error {
_, err := fmt.Fprintf(w, "%s\t%d\n", h.NetName, h.NetID)
return err
}
func printNetNamespaceList(list *sdnapi.NetNamespaceList, w io.Writer, withNamespace, wide, showAll bool, columnLabels []string) error {
for _, item := range list.Items {
if err := printNetNamespace(&item, w, withNamespace, wide, showAll, columnLabels); err != nil {
return err
}
}
return nil
}
func printClusterNetwork(n *sdnapi.ClusterNetwork, w io.Writer, withNamespace, wide, showAll bool, columnLabels []string) error {
_, err := fmt.Fprintf(w, "%s\t%s\t%d\t%s\n", n.Name, n.Network, n.HostSubnetLength, n.ServiceNetwork)
return err
}
func printClusterNetworkList(list *sdnapi.ClusterNetworkList, w io.Writer, withNamespace, wide, showAll bool, columnLabels []string) error {
for _, item := range list.Items {
if err := printClusterNetwork(&item, w, withNamespace, wide, showAll, columnLabels); err != nil {
return err
}
}
return nil
}