Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pretty up policy describe #1113

Merged
merged 2 commits into from
Feb 24, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 8 additions & 19 deletions pkg/cmd/cli/describe/describer.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package describe

import (
"fmt"
"sort"
"reflect"
"strings"
"text/tabwriter"

Expand All @@ -11,6 +11,7 @@ import (
kclient "github.com/GoogleCloudPlatform/kubernetes/pkg/client"
kctl "github.com/GoogleCloudPlatform/kubernetes/pkg/kubectl"
"github.com/GoogleCloudPlatform/kubernetes/pkg/runtime"
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"

buildapi "github.com/openshift/origin/pkg/build/api"
"github.com/openshift/origin/pkg/client"
Expand Down Expand Up @@ -276,14 +277,8 @@ func (d *PolicyDescriber) Describe(namespace, name string) (string, error) {
formatMeta(out, policy.ObjectMeta)
formatString(out, "Last Modified", policy.LastModified)

// display the rules in a consistent order
sortedKeys := make([]string, 0)
for key := range policy.Roles {
sortedKeys = append(sortedKeys, key)
}
sort.Strings(sortedKeys)

for _, key := range sortedKeys {
// using .List() here because I always want the sorted order that it provides
for _, key := range util.KeySet(reflect.ValueOf(policy.Roles)).List() {
role := policy.Roles[key]
fmt.Fprint(out, key+"\tVerbs\tResources\tExtension\n")
for _, rule := range role.Rules {
Expand All @@ -294,8 +289,8 @@ func (d *PolicyDescriber) Describe(namespace, name string) (string, error) {

fmt.Fprintf(out, "%v\t%v\t%v\t%v\n",
"",
rule.Verbs,
rule.Resources,
rule.Verbs.List(),
rule.Resources.List(),
extensionString)

}
Expand Down Expand Up @@ -323,14 +318,8 @@ func (d *PolicyBindingDescriber) Describe(namespace, name string) (string, error
formatString(out, "Last Modified", policyBinding.LastModified)
formatString(out, "Policy", policyBinding.PolicyRef.Namespace)

// display the rules in a consistent order
sortedKeys := make([]string, 0)
for key := range policyBinding.RoleBindings {
sortedKeys = append(sortedKeys, key)
}
sort.Strings(sortedKeys)

for _, key := range sortedKeys {
// using .List() here because I always want the sorted order that it provides
for _, key := range util.KeySet(reflect.ValueOf(policyBinding.RoleBindings)).List() {
roleBinding := policyBinding.RoleBindings[key]
formatString(out, "RoleBinding["+key+"]", " ")
formatString(out, "\tRole", roleBinding.RoleRef.Name)
Expand Down