Skip to content

Commit

Permalink
fix: range through all resources to build webhook
Browse files Browse the repository at this point in the history
Signed-off-by: anushkamittal20 <anumittal4641@gmail.com>
  • Loading branch information
anushkamittal20 committed Jul 30, 2024
1 parent 7ff7bd9 commit 5e09c3a
Showing 1 changed file with 23 additions and 22 deletions.
45 changes: 23 additions & 22 deletions pkg/controllers/webhook/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,30 +75,31 @@ func (wh *webhook) buildRulesWithOperations(final map[string][]admissionregistra
rules := make([]admissionregistrationv1.RuleWithOperations, 0, len(wh.rules))

for gv, resources := range wh.rules {
firstResource := sets.List(resources)[0]
// if we have pods, we add pods/ephemeralcontainers by default
if (gv.Group == "" || gv.Group == "*") && (gv.Version == "v1" || gv.Version == "*") && (resources.Has("pods") || resources.Has("*")) {
resources.Insert("pods/ephemeralcontainers")
}
for res := range resources {
// if we have pods, we add pods/ephemeralcontainers by default
if (gv.Group == "" || gv.Group == "*") && (gv.Version == "v1" || gv.Version == "*") && (resources.Has("pods") || resources.Has("*")) {
resources.Insert("pods/ephemeralcontainers")
}

operations := findKeyContainingSubstring(final, firstResource, defaultOpn)
if len(operations) == 0 {
continue
}
operations := findKeyContainingSubstring(final, res, defaultOpn)
if len(operations) == 0 {
continue
}

slices.SortFunc(operations, func(a, b admissionregistrationv1.OperationType) int {
return cmp.Compare(a, b)
})

rules = append(rules, admissionregistrationv1.RuleWithOperations{
Rule: admissionregistrationv1.Rule{
APIGroups: []string{gv.Group},
APIVersions: []string{gv.Version},
Resources: sets.List(resources),
Scope: ptr.To(gv.scopeType),
},
Operations: operations,
})
slices.SortFunc(operations, func(a, b admissionregistrationv1.OperationType) int {
return cmp.Compare(a, b)
})

rules = append(rules, admissionregistrationv1.RuleWithOperations{
Rule: admissionregistrationv1.Rule{
APIGroups: []string{gv.Group},
APIVersions: []string{gv.Version},
Resources: []string{res},
Scope: ptr.To(gv.scopeType),
},
Operations: operations,
})
}
}
less := func(a []string, b []string) (int, bool) {
if x := cmp.Compare(len(a), len(b)); x != 0 {
Expand Down

0 comments on commit 5e09c3a

Please sign in to comment.