Skip to content

Commit

Permalink
Register Webhook Rules from callbacks
Browse files Browse the repository at this point in the history
Signed-off-by: Pierangelo Di Pilato <[email protected]>
  • Loading branch information
pierDipi committed Dec 22, 2021
1 parent 0bb0dbb commit 4162f86
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
10 changes: 10 additions & 0 deletions webhook/resourcesemantics/defaulting/defaulting.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,17 @@ func (ac *reconciler) reconcileMutatingWebhook(ctx context.Context, caCert []byt
logger := logging.FromContext(ctx)

rules := make([]admissionregistrationv1.RuleWithOperations, 0, len(ac.handlers))
gvks := make(map[schema.GroupVersionKind]struct{}, len(ac.handlers)+len(ac.callbacks))
for gvk := range ac.handlers {
gvks[gvk] = struct{}{}
}
for gvk := range ac.callbacks {
if _, ok := gvks[gvk]; !ok {
gvks[gvk] = struct{}{}
}
}

for gvk := range gvks {
plural := strings.ToLower(flect.Pluralize(gvk.Kind))

rules = append(rules, admissionregistrationv1.RuleWithOperations{
Expand Down
18 changes: 17 additions & 1 deletion webhook/resourcesemantics/defaulting/table_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import (
"k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/util/wait"
clientgotesting "k8s.io/client-go/testing"

"knative.dev/pkg/configmap"
"knative.dev/pkg/controller"
"knative.dev/pkg/ptr"
Expand Down Expand Up @@ -91,6 +92,20 @@ func TestReconcile(t *testing.T) {
APIVersions: []string{"v1alpha1"},
Resources: []string{"resources", "resources/status"},
},
}, {
Operations: []admissionregistrationv1.OperationType{"CREATE", "UPDATE"},
Rule: admissionregistrationv1.Rule{
APIGroups: []string{"pkg.knative.dev"},
APIVersions: []string{"v1beta1"},
Resources: []string{"resourcecallbackdefaultcreates", "resourcecallbackdefaultcreates/status"},
},
}, {
Operations: []admissionregistrationv1.OperationType{"CREATE", "UPDATE"},
Rule: admissionregistrationv1.Rule{
APIGroups: []string{"pkg.knative.dev"},
APIVersions: []string{"v1beta1"},
Resources: []string{"resourcecallbackdefaults", "resourcecallbackdefaults/status"},
},
}, {
Operations: []admissionregistrationv1.OperationType{"CREATE", "UPDATE"},
Rule: admissionregistrationv1.Rule{
Expand Down Expand Up @@ -419,7 +434,8 @@ func TestReconcile(t *testing.T) {
},
path: path,

handlers: handlers,
handlers: handlers,
callbacks: callbacks,

client: kubeclient.Get(ctx),
mwhlister: listers.GetMutatingWebhookConfigurationLister(),
Expand Down

0 comments on commit 4162f86

Please sign in to comment.