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

[Bug] JMESPath conditions for name, namespace or labels don't work #2138

Open
1 task done
bertbaron opened this issue Nov 9, 2024 · 0 comments · May be fixed by #2140
Open
1 task done

[Bug] JMESPath conditions for name, namespace or labels don't work #2138

bertbaron opened this issue Nov 9, 2024 · 0 comments · May be fixed by #2140
Labels
bug Something isn't working

Comments

@bertbaron
Copy link

bertbaron commented Nov 9, 2024

chainsaw version Version

v0.2.11

Description

JMESPath conditions for name or namespace are ignored. When a JMESPath condition is used for a label, all labels are ignored. In our setup this resulted in strange sporadic failures where totally different resources from other tests were matched.

The problem is that ResourceRef assumes that the values for those properties are string and silently removes them as a side-effect when they aren't, removing all labels if any label value isn't a string.

This could be considered an unsupported feature, but because of the strange behaviour and the clear cause I found in the code I think it can be considered a bug.

I already created a fix for which I will submit a pull request.

Steps to reproduce

  1. Run the following test:
apiVersion: chainsaw.kyverno.io/v1alpha1
kind: Test
metadata:
  name: metadata-template-conditions
spec:
  steps:
    - try:
        - apply:
            resource:
              apiVersion: v1
              kind: ConfigMap
              metadata:
                labels:
                  color: green
                  type: peugeot
                  top_speed: '130'
                name: peugeot-206
        - assert:
            resource:
              apiVersion: v1
              kind: ConfigMap
              metadata:
                labels:
                  color: red
                  type: ferrari
                  top_speed:
                    (to_number(@) > `200`): true
                name:
                  (starts_with(@, 'ferrari-')): true

Expected behavior

The test should fail because four conditions don't match, of which two are not even JMESPath conditions.

Screenshots

No response

Logs

No response

Slack discussion

No response

Troubleshooting

  • I have searched other issues in this repository and mine is not recorded.
@bertbaron bertbaron added the bug Something isn't working label Nov 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant