Skip to content

Commit 5682b68

Browse files
liggittk8s-publishing-bot
authored andcommitted
Drop locked StrictCostEnforcementForVAP and StrictCostEnforcementForWebhooks feature gates
Kubernetes-commit: bd11e52bfc10b9b08edbc43cd0c83458f38634f2
1 parent 55248d7 commit 5682b68

File tree

23 files changed

+159
-271
lines changed

23 files changed

+159
-271
lines changed

pkg/admission/plugin/cel/compile.go

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -229,18 +229,19 @@ func mustBuildEnvs(baseEnv *environment.EnvSet) variableDeclEnvs {
229229
for _, hasParams := range []bool{false, true} {
230230
for _, hasAuthorizer := range []bool{false, true} {
231231
var err error
232-
for _, strictCost := range []bool{false, true} {
233-
decl := OptionalVariableDeclarations{HasParams: hasParams, HasAuthorizer: hasAuthorizer, StrictCost: strictCost}
232+
{
233+
decl := OptionalVariableDeclarations{HasParams: hasParams, HasAuthorizer: hasAuthorizer}
234234
envs[decl], err = createEnvForOpts(baseEnv, namespaceType, requestType, decl)
235235
if err != nil {
236236
panic(err)
237237
}
238238
}
239-
// We only need this ObjectTypes where strict cost is true
240-
decl := OptionalVariableDeclarations{HasParams: hasParams, HasAuthorizer: hasAuthorizer, StrictCost: true, HasPatchTypes: true}
241-
envs[decl], err = createEnvForOpts(baseEnv, namespaceType, requestType, decl)
242-
if err != nil {
243-
panic(err)
239+
{
240+
decl := OptionalVariableDeclarations{HasParams: hasParams, HasAuthorizer: hasAuthorizer, HasPatchTypes: true}
241+
envs[decl], err = createEnvForOpts(baseEnv, namespaceType, requestType, decl)
242+
if err != nil {
243+
panic(err)
244+
}
244245
}
245246
}
246247
}
@@ -274,16 +275,11 @@ func createEnvForOpts(baseEnv *environment.EnvSet, namespaceType *apiservercel.D
274275
requestType,
275276
},
276277
},
278+
environment.StrictCostOpt,
277279
)
278280
if err != nil {
279281
return nil, fmt.Errorf("environment misconfigured: %w", err)
280282
}
281-
if opts.StrictCost {
282-
extended, err = extended.Extend(environment.StrictCostOpt)
283-
if err != nil {
284-
return nil, fmt.Errorf("environment misconfigured: %w", err)
285-
}
286-
}
287283

288284
if opts.HasPatchTypes {
289285
extended, err = extended.Extend(hasPatchTypes)

pkg/admission/plugin/cel/compile_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ func TestCompileValidatingPolicyExpression(t *testing.T) {
178178
}
179179

180180
// Include the test library, which includes the test() function in the storage environment during test
181-
base := environment.MustBaseEnvSet(environment.DefaultCompatibilityVersion(), true)
181+
base := environment.MustBaseEnvSet(environment.DefaultCompatibilityVersion())
182182
extended, err := base.Extend(environment.VersionedOptions{
183183
IntroducedVersion: version.MajorMinor(1, 999),
184184
EnvOptions: []celgo.EnvOption{library.Test()},
@@ -254,7 +254,7 @@ func TestCompileValidatingPolicyExpression(t *testing.T) {
254254
}
255255

256256
func BenchmarkCompile(b *testing.B) {
257-
compiler := NewCompiler(environment.MustBaseEnvSet(environment.DefaultCompatibilityVersion(), true))
257+
compiler := NewCompiler(environment.MustBaseEnvSet(environment.DefaultCompatibilityVersion()))
258258
b.ResetTimer()
259259
for i := 0; i < b.N; i++ {
260260
options := OptionalVariableDeclarations{HasParams: rand.Int()%2 == 0, HasAuthorizer: rand.Int()%2 == 0}

pkg/admission/plugin/cel/composition_test.go

Lines changed: 17 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -48,15 +48,14 @@ func (t *testVariable) GetName() string {
4848

4949
func TestCompositedPolicies(t *testing.T) {
5050
cases := []struct {
51-
name string
52-
variables []NamedExpressionAccessor
53-
expression string
54-
attributes admission.Attributes
55-
expectedResult any
56-
expectErr bool
57-
expectedErrorMessage string
58-
runtimeCostBudget int64
59-
strictCostEnforcement bool
51+
name string
52+
variables []NamedExpressionAccessor
53+
expression string
54+
attributes admission.Attributes
55+
expectedResult any
56+
expectErr bool
57+
expectedErrorMessage string
58+
runtimeCostBudget int64
6059
}{
6160
{
6261
name: "simple",
@@ -187,44 +186,29 @@ func TestCompositedPolicies(t *testing.T) {
187186
expectedErrorMessage: "found no matching overload for '_==_' applied to '(string, int)'",
188187
},
189188
{
190-
name: "with strictCostEnforcement on: exceeds cost budget",
189+
name: "exceeds cost budget",
191190
variables: []NamedExpressionAccessor{
192191
&testVariable{
193192
name: "dict",
194193
expression: "'abc 123 def 123'.split(' ')",
195194
},
196195
},
197-
attributes: endpointCreateAttributes(),
198-
expression: "size(variables.dict) > 0",
199-
expectErr: true,
200-
expectedErrorMessage: "validation failed due to running out of cost budget, no further validation rules will be run",
201-
runtimeCostBudget: 5,
202-
strictCostEnforcement: true,
203-
},
204-
{
205-
name: "with strictCostEnforcement off: not exceed cost budget",
206-
variables: []NamedExpressionAccessor{
207-
&testVariable{
208-
name: "dict",
209-
expression: "'abc 123 def 123'.split(' ')",
210-
},
211-
},
212-
attributes: endpointCreateAttributes(),
213-
expression: "size(variables.dict) > 0",
214-
expectedResult: true,
215-
runtimeCostBudget: 5,
216-
strictCostEnforcement: false,
196+
attributes: endpointCreateAttributes(),
197+
expression: "size(variables.dict) > 0",
198+
expectErr: true,
199+
expectedErrorMessage: "validation failed due to running out of cost budget, no further validation rules will be run",
200+
runtimeCostBudget: 5,
217201
},
218202
}
219203
for _, tc := range cases {
220204
t.Run(tc.name, func(t *testing.T) {
221-
compiler, err := NewCompositedCompiler(environment.MustBaseEnvSet(environment.DefaultCompatibilityVersion(), tc.strictCostEnforcement))
205+
compiler, err := NewCompositedCompiler(environment.MustBaseEnvSet(environment.DefaultCompatibilityVersion()))
222206
if err != nil {
223207
t.Fatal(err)
224208
}
225-
compiler.CompileAndStoreVariables(tc.variables, OptionalVariableDeclarations{HasParams: false, HasAuthorizer: false, StrictCost: tc.strictCostEnforcement}, environment.NewExpressions)
209+
compiler.CompileAndStoreVariables(tc.variables, OptionalVariableDeclarations{HasParams: false, HasAuthorizer: false}, environment.NewExpressions)
226210
validations := []ExpressionAccessor{&testCondition{Expression: tc.expression}}
227-
f := compiler.CompileCondition(validations, OptionalVariableDeclarations{HasParams: false, HasAuthorizer: false, StrictCost: tc.strictCostEnforcement}, environment.NewExpressions)
211+
f := compiler.CompileCondition(validations, OptionalVariableDeclarations{HasParams: false, HasAuthorizer: false}, environment.NewExpressions)
228212
versionedAttr, err := admission.NewVersionedAttributes(tc.attributes, tc.attributes.GetKind(), newObjectInterfacesForTest())
229213
if err != nil {
230214
t.Fatal(err)

0 commit comments

Comments
 (0)