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

fix: Eventsource resourse label selector operators not working #2795

Merged

Conversation

gokulav137
Copy link
Contributor

Fixes : #2775

Fixed Exist and DoesNotExist throwing error
2023-08-26T14:33:06.147Z ERROR argo-events.eventsource eventsources/eventing.go:564 Failed to start listening eventsource {"eventSourceName": "notification", "eventSourceType": "resource", "eventName": "completed-workflows", "error": "failed after retries: failed to create the label selector for the event source completed-workflows, values: Invalid value: []string{\"\"}: values set must be empty for exists and does not exist"}

Fixed documentation mentioning unsupported operators

Add multiple value support for In and NotIn using comma seperator

Checklist:

gokulav137 and others added 6 commits September 9, 2023 18:38
feat: add all sprig functions to templates (argoproj#2768)
…r correctly

- For Exists and DoesNotExists value is set to empty if no value is
	provided when creating label requirement
- For In and NotIn value is split by "," to create label requirement

Signed-off-by: gokulav137 <gokulav999@gmail.com>
- Test equality operators =, == and in
- Test inequality operators != and notin
- Test greater than operator and lower than operator
- Test exists operator and doesnot exist operator
- Test comma separated values for in
- Test invalid operators <= and >=

Signed-off-by: gokulav137 <gokulav999@gmail.com>
Signed-off-by: gokulav137 <gokulav999@gmail.com>
Signed-off-by: gokulav137 <gokulav999@gmail.com>
@gokulav137 gokulav137 marked this pull request as ready for review September 11, 2023 11:12
@@ -250,7 +250,14 @@ func LabelReq(sel v1alpha1.Selector) (*labels.Requirement, error) {
if sel.Operation != "" {
op = selection.Operator(sel.Operation)
}
req, err := labels.NewRequirement(sel.Key, op, []string{sel.Value})
values := []string{sel.Value}
if (op == selection.Exists || op == selection.DoesNotExist) && sel.Value == "" {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Return an error when sel.Value != ""?

Copy link
Contributor Author

@gokulav137 gokulav137 Sep 12, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If operator is exists or doesnotexists, an error will be thrown from labels.NewRequirement if values is not empty.

Invalid value: []string{""}: values set must be empty for exists and does not exist

Should I add an error from our end? @whynowy

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is good, thanks!

@@ -250,7 +250,14 @@ func LabelReq(sel v1alpha1.Selector) (*labels.Requirement, error) {
if sel.Operation != "" {
op = selection.Operator(sel.Operation)
}
req, err := labels.NewRequirement(sel.Key, op, []string{sel.Value})
values := []string{sel.Value}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Start with var values = make([]string, 0), and use if else?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense will make the change

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Used switch and var []string instead of if else block due to linting error.

@whynowy whynowy changed the title Fix: Eventsource resourse label selector operators not working fix: Eventsource resourse label selector operators not working Sep 12, 2023
Signed-off-by: gokulav137 <gokulav999@gmail.com>
Signed-off-by: gokulav137 <gokulav999@gmail.com>
@gokulav137 gokulav137 force-pushed the fix-label-selector-exist-and-doesnot-exist branch 2 times, most recently from 7b256a7 to 3030191 Compare September 12, 2023 17:58
@whynowy whynowy merged commit f5ce1ef into argoproj:master Sep 12, 2023
20 of 22 checks passed
joelcomp1 pushed a commit to joelcomp1/argo-events that referenced this pull request Sep 26, 2023
…roj#2795)

Signed-off-by: gokulav137 <gokulav999@gmail.com>
Signed-off-by: jmillage <jmillage@bcubed-corp.com>
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

Successfully merging this pull request may close these issues.

EventSource "Resource" label selector doesn't support "exists" operator (and possibly others)
2 participants