Move CEL env initialization out of package init()

This ensures compatibility version and feature gates can be initialized
before cached CEL environments are created.
This commit is contained in:
Jordan Liggitt
2024-06-29 21:45:55 -04:00
parent 1d2ad282cf
commit 03d48b7683
7 changed files with 75 additions and 32 deletions

View File

@@ -3425,14 +3425,16 @@ func TestValidateValidatingAdmissionPolicyUpdate(t *testing.T) {
t.Fatal(err)
}
if strictCost {
strictStatelessCELCompiler = plugincel.NewCompiler(extended)
originalCompiler := getStrictStatelessCELCompiler()
lazyStrictStatelessCELCompiler = plugincel.NewCompiler(extended)
defer func() {
strictStatelessCELCompiler = plugincel.NewCompiler(environment.MustBaseEnvSet(environment.DefaultCompatibilityVersion(), strictCost))
lazyStrictStatelessCELCompiler = originalCompiler
}()
} else {
nonStrictStatelessCELCompiler = plugincel.NewCompiler(extended)
originalCompiler := getNonStrictStatelessCELCompiler()
lazyNonStrictStatelessCELCompiler = plugincel.NewCompiler(extended)
defer func() {
nonStrictStatelessCELCompiler = plugincel.NewCompiler(environment.MustBaseEnvSet(environment.DefaultCompatibilityVersion(), strictCost))
lazyNonStrictStatelessCELCompiler = originalCompiler
}()
}