-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Closes #4949: Label-based filtering for Helm via predicates #4997
Conversation
d386566
to
c05f541
Compare
07e445c
to
12e0fc3
Compare
Needs a changelog fragment (addition) and docs in https://master.sdk.operatorframework.io/docs/building-operators/helm/reference/watches/. |
1cbf0bc
to
658fafa
Compare
72ec429
to
b62d5ca
Compare
Test output:
Additionally, go unit tests still seem to be failing on this PR even though they pass locally.
|
b62d5ca
to
6942467
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/lgtm
cfg, _ := config.GetConfig() | ||
mgr, _ := manager.New(cfg, manager.Options{}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm surprised this returns a valid manager. @VenkatRamaraju does this pass locally for you?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah it does not pass. I recommend refactoring the predicate parse logic into its own function and writing a test specifically for that function.
98e539d
to
b38ce97
Compare
b38ce97
to
1128eae
Compare
if !reflect.ValueOf(selector).IsZero() { | ||
p, err := ctrlpredicate.LabelSelectorPredicate(selector) | ||
if err != nil { | ||
log.Error(err, "Unable to create predicate from selector.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
log.Error(err, "Unable to create predicate from selector.") | |
return fmt.Errorf("error constructing predicate from watches selector: %v", err), nil |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do you mean return nil, fmt.Errorf("error constructing predicate from watches selector: %v", err)
since the first return type is predicate and the second return type is error?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes sorry.
@@ -93,6 +104,21 @@ func Add(mgr manager.Manager, options WatchOptions) error { | |||
return nil | |||
} | |||
|
|||
// parsePredicateSelector parses the selector in the WatchOptions and creates a predicate | |||
// that is used to filter resources based on the specified selector | |||
func parsePredicateSelector(selector metav1.LabelSelector) ctrlpredicate.Predicate { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function should return an error since the user will not want their operator to run if their selectors are not applied.
func parsePredicateSelector(selector metav1.LabelSelector) ctrlpredicate.Predicate { | |
func parsePredicateSelector(selector metav1.LabelSelector) (ctrlpredicate.Predicate, error) { |
} else { | ||
return p | ||
} | ||
} | ||
return nil |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
} else { | |
return p | |
} | |
} | |
return nil | |
return p, nil | |
} | |
return nil, nil |
1128eae
to
0f4b47a
Compare
if !reflect.ValueOf(selector).IsZero() { | ||
p, err := ctrlpredicate.LabelSelectorPredicate(selector) | ||
if err != nil { | ||
return nil, fmt.Errorf("Error constructing predicate from watches selector: %v", err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Error messages must start with a lowercase character if alphabetical.
return nil, fmt.Errorf("Error constructing predicate from watches selector: %v", err) | |
return nil, fmt.Errorf("error constructing predicate from watches selector: %v", err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One fix then LGTM
94e295b
to
42a7d92
Compare
@@ -0,0 +1,7 @@ | |||
entries: | |||
- description: > | |||
Added a filter predicate for labels based on selectors specified in watches.yaml. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should make it clear this is for the helm-operator specifically
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/lgtm
Code all looks good, changelog fragment probably needs a slight tweak though
Signed-off-by: Venkat Ramaraju <venky2063@gmail.com>
42a7d92
to
c04315b
Compare
/lgtm |
Signed-off-by: Venkat Ramaraju <venky2063@gmail.com>
Signed-off-by: Venkat Ramaraju <venky2063@gmail.com> Signed-off-by: Thierry Wasylczenko <thierry.wasylczenko@gmail.com>
Description of the change:
Added a predicate to filter events based on labels.
Motivation for the change:
Allow Helm operators to only watch CRs with specific labels defined in
watches.yaml
, as mentioned in #4949.