mirror of
				https://github.com/optim-enterprises-bv/kubernetes.git
				synced 2025-11-04 12:18:16 +00:00 
			
		
		
		
	pkg/kubectl: add resource printers for rbac api group
This commit is contained in:
		@@ -40,6 +40,7 @@ import (
 | 
			
		||||
	"k8s.io/kubernetes/pkg/apis/autoscaling"
 | 
			
		||||
	"k8s.io/kubernetes/pkg/apis/batch"
 | 
			
		||||
	"k8s.io/kubernetes/pkg/apis/extensions"
 | 
			
		||||
	"k8s.io/kubernetes/pkg/apis/rbac"
 | 
			
		||||
	"k8s.io/kubernetes/pkg/labels"
 | 
			
		||||
	"k8s.io/kubernetes/pkg/runtime"
 | 
			
		||||
	utilerrors "k8s.io/kubernetes/pkg/util/errors"
 | 
			
		||||
@@ -433,6 +434,10 @@ var persistentVolumeColumns = []string{"NAME", "CAPACITY", "ACCESSMODES", "STATU
 | 
			
		||||
var persistentVolumeClaimColumns = []string{"NAME", "STATUS", "VOLUME", "CAPACITY", "ACCESSMODES", "AGE"}
 | 
			
		||||
var componentStatusColumns = []string{"NAME", "STATUS", "MESSAGE", "ERROR"}
 | 
			
		||||
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
 | 
			
		||||
var thirdPartyResourceDataColumns = []string{"NAME", "LABELS", "DATA"}
 | 
			
		||||
@@ -502,6 +507,14 @@ func (h *HumanReadablePrinter) addDefaultHandlers() {
 | 
			
		||||
	h.Handler(clusterColumns, printClusterList)
 | 
			
		||||
	h.Handler(networkPolicyColumns, printNetworkPolicy)
 | 
			
		||||
	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 {
 | 
			
		||||
@@ -1488,27 +1501,7 @@ func printEventList(list *api.EventList, w io.Writer, options PrintOptions) erro
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func printLimitRange(limitRange *api.LimitRange, w io.Writer, options PrintOptions) error {
 | 
			
		||||
	name := limitRange.Name
 | 
			
		||||
	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
 | 
			
		||||
	return printObjectMeta(limitRange.ObjectMeta, w, options, true)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Prints the LimitRangeList in a human-friendly format.
 | 
			
		||||
@@ -1521,30 +1514,32 @@ func printLimitRangeList(list *api.LimitRangeList, w io.Writer, options PrintOpt
 | 
			
		||||
	return nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func printResourceQuota(resourceQuota *api.ResourceQuota, w io.Writer, options PrintOptions) error {
 | 
			
		||||
	name := resourceQuota.Name
 | 
			
		||||
	namespace := resourceQuota.Namespace
 | 
			
		||||
 | 
			
		||||
	if options.WithNamespace {
 | 
			
		||||
		if _, err := fmt.Fprintf(w, "%s\t", namespace); err != nil {
 | 
			
		||||
// printObjectMeta prints the object metadata of a given resource.
 | 
			
		||||
func printObjectMeta(meta api.ObjectMeta, w io.Writer, options PrintOptions, namespaced bool) error {
 | 
			
		||||
	if namespaced && options.WithNamespace {
 | 
			
		||||
		if _, err := fmt.Fprintf(w, "%s\t", meta.Namespace); err != nil {
 | 
			
		||||
			return err
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	if _, err := fmt.Fprintf(
 | 
			
		||||
		w, "%s\t%s",
 | 
			
		||||
		name,
 | 
			
		||||
		translateTimestamp(resourceQuota.CreationTimestamp),
 | 
			
		||||
		meta.Name,
 | 
			
		||||
		translateTimestamp(meta.CreationTimestamp),
 | 
			
		||||
	); err != nil {
 | 
			
		||||
		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
 | 
			
		||||
	}
 | 
			
		||||
	_, err := fmt.Fprint(w, AppendAllLabels(options.ShowLabels, resourceQuota.Labels))
 | 
			
		||||
	_, err := fmt.Fprint(w, AppendAllLabels(options.ShowLabels, meta.Labels))
 | 
			
		||||
	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.
 | 
			
		||||
func printResourceQuotaList(list *api.ResourceQuotaList, w io.Writer, options PrintOptions) error {
 | 
			
		||||
	for i := range list.Items {
 | 
			
		||||
@@ -1555,6 +1550,62 @@ func printResourceQuotaList(list *api.ResourceQuotaList, w io.Writer, options Pr
 | 
			
		||||
	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 {
 | 
			
		||||
	if options.WithNamespace {
 | 
			
		||||
		return fmt.Errorf("componentStatus is not namespaced")
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user