mirror of
https://github.com/k3s-io/kubernetes.git
synced 2026-07-17 20:00:07 +00:00
Merge pull request #132061 from miltosdoul/fix_typeprovider_datarace
fix: datarace in ResolverTypeProvider
This commit is contained in:
@@ -105,23 +105,13 @@ func (p *ResolverTypeProvider) FindIdent(identName string) (ref.Val, bool) {
|
||||
return p.underlyingTypeProvider.FindIdent(identName)
|
||||
}
|
||||
|
||||
// ResolverEnvOption creates the ResolverTypeProvider with a given DynamicTypeResolver,
|
||||
// and also returns the CEL ResolverEnvOption to apply it to the env.
|
||||
// ResolverEnvOption creates the ResolverTypeProvider with a given DynamicTypeResolver
|
||||
// and returns the CEL ResolverEnvOption to apply it to the env.
|
||||
func ResolverEnvOption(resolver TypeResolver) cel.EnvOption {
|
||||
_, envOpt := NewResolverTypeProviderAndEnvOption(resolver)
|
||||
return envOpt
|
||||
}
|
||||
|
||||
// NewResolverTypeProviderAndEnvOption creates the ResolverTypeProvider with a given DynamicTypeResolver,
|
||||
// and also returns the CEL ResolverEnvOption to apply it to the env.
|
||||
func NewResolverTypeProviderAndEnvOption(resolver TypeResolver) (*ResolverTypeProvider, cel.EnvOption) {
|
||||
tp := &ResolverTypeProvider{typeResolver: resolver}
|
||||
var envOption cel.EnvOption = func(e *cel.Env) (*cel.Env, error) {
|
||||
// wrap the existing type provider (acquired from the env)
|
||||
// and set new type provider for the env.
|
||||
tp.underlyingTypeProvider = e.CELTypeProvider()
|
||||
return func(e *cel.Env) (*cel.Env, error) {
|
||||
tp := &ResolverTypeProvider{typeResolver: resolver, underlyingTypeProvider: e.CELTypeProvider()}
|
||||
// set new type provider for the env.
|
||||
typeProviderOption := cel.CustomTypeProvider(tp)
|
||||
return typeProviderOption(e)
|
||||
}
|
||||
return tp, envOption
|
||||
}
|
||||
|
||||
@@ -58,7 +58,7 @@ func TestTypeProvider(t *testing.T) {
|
||||
},
|
||||
} {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
_, option := NewResolverTypeProviderAndEnvOption(&mockTypeResolver{})
|
||||
option := ResolverEnvOption(&mockTypeResolver{})
|
||||
env := mustCreateEnv(t, option)
|
||||
ast, issues := env.Compile(tc.expression)
|
||||
if len(tc.expectCompileError) > 0 {
|
||||
|
||||
@@ -212,7 +212,7 @@ func TestTypeResolver(t *testing.T) {
|
||||
},
|
||||
} {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
_, option := common.NewResolverTypeProviderAndEnvOption(&DynamicTypeResolver{})
|
||||
option := common.ResolverEnvOption(&DynamicTypeResolver{})
|
||||
env := mustCreateEnv(t, option)
|
||||
ast, issues := env.Compile(tc.expression)
|
||||
if len(tc.expectCompileError) > 0 {
|
||||
@@ -307,7 +307,7 @@ func TestCELOptional(t *testing.T) {
|
||||
},
|
||||
} {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
_, option := common.NewResolverTypeProviderAndEnvOption(&DynamicTypeResolver{})
|
||||
option := common.ResolverEnvOption(&DynamicTypeResolver{})
|
||||
env := mustCreateEnvWithOptional(t, option)
|
||||
ast, issues := env.Compile(tc.expression)
|
||||
if len(tc.expectedCompileError) > 0 {
|
||||
|
||||
Reference in New Issue
Block a user