Skip to content

Commit ea13c5e

Browse files
authored
Merge pull request kubernetes#127905 from cici37/revert-127400
Revert pr 127400 due to regression
2 parents 03f1344 + 95ec163 commit ea13c5e

File tree

1 file changed

+3
-13
lines changed
  • staging/src/k8s.io/apiserver/pkg/admission/plugin/webhook/generic

1 file changed

+3
-13
lines changed

staging/src/k8s.io/apiserver/pkg/admission/plugin/webhook/generic/webhook.go

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@ import (
2020
"context"
2121
"fmt"
2222
"io"
23-
"sync"
24-
2523
"k8s.io/apiserver/pkg/cel/environment"
2624
"k8s.io/apiserver/pkg/features"
2725
utilfeature "k8s.io/apiserver/pkg/util/feature"
@@ -47,12 +45,6 @@ import (
4745
clientset "k8s.io/client-go/kubernetes"
4846
)
4947

50-
var (
51-
// filterCompiler is memory heavy, so we only want to create it once and share it.
52-
filterCompilerOnce sync.Once
53-
filterCompiler cel.FilterCompiler
54-
)
55-
5648
// Webhook is an abstract admission plugin with all the infrastructure to define Admit or Validate on-top.
5749
type Webhook struct {
5850
*admission.Handler
@@ -64,6 +56,7 @@ type Webhook struct {
6456
namespaceMatcher *namespace.Matcher
6557
objectMatcher *object.Matcher
6658
dispatcher Dispatcher
59+
filterCompiler cel.FilterCompiler
6760
authorizer authorizer.Authorizer
6861
}
6962

@@ -101,17 +94,14 @@ func NewWebhook(handler *admission.Handler, configFile io.Reader, sourceFactory
10194
cm.SetAuthenticationInfoResolver(authInfoResolver)
10295
cm.SetServiceResolver(webhookutil.NewDefaultServiceResolver())
10396

104-
filterCompilerOnce.Do(func() {
105-
filterCompiler = cel.NewFilterCompiler(environment.MustBaseEnvSet(environment.DefaultCompatibilityVersion(), utilfeature.DefaultFeatureGate.Enabled(features.StrictCostEnforcementForWebhooks)))
106-
})
107-
10897
return &Webhook{
10998
Handler: handler,
11099
sourceFactory: sourceFactory,
111100
clientManager: &cm,
112101
namespaceMatcher: &namespace.Matcher{},
113102
objectMatcher: &object.Matcher{},
114103
dispatcher: dispatcherFactory(&cm),
104+
filterCompiler: cel.NewFilterCompiler(environment.MustBaseEnvSet(environment.DefaultCompatibilityVersion(), utilfeature.DefaultFeatureGate.Enabled(features.StrictCostEnforcementForWebhooks))),
115105
}, nil
116106
}
117107

@@ -237,7 +227,7 @@ func (a *Webhook) ShouldCallHook(ctx context.Context, h webhook.WebhookAccessor,
237227
return nil, apierrors.NewInternalError(err)
238228
}
239229

240-
matcher := h.GetCompiledMatcher(filterCompiler)
230+
matcher := h.GetCompiledMatcher(a.filterCompiler)
241231
matchResult := matcher.Match(ctx, versionedAttr, nil, a.authorizer)
242232

243233
if matchResult.Error != nil {

0 commit comments

Comments
 (0)