Merge pull request #46326 from xilabao/add-role-to-describe-command
Automatic merge from submit-queue (batch tested with PRs 46432, 46701, 46326, 40848, 46396) add role/clusterrole to describe.go **What this PR does / why we need it**: ``` # ./cluster/kubectl.sh describe clusterrole system:kube-scheduler Name: system:kube-scheduler Labels: kubernetes.io/bootstrapping=rbac-defaults Annotations: rbac.authorization.kubernetes.io/autoupdate=true PolicyRule: Resources Non-Resource URLs Resource Names Verbs --------- ----------------- -------------- ----- bindings [] [] [create] endpoints [] [] [create] endpoints [] [kube-scheduler] [delete] endpoints [] [kube-scheduler] [get] endpoints [] [kube-scheduler] [patch] endpoints [] [kube-scheduler] [update] events [] [] [create patch update] nodes [] [] [get list watch] persistentvolumeclaims [] [] [get list watch] persistentvolumes [] [] [get list watch] pods [] [] [get list watch] pods/binding [] [] [create] pods/status [] [] [update] replicasets.extensions [] [] [get list watch] replicationcontrollers [] [] [get list watch] services [] [] [get list watch] statefulsets.apps [] [] [get list watch] ``` **Which issue this PR fixes**: **Special notes for your reviewer**: **Release note**: ```release-note NONE ```
This commit is contained in:
@@ -124,6 +124,38 @@ func SubjectsStrings(subjects []Subject) ([]string, []string, []string, []string
|
||||
return users, groups, sas, others
|
||||
}
|
||||
|
||||
func (r PolicyRule) String() string {
|
||||
return "PolicyRule" + r.CompactString()
|
||||
}
|
||||
|
||||
// CompactString exposes a compact string representation for use in escalation error messages
|
||||
func (r PolicyRule) CompactString() string {
|
||||
formatStringParts := []string{}
|
||||
formatArgs := []interface{}{}
|
||||
if len(r.Resources) > 0 {
|
||||
formatStringParts = append(formatStringParts, "Resources:%q")
|
||||
formatArgs = append(formatArgs, r.Resources)
|
||||
}
|
||||
if len(r.NonResourceURLs) > 0 {
|
||||
formatStringParts = append(formatStringParts, "NonResourceURLs:%q")
|
||||
formatArgs = append(formatArgs, r.NonResourceURLs)
|
||||
}
|
||||
if len(r.ResourceNames) > 0 {
|
||||
formatStringParts = append(formatStringParts, "ResourceNames:%q")
|
||||
formatArgs = append(formatArgs, r.ResourceNames)
|
||||
}
|
||||
if len(r.APIGroups) > 0 {
|
||||
formatStringParts = append(formatStringParts, "APIGroups:%q")
|
||||
formatArgs = append(formatArgs, r.APIGroups)
|
||||
}
|
||||
if len(r.Verbs) > 0 {
|
||||
formatStringParts = append(formatStringParts, "Verbs:%q")
|
||||
formatArgs = append(formatArgs, r.Verbs)
|
||||
}
|
||||
formatString := "{" + strings.Join(formatStringParts, ", ") + "}"
|
||||
return fmt.Sprintf(formatString, formatArgs...)
|
||||
}
|
||||
|
||||
// +k8s:deepcopy-gen=false
|
||||
// PolicyRuleBuilder let's us attach methods. A no-no for API types.
|
||||
// We use it to construct rules in code. It's more compact than trying to write them
|
||||
@@ -341,3 +373,11 @@ func (r *RoleBindingBuilder) Binding() (RoleBinding, error) {
|
||||
|
||||
return r.RoleBinding, nil
|
||||
}
|
||||
|
||||
type SortableRuleSlice []PolicyRule
|
||||
|
||||
func (s SortableRuleSlice) Len() int { return len(s) }
|
||||
func (s SortableRuleSlice) Swap(i, j int) { s[i], s[j] = s[j], s[i] }
|
||||
func (s SortableRuleSlice) Less(i, j int) bool {
|
||||
return strings.Compare(s[i].String(), s[j].String()) < 0
|
||||
}
|
||||
|
Reference in New Issue
Block a user