Merge pull request #26975 from ericchiang/kubectl-resource-printer-for-rbac-group

Automatic merge from submit-queue

pkg/kubectl: add resource printers for rbac api group

This PR adds the necessary kubectl printers for the rbac api group which we overlooked in previous PRs.

cc @erictune
pull/6/head
k8s-merge-robot 2016-06-12 17:13:55 -07:00 committed by GitHub
commit 98f0d22bcc
1 changed files with 82 additions and 31 deletions

View File

@ -40,6 +40,7 @@ import (
"k8s.io/kubernetes/pkg/apis/autoscaling" "k8s.io/kubernetes/pkg/apis/autoscaling"
"k8s.io/kubernetes/pkg/apis/batch" "k8s.io/kubernetes/pkg/apis/batch"
"k8s.io/kubernetes/pkg/apis/extensions" "k8s.io/kubernetes/pkg/apis/extensions"
"k8s.io/kubernetes/pkg/apis/rbac"
"k8s.io/kubernetes/pkg/labels" "k8s.io/kubernetes/pkg/labels"
"k8s.io/kubernetes/pkg/runtime" "k8s.io/kubernetes/pkg/runtime"
utilerrors "k8s.io/kubernetes/pkg/util/errors" utilerrors "k8s.io/kubernetes/pkg/util/errors"
@ -434,6 +435,10 @@ var persistentVolumeColumns = []string{"NAME", "CAPACITY", "ACCESSMODES", "STATU
var persistentVolumeClaimColumns = []string{"NAME", "STATUS", "VOLUME", "CAPACITY", "ACCESSMODES", "AGE"} var persistentVolumeClaimColumns = []string{"NAME", "STATUS", "VOLUME", "CAPACITY", "ACCESSMODES", "AGE"}
var componentStatusColumns = []string{"NAME", "STATUS", "MESSAGE", "ERROR"} var componentStatusColumns = []string{"NAME", "STATUS", "MESSAGE", "ERROR"}
var thirdPartyResourceColumns = []string{"NAME", "DESCRIPTION", "VERSION(S)"} var thirdPartyResourceColumns = []string{"NAME", "DESCRIPTION", "VERSION(S)"}
var roleColumns = []string{"NAME", "AGE"}
var roleBindingColumns = []string{"NAME", "AGE"}
var clusterRoleColumns = []string{"NAME", "AGE"}
var clusterRoleBindingColumns = []string{"NAME", "AGE"}
// TODO: consider having 'KIND' for third party resource data // TODO: consider having 'KIND' for third party resource data
var thirdPartyResourceDataColumns = []string{"NAME", "LABELS", "DATA"} var thirdPartyResourceDataColumns = []string{"NAME", "LABELS", "DATA"}
@ -503,6 +508,14 @@ func (h *HumanReadablePrinter) addDefaultHandlers() {
h.Handler(clusterColumns, printClusterList) h.Handler(clusterColumns, printClusterList)
h.Handler(networkPolicyColumns, printNetworkPolicy) h.Handler(networkPolicyColumns, printNetworkPolicy)
h.Handler(networkPolicyColumns, printNetworkPolicyList) h.Handler(networkPolicyColumns, printNetworkPolicyList)
h.Handler(roleColumns, printRole)
h.Handler(roleColumns, printRoleList)
h.Handler(roleBindingColumns, printRoleBinding)
h.Handler(roleBindingColumns, printRoleBindingList)
h.Handler(clusterRoleColumns, printClusterRole)
h.Handler(clusterRoleColumns, printClusterRoleList)
h.Handler(clusterRoleBindingColumns, printClusterRoleBinding)
h.Handler(clusterRoleBindingColumns, printClusterRoleBindingList)
} }
func (h *HumanReadablePrinter) unknown(data []byte, w io.Writer) error { func (h *HumanReadablePrinter) unknown(data []byte, w io.Writer) error {
@ -1496,27 +1509,7 @@ func printEventList(list *api.EventList, w io.Writer, options PrintOptions) erro
} }
func printLimitRange(limitRange *api.LimitRange, w io.Writer, options PrintOptions) error { func printLimitRange(limitRange *api.LimitRange, w io.Writer, options PrintOptions) error {
name := limitRange.Name return printObjectMeta(limitRange.ObjectMeta, w, options, true)
namespace := limitRange.Namespace
if options.WithNamespace {
if _, err := fmt.Fprintf(w, "%s\t", namespace); err != nil {
return err
}
}
if _, err := fmt.Fprintf(
w, "%s\t%s",
name,
translateTimestamp(limitRange.CreationTimestamp),
); err != nil {
return err
}
if _, err := fmt.Fprint(w, AppendLabels(limitRange.Labels, options.ColumnLabels)); err != nil {
return err
}
_, err := fmt.Fprint(w, AppendAllLabels(options.ShowLabels, limitRange.Labels))
return err
} }
// Prints the LimitRangeList in a human-friendly format. // Prints the LimitRangeList in a human-friendly format.
@ -1529,30 +1522,32 @@ func printLimitRangeList(list *api.LimitRangeList, w io.Writer, options PrintOpt
return nil return nil
} }
func printResourceQuota(resourceQuota *api.ResourceQuota, w io.Writer, options PrintOptions) error { // printObjectMeta prints the object metadata of a given resource.
name := resourceQuota.Name func printObjectMeta(meta api.ObjectMeta, w io.Writer, options PrintOptions, namespaced bool) error {
namespace := resourceQuota.Namespace if namespaced && options.WithNamespace {
if _, err := fmt.Fprintf(w, "%s\t", meta.Namespace); err != nil {
if options.WithNamespace {
if _, err := fmt.Fprintf(w, "%s\t", namespace); err != nil {
return err return err
} }
} }
if _, err := fmt.Fprintf( if _, err := fmt.Fprintf(
w, "%s\t%s", w, "%s\t%s",
name, meta.Name,
translateTimestamp(resourceQuota.CreationTimestamp), translateTimestamp(meta.CreationTimestamp),
); err != nil { ); err != nil {
return err return err
} }
if _, err := fmt.Fprint(w, AppendLabels(resourceQuota.Labels, options.ColumnLabels)); err != nil { if _, err := fmt.Fprint(w, AppendLabels(meta.Labels, options.ColumnLabels)); err != nil {
return err return err
} }
_, err := fmt.Fprint(w, AppendAllLabels(options.ShowLabels, resourceQuota.Labels)) _, err := fmt.Fprint(w, AppendAllLabels(options.ShowLabels, meta.Labels))
return err return err
} }
func printResourceQuota(resourceQuota *api.ResourceQuota, w io.Writer, options PrintOptions) error {
return printObjectMeta(resourceQuota.ObjectMeta, w, options, true)
}
// Prints the ResourceQuotaList in a human-friendly format. // Prints the ResourceQuotaList in a human-friendly format.
func printResourceQuotaList(list *api.ResourceQuotaList, w io.Writer, options PrintOptions) error { func printResourceQuotaList(list *api.ResourceQuotaList, w io.Writer, options PrintOptions) error {
for i := range list.Items { for i := range list.Items {
@ -1563,6 +1558,62 @@ func printResourceQuotaList(list *api.ResourceQuotaList, w io.Writer, options Pr
return nil return nil
} }
func printRole(role *rbac.Role, w io.Writer, options PrintOptions) error {
return printObjectMeta(role.ObjectMeta, w, options, true)
}
// Prints the Role in a human-friendly format.
func printRoleList(list *rbac.RoleList, w io.Writer, options PrintOptions) error {
for i := range list.Items {
if err := printRole(&list.Items[i], w, options); err != nil {
return err
}
}
return nil
}
func printRoleBinding(roleBinding *rbac.RoleBinding, w io.Writer, options PrintOptions) error {
return printObjectMeta(roleBinding.ObjectMeta, w, options, true)
}
// Prints the RoleBinding in a human-friendly format.
func printRoleBindingList(list *rbac.RoleBindingList, w io.Writer, options PrintOptions) error {
for i := range list.Items {
if err := printRoleBinding(&list.Items[i], w, options); err != nil {
return err
}
}
return nil
}
func printClusterRole(clusterRole *rbac.ClusterRole, w io.Writer, options PrintOptions) error {
return printObjectMeta(clusterRole.ObjectMeta, w, options, false)
}
// Prints the ClusterRole in a human-friendly format.
func printClusterRoleList(list *rbac.ClusterRoleList, w io.Writer, options PrintOptions) error {
for i := range list.Items {
if err := printClusterRole(&list.Items[i], w, options); err != nil {
return err
}
}
return nil
}
func printClusterRoleBinding(clusterRoleBinding *rbac.ClusterRoleBinding, w io.Writer, options PrintOptions) error {
return printObjectMeta(clusterRoleBinding.ObjectMeta, w, options, false)
}
// Prints the ClusterRoleBinding in a human-friendly format.
func printClusterRoleBindingList(list *rbac.ClusterRoleBindingList, w io.Writer, options PrintOptions) error {
for i := range list.Items {
if err := printClusterRoleBinding(&list.Items[i], w, options); err != nil {
return err
}
}
return nil
}
func printComponentStatus(item *api.ComponentStatus, w io.Writer, options PrintOptions) error { func printComponentStatus(item *api.ComponentStatus, w io.Writer, options PrintOptions) error {
if options.WithNamespace { if options.WithNamespace {
return fmt.Errorf("componentStatus is not namespaced") return fmt.Errorf("componentStatus is not namespaced")