When combining PolicyRules, don't duplicate verbs
Kubernetes-commit: ea23faa523c8d118a76c636544a01314619ec21c
This commit is contained in:
parent
141dc474a6
commit
8b7900f520
|
|
@ -18,6 +18,7 @@ package rbac
|
||||||
|
|
||||||
import (
|
import (
|
||||||
rbacv1 "k8s.io/api/rbac/v1"
|
rbacv1 "k8s.io/api/rbac/v1"
|
||||||
|
"k8s.io/apimachinery/pkg/util/sets"
|
||||||
"reflect"
|
"reflect"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
@ -42,7 +43,13 @@ func CompactRules(rules []rbacv1.PolicyRule) ([]rbacv1.PolicyRule, error) {
|
||||||
if existingRule.Verbs == nil {
|
if existingRule.Verbs == nil {
|
||||||
existingRule.Verbs = []string{}
|
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 {
|
} else {
|
||||||
// Copy the rule to accumulate matching simple resource rules into
|
// Copy the rule to accumulate matching simple resource rules into
|
||||||
simpleRules[resource] = rule.DeepCopy()
|
simpleRules[resource] = rule.DeepCopy()
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue