When combining PolicyRules, don't duplicate verbs
Kubernetes-commit: ea23faa523c8d118a76c636544a01314619ec21c
This commit is contained in:
parent
052adb602f
commit
2e85eacc5d
|
@ -18,6 +18,7 @@ package rbac
|
|||
|
||||
import (
|
||||
rbacv1 "k8s.io/api/rbac/v1"
|
||||
"k8s.io/apimachinery/pkg/util/sets"
|
||||
"reflect"
|
||||
"strings"
|
||||
)
|
||||
|
@ -42,7 +43,13 @@ func CompactRules(rules []rbacv1.PolicyRule) ([]rbacv1.PolicyRule, error) {
|
|||
if existingRule.Verbs == nil {
|
||||
existingRule.Verbs = []string{}
|
||||
}
|
||||
existingRule.Verbs = append(existingRule.Verbs, rule.Verbs...)
|
||||
existingVerbs := sets.NewString(existingRule.Verbs...)
|
||||
for _, verb := range rule.Verbs {
|
||||
if !existingVerbs.Has(verb) {
|
||||
existingRule.Verbs = append(existingRule.Verbs, verb)
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
// Copy the rule to accumulate matching simple resource rules into
|
||||
simpleRules[resource] = rule.DeepCopy()
|
||||
|
|
Loading…
Reference in New Issue