diff --git a/pkg/printers/internalversion/printers.go b/pkg/printers/internalversion/printers.go index af9de27ea7f..5ad96ad410a 100644 --- a/pkg/printers/internalversion/printers.go +++ b/pkg/printers/internalversion/printers.go @@ -371,8 +371,8 @@ func AddHandlers(h printers.PrintHandler) { roleBindingsColumnDefinitions := []metav1.TableColumnDefinition{ {Name: "Name", Type: "string", Format: "name", Description: metav1.ObjectMeta{}.SwaggerDoc()["name"]}, + {Name: "Role", Type: "string", Description: rbacv1beta1.RoleBinding{}.SwaggerDoc()["roleRef"]}, {Name: "Age", Type: "string", Description: metav1.ObjectMeta{}.SwaggerDoc()["creationTimestamp"]}, - {Name: "Role", Type: "string", Priority: 1, Description: rbacv1beta1.RoleBinding{}.SwaggerDoc()["roleRef"]}, {Name: "Users", Type: "string", Priority: 1, Description: "Users in the roleBinding"}, {Name: "Groups", Type: "string", Priority: 1, Description: "Groups in the roleBinding"}, {Name: "ServiceAccounts", Type: "string", Priority: 1, Description: "ServiceAccounts in the roleBinding"}, @@ -382,8 +382,8 @@ func AddHandlers(h printers.PrintHandler) { clusterRoleBindingsColumnDefinitions := []metav1.TableColumnDefinition{ {Name: "Name", Type: "string", Format: "name", Description: metav1.ObjectMeta{}.SwaggerDoc()["name"]}, + {Name: "Role", Type: "string", Description: rbacv1beta1.ClusterRoleBinding{}.SwaggerDoc()["roleRef"]}, {Name: "Age", Type: "string", Description: metav1.ObjectMeta{}.SwaggerDoc()["creationTimestamp"]}, - {Name: "Role", Type: "string", Priority: 1, Description: rbacv1beta1.ClusterRoleBinding{}.SwaggerDoc()["roleRef"]}, {Name: "Users", Type: "string", Priority: 1, Description: "Users in the clusterRoleBinding"}, {Name: "Groups", Type: "string", Priority: 1, Description: "Groups in the clusterRoleBinding"}, {Name: "ServiceAccounts", Type: "string", Priority: 1, Description: "ServiceAccounts in the clusterRoleBinding"}, @@ -1630,11 +1630,11 @@ func printRoleBinding(obj *rbac.RoleBinding, options printers.GenerateOptions) ( Object: runtime.RawExtension{Object: obj}, } - row.Cells = append(row.Cells, obj.Name, translateTimestampSince(obj.CreationTimestamp)) + roleRef := fmt.Sprintf("%s/%s", obj.RoleRef.Kind, obj.RoleRef.Name) + row.Cells = append(row.Cells, obj.Name, roleRef, translateTimestampSince(obj.CreationTimestamp)) if options.Wide { - roleRef := fmt.Sprintf("%s/%s", obj.RoleRef.Kind, obj.RoleRef.Name) users, groups, sas, _ := rbac.SubjectsStrings(obj.Subjects) - row.Cells = append(row.Cells, roleRef, strings.Join(users, ", "), strings.Join(groups, ", "), strings.Join(sas, ", ")) + row.Cells = append(row.Cells, strings.Join(users, ", "), strings.Join(groups, ", "), strings.Join(sas, ", ")) } return []metav1.TableRow{row}, nil } @@ -1657,11 +1657,11 @@ func printClusterRoleBinding(obj *rbac.ClusterRoleBinding, options printers.Gene Object: runtime.RawExtension{Object: obj}, } - row.Cells = append(row.Cells, obj.Name, translateTimestampSince(obj.CreationTimestamp)) + roleRef := fmt.Sprintf("%s/%s", obj.RoleRef.Kind, obj.RoleRef.Name) + row.Cells = append(row.Cells, obj.Name, roleRef, translateTimestampSince(obj.CreationTimestamp)) if options.Wide { - roleRef := fmt.Sprintf("%s/%s", obj.RoleRef.Kind, obj.RoleRef.Name) users, groups, sas, _ := rbac.SubjectsStrings(obj.Subjects) - row.Cells = append(row.Cells, roleRef, strings.Join(users, ", "), strings.Join(groups, ", "), strings.Join(sas, ", ")) + row.Cells = append(row.Cells, strings.Join(users, ", "), strings.Join(groups, ", "), strings.Join(sas, ", ")) } return []metav1.TableRow{row}, nil } diff --git a/pkg/printers/internalversion/printers_test.go b/pkg/printers/internalversion/printers_test.go index 0805bec4e68..53f4d474497 100644 --- a/pkg/printers/internalversion/printers_test.go +++ b/pkg/printers/internalversion/printers_test.go @@ -3253,7 +3253,7 @@ func TestPrintRoleBinding(t *testing.T) { }, options: printers.GenerateOptions{}, // Columns: Name, Age - expected: []metav1.TableRow{{Cells: []interface{}{"binding1", "0s"}}}, + expected: []metav1.TableRow{{Cells: []interface{}{"binding1", "Role/extension-apiserver-authentication-reader", "0s"}}}, }, // Generate options=Wide; print subject and roles. { @@ -3284,7 +3284,7 @@ func TestPrintRoleBinding(t *testing.T) { }, options: printers.GenerateOptions{Wide: true}, // Columns: Name, Age, Role, Users, Groups, ServiceAccounts - expected: []metav1.TableRow{{Cells: []interface{}{"binding2", "0s", "Role/role-name", "user-name", "group-name", "service-account-namespace/service-account-name"}}}, + expected: []metav1.TableRow{{Cells: []interface{}{"binding2", "Role/role-name", "0s", "user-name", "group-name", "service-account-namespace/service-account-name"}}}, }, } @@ -3328,7 +3328,7 @@ func TestPrintClusterRoleBinding(t *testing.T) { }, options: printers.GenerateOptions{}, // Columns: Name, Age - expected: []metav1.TableRow{{Cells: []interface{}{"binding1", "0s"}}}, + expected: []metav1.TableRow{{Cells: []interface{}{"binding1", "Role/extension-apiserver-authentication-reader", "0s"}}}, }, // Generate options=Wide; print subject and roles. { @@ -3359,7 +3359,7 @@ func TestPrintClusterRoleBinding(t *testing.T) { }, options: printers.GenerateOptions{Wide: true}, // Columns: Name, Age, Role, Users, Groups, ServiceAccounts - expected: []metav1.TableRow{{Cells: []interface{}{"binding2", "0s", "Role/role-name", "user-name", "group-name", "service-account-namespace/service-account-name"}}}, + expected: []metav1.TableRow{{Cells: []interface{}{"binding2", "Role/role-name", "0s", "user-name", "group-name", "service-account-namespace/service-account-name"}}}, }, }