fix: ResolverTypeProvider data race
Kubernetes-commit: de1d6fbf2422eb1da7a1fe38e0d0d6b3bfc53fd1
This commit is contained in:
parent
b50caf5d66
commit
99e4fe9de1
|
@ -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 {
|
||||
|
|
Loading…
Reference in New Issue