When combining PolicyRules, don't duplicate verbs

Kubernetes-commit: ea23faa523c8d118a76c636544a01314619ec21c
This commit is contained in:
Sally O'Malley 2020-05-18 15:20:06 -04:00 committed by Kubernetes Publisher
parent 052adb602f
commit 2e85eacc5d
1 changed files with 8 additions and 1 deletions

View File

@ -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()