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)
|
return p.underlyingTypeProvider.FindIdent(identName)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ResolverEnvOption creates the ResolverTypeProvider with a given DynamicTypeResolver,
|
// ResolverEnvOption creates the ResolverTypeProvider with a given DynamicTypeResolver
|
||||||
// and also returns the CEL ResolverEnvOption to apply it to the env.
|
// and returns the CEL ResolverEnvOption to apply it to the env.
|
||||||
func ResolverEnvOption(resolver TypeResolver) cel.EnvOption {
|
func ResolverEnvOption(resolver TypeResolver) cel.EnvOption {
|
||||||
_, envOpt := NewResolverTypeProviderAndEnvOption(resolver)
|
return func(e *cel.Env) (*cel.Env, error) {
|
||||||
return envOpt
|
tp := &ResolverTypeProvider{typeResolver: resolver, underlyingTypeProvider: e.CELTypeProvider()}
|
||||||
}
|
// set new type provider for the env.
|
||||||
|
|
||||||
// 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()
|
|
||||||
typeProviderOption := cel.CustomTypeProvider(tp)
|
typeProviderOption := cel.CustomTypeProvider(tp)
|
||||||
return typeProviderOption(e)
|
return typeProviderOption(e)
|
||||||
}
|
}
|
||||||
return tp, envOption
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -58,7 +58,7 @@ func TestTypeProvider(t *testing.T) {
|
||||||
},
|
},
|
||||||
} {
|
} {
|
||||||
t.Run(tc.name, func(t *testing.T) {
|
t.Run(tc.name, func(t *testing.T) {
|
||||||
_, option := NewResolverTypeProviderAndEnvOption(&mockTypeResolver{})
|
option := ResolverEnvOption(&mockTypeResolver{})
|
||||||
env := mustCreateEnv(t, option)
|
env := mustCreateEnv(t, option)
|
||||||
ast, issues := env.Compile(tc.expression)
|
ast, issues := env.Compile(tc.expression)
|
||||||
if len(tc.expectCompileError) > 0 {
|
if len(tc.expectCompileError) > 0 {
|
||||||
|
|
|
@ -212,7 +212,7 @@ func TestTypeResolver(t *testing.T) {
|
||||||
},
|
},
|
||||||
} {
|
} {
|
||||||
t.Run(tc.name, func(t *testing.T) {
|
t.Run(tc.name, func(t *testing.T) {
|
||||||
_, option := common.NewResolverTypeProviderAndEnvOption(&DynamicTypeResolver{})
|
option := common.ResolverEnvOption(&DynamicTypeResolver{})
|
||||||
env := mustCreateEnv(t, option)
|
env := mustCreateEnv(t, option)
|
||||||
ast, issues := env.Compile(tc.expression)
|
ast, issues := env.Compile(tc.expression)
|
||||||
if len(tc.expectCompileError) > 0 {
|
if len(tc.expectCompileError) > 0 {
|
||||||
|
@ -307,7 +307,7 @@ func TestCELOptional(t *testing.T) {
|
||||||
},
|
},
|
||||||
} {
|
} {
|
||||||
t.Run(tc.name, func(t *testing.T) {
|
t.Run(tc.name, func(t *testing.T) {
|
||||||
_, option := common.NewResolverTypeProviderAndEnvOption(&DynamicTypeResolver{})
|
option := common.ResolverEnvOption(&DynamicTypeResolver{})
|
||||||
env := mustCreateEnvWithOptional(t, option)
|
env := mustCreateEnvWithOptional(t, option)
|
||||||
ast, issues := env.Compile(tc.expression)
|
ast, issues := env.Compile(tc.expression)
|
||||||
if len(tc.expectedCompileError) > 0 {
|
if len(tc.expectedCompileError) > 0 {
|
||||||
|
|
Loading…
Reference in New Issue