Thanks for your reply, the following code can reproduce the problem.
package main
import (
"fmt"
_ "
github.com/gogo/protobuf/gogoproto"
proto1 "
github.com/gogo/protobuf/proto"
goproto "
github.com/golang/protobuf/proto"
"
github.com/google/cel-go/cel"
"
github.com/google/cel-go/checker/decls"
"
k8s.io/apiserver/pkg/apis/audit/v1beta1"
)
var ProtoMap = []string{
"
k8s.io/api/authentication/v1/generated.proto",
"
k8s.io/apimachinery/pkg/runtime/generated.proto",
"
k8s.io/apimachinery/pkg/runtime/schema/generated.proto",
"
k8s.io/apimachinery/pkg/apis/meta/v1/generated.proto",
}
func main() {
event := &v1beta1.Event{}
event.UserAgent = "test"
for _, p:= range ProtoMap {
descriptor := proto1.FileDescriptor("
k8s.io/kubernetes/vendor/"+p)
goproto.RegisterFile(p, descriptor)
}
goproto.RegisterFile(
"
github.com/gogo/protobuf/gogoproto/gogo.proto",
proto1.FileDescriptor("gogo.proto"))
env, err := cel.NewEnv(
cel.Types(&v1beta1.Event{}),
cel.Declarations(
decls.NewVar("event",
decls.NewObjectType("k8s.io.apiserver.pkg.apis.audit.v1beta1.Event"),
),
),
)
ast, iss := env.Compile(`event.userAgent == "test"`)
if iss.Err() != nil {
fmt.Print(iss.Err())
}
prog, err := env.Program(ast)
if err != nil {
fmt.Print(err)
}
vars := make(map[string]interface{})
vars["event"] = event
out, _ , err := prog.Eval(vars)
if err != nil {
fmt.Print(err)
}
// expected = True
fmt.Print("result:", out)
}
I think this example expect result is bool value. but i got an error.
runtime.call32 at asm_amd64.s:1
runtime.gopanic at panic.go:975
reflect.flag.mustBe at value.go:208
reflect.Value.Call at value.go:319
main.main at testcel.go:57
runtime.main at proc.go:203
runtime.goexit at asm_amd64.s:1373
- Async stack trace
runtime.rt0_go at asm_amd64.s:220