Skip to content

Commit 9b387da

Browse files
committed
Improve rolebinding/clusterrolebinding printers
1 parent 5448a8b commit 9b387da

File tree

2 files changed

+12
-12
lines changed

2 files changed

+12
-12
lines changed

pkg/printers/internalversion/printers.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -371,8 +371,8 @@ func AddHandlers(h printers.PrintHandler) {
371371

372372
roleBindingsColumnDefinitions := []metav1.TableColumnDefinition{
373373
{Name: "Name", Type: "string", Format: "name", Description: metav1.ObjectMeta{}.SwaggerDoc()["name"]},
374+
{Name: "Role", Type: "string", Description: rbacv1beta1.RoleBinding{}.SwaggerDoc()["roleRef"]},
374375
{Name: "Age", Type: "string", Description: metav1.ObjectMeta{}.SwaggerDoc()["creationTimestamp"]},
375-
{Name: "Role", Type: "string", Priority: 1, Description: rbacv1beta1.RoleBinding{}.SwaggerDoc()["roleRef"]},
376376
{Name: "Users", Type: "string", Priority: 1, Description: "Users in the roleBinding"},
377377
{Name: "Groups", Type: "string", Priority: 1, Description: "Groups in the roleBinding"},
378378
{Name: "ServiceAccounts", Type: "string", Priority: 1, Description: "ServiceAccounts in the roleBinding"},
@@ -382,8 +382,8 @@ func AddHandlers(h printers.PrintHandler) {
382382

383383
clusterRoleBindingsColumnDefinitions := []metav1.TableColumnDefinition{
384384
{Name: "Name", Type: "string", Format: "name", Description: metav1.ObjectMeta{}.SwaggerDoc()["name"]},
385+
{Name: "Role", Type: "string", Description: rbacv1beta1.ClusterRoleBinding{}.SwaggerDoc()["roleRef"]},
385386
{Name: "Age", Type: "string", Description: metav1.ObjectMeta{}.SwaggerDoc()["creationTimestamp"]},
386-
{Name: "Role", Type: "string", Priority: 1, Description: rbacv1beta1.ClusterRoleBinding{}.SwaggerDoc()["roleRef"]},
387387
{Name: "Users", Type: "string", Priority: 1, Description: "Users in the clusterRoleBinding"},
388388
{Name: "Groups", Type: "string", Priority: 1, Description: "Groups in the clusterRoleBinding"},
389389
{Name: "ServiceAccounts", Type: "string", Priority: 1, Description: "ServiceAccounts in the clusterRoleBinding"},
@@ -1630,11 +1630,11 @@ func printRoleBinding(obj *rbac.RoleBinding, options printers.GenerateOptions) (
16301630
Object: runtime.RawExtension{Object: obj},
16311631
}
16321632

1633-
row.Cells = append(row.Cells, obj.Name, translateTimestampSince(obj.CreationTimestamp))
1633+
roleRef := fmt.Sprintf("%s/%s", obj.RoleRef.Kind, obj.RoleRef.Name)
1634+
row.Cells = append(row.Cells, obj.Name, roleRef, translateTimestampSince(obj.CreationTimestamp))
16341635
if options.Wide {
1635-
roleRef := fmt.Sprintf("%s/%s", obj.RoleRef.Kind, obj.RoleRef.Name)
16361636
users, groups, sas, _ := rbac.SubjectsStrings(obj.Subjects)
1637-
row.Cells = append(row.Cells, roleRef, strings.Join(users, ", "), strings.Join(groups, ", "), strings.Join(sas, ", "))
1637+
row.Cells = append(row.Cells, strings.Join(users, ", "), strings.Join(groups, ", "), strings.Join(sas, ", "))
16381638
}
16391639
return []metav1.TableRow{row}, nil
16401640
}
@@ -1657,11 +1657,11 @@ func printClusterRoleBinding(obj *rbac.ClusterRoleBinding, options printers.Gene
16571657
Object: runtime.RawExtension{Object: obj},
16581658
}
16591659

1660-
row.Cells = append(row.Cells, obj.Name, translateTimestampSince(obj.CreationTimestamp))
1660+
roleRef := fmt.Sprintf("%s/%s", obj.RoleRef.Kind, obj.RoleRef.Name)
1661+
row.Cells = append(row.Cells, obj.Name, roleRef, translateTimestampSince(obj.CreationTimestamp))
16611662
if options.Wide {
1662-
roleRef := fmt.Sprintf("%s/%s", obj.RoleRef.Kind, obj.RoleRef.Name)
16631663
users, groups, sas, _ := rbac.SubjectsStrings(obj.Subjects)
1664-
row.Cells = append(row.Cells, roleRef, strings.Join(users, ", "), strings.Join(groups, ", "), strings.Join(sas, ", "))
1664+
row.Cells = append(row.Cells, strings.Join(users, ", "), strings.Join(groups, ", "), strings.Join(sas, ", "))
16651665
}
16661666
return []metav1.TableRow{row}, nil
16671667
}

pkg/printers/internalversion/printers_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3253,7 +3253,7 @@ func TestPrintRoleBinding(t *testing.T) {
32533253
},
32543254
options: printers.GenerateOptions{},
32553255
// Columns: Name, Age
3256-
expected: []metav1.TableRow{{Cells: []interface{}{"binding1", "0s"}}},
3256+
expected: []metav1.TableRow{{Cells: []interface{}{"binding1", "Role/extension-apiserver-authentication-reader", "0s"}}},
32573257
},
32583258
// Generate options=Wide; print subject and roles.
32593259
{
@@ -3284,7 +3284,7 @@ func TestPrintRoleBinding(t *testing.T) {
32843284
},
32853285
options: printers.GenerateOptions{Wide: true},
32863286
// Columns: Name, Age, Role, Users, Groups, ServiceAccounts
3287-
expected: []metav1.TableRow{{Cells: []interface{}{"binding2", "0s", "Role/role-name", "user-name", "group-name", "service-account-namespace/service-account-name"}}},
3287+
expected: []metav1.TableRow{{Cells: []interface{}{"binding2", "Role/role-name", "0s", "user-name", "group-name", "service-account-namespace/service-account-name"}}},
32883288
},
32893289
}
32903290

@@ -3328,7 +3328,7 @@ func TestPrintClusterRoleBinding(t *testing.T) {
33283328
},
33293329
options: printers.GenerateOptions{},
33303330
// Columns: Name, Age
3331-
expected: []metav1.TableRow{{Cells: []interface{}{"binding1", "0s"}}},
3331+
expected: []metav1.TableRow{{Cells: []interface{}{"binding1", "Role/extension-apiserver-authentication-reader", "0s"}}},
33323332
},
33333333
// Generate options=Wide; print subject and roles.
33343334
{
@@ -3359,7 +3359,7 @@ func TestPrintClusterRoleBinding(t *testing.T) {
33593359
},
33603360
options: printers.GenerateOptions{Wide: true},
33613361
// Columns: Name, Age, Role, Users, Groups, ServiceAccounts
3362-
expected: []metav1.TableRow{{Cells: []interface{}{"binding2", "0s", "Role/role-name", "user-name", "group-name", "service-account-namespace/service-account-name"}}},
3362+
expected: []metav1.TableRow{{Cells: []interface{}{"binding2", "Role/role-name", "0s", "user-name", "group-name", "service-account-namespace/service-account-name"}}},
33633363
},
33643364
}
33653365

0 commit comments

Comments
 (0)