Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Function contains crashes for element of type object #6

Open
anbrsap opened this issue Dec 6, 2022 · 0 comments
Open

Function contains crashes for element of type object #6

anbrsap opened this issue Dec 6, 2022 · 0 comments

Comments

@anbrsap
Copy link

anbrsap commented Dec 6, 2022

Problem

With the following JMESPatch expression (download):

contains(`[{"k": "v"}]`, `{ "k": "v" }`)

go-jmespath panicks:

$ kyverno jp -e contains.jmespath.txt <<<"{}"
panic: runtime error: comparing uncomparable type map[string]interface {}

goroutine 1 [running]:
github.com/jmespath/go-jmespath.jpfContains({0xc000bd08e0?, 0xc000bd08e0?, 0x2?})
	/home/runner/go/pkg/mod/github.com/kyverno/[email protected]/functions.go:455 +0x145
github.com/jmespath/go-jmespath.(*functionCaller).CallFunction(0x28a9be0?, {0xc000796240, 0x8}, {0xc000bd08e0, 0x2, 0x2}, 0xc000bde0b0)
	/home/runner/go/pkg/mod/github.com/kyverno/[email protected]/functions.go:401 +0x252
github.com/jmespath/go-jmespath.(*treeInterpreter).Execute(0xc000bde0b0, {0x4, {0x27e9160, 0xc000bcc280}, {0xc000bca420, 0x2, 0x2}}, {0x290c1c0, 0xc000bd2720})
	/home/runner/go/pkg/mod/github.com/kyverno/[email protected]/interpreter.go:93 +0x1fe9
github.com/jmespath/go-jmespath.(*JMESPath).Search(...)
	/home/runner/go/pkg/mod/github.com/kyverno/[email protected]/api.go:37
github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/jp.Command.func1(0xc000bc8c00?, {0xc000bd03e0?, 0x2?, 0x2?})
	/home/runner/work/kyverno/kyverno/cmd/cli/kubectl-kyverno/jp/jp_command.go:87 +0x846
github.com/spf13/cobra.(*Command).execute(0xc000bc8c00, {0xc000bd03c0, 0x2, 0x2})
	/home/runner/go/pkg/mod/github.com/spf13/[email protected]/command.go:916 +0x862
github.com/spf13/cobra.(*Command).ExecuteC(0xc000bc8000)
	/home/runner/go/pkg/mod/github.com/spf13/[email protected]/command.go:1040 +0x3b4
github.com/spf13/cobra.(*Command).Execute(...)
	/home/runner/go/pkg/mod/github.com/spf13/[email protected]/command.go:968
main.main()
	/home/runner/work/kyverno/kyverno/cmd/cli/kubectl-kyverno/main.go:35 +0xc9

Expected Behavior

The expression should evaluate to true.

Interestingly, a comparison using == of the same object values works as expected (download):

`{"k":"v"}` == `{ "k": "v" }`
$ kyverno jp -e equals.jmespath.txt <<<"{}"
true

Additional Info

Kyverno versions known to be affected (non-exhaustive): 1.8.1, 1.8.3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant