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

✨ pkg/predicate.go: add And and Or predicates #1043

Merged
merged 1 commit into from
Jul 17, 2020

Conversation

joelanford
Copy link
Member

This PR adds two new boolean predicate functions (predicate.And() and predicate.Or()) that take a variadic predicates argument.

When creating a watch, multiple predicates can be used, but they are always logically ANDed together. If these boolean predicates existed, it would be easier for users to reuse simple predicates to build complex predicate filters for their watches without having to resort to writing their own monolithic predicate from scratch.

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Jul 10, 2020
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: joelanford

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added approved Indicates a PR has been approved by an approver from all required OWNERS files. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Jul 10, 2020
@joelanford
Copy link
Member Author

/hold
to get an approval other than mine.

@k8s-ci-robot k8s-ci-robot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Jul 10, 2020
@alvaroaleman
Copy link
Member

When creating a watch, multiple predicates can be used, but they are always logically ANDed together. If these boolean predicates existed, it would be easier for users to reuse simple predicates to build complex predicate filters for their watches without having to resort to writing their own monolithic predicate from scratch.

If and is already the default, why add an explicit wrapper to replicate that?

@joelanford
Copy link
Member Author

joelanford commented Jul 10, 2020

If and is already the default, why add an explicit wrapper to replicate that?

It would still be needed for arbitrary boolean syntax: e.g. (A || (B && C))

Edit: wondering if there should be a Not() predicate as well to complete the necessary boolean primatives. I suppose that could be added later if it turns out to be useful.

Copy link
Member

@alvaroaleman alvaroaleman left a comment

Choose a reason for hiding this comment

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

/lgtm

We should probably add godocs clarifying that predicates are anded by default

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jul 10, 2020
@joelanford
Copy link
Member Author

/hold cancel

This was discussed at the biweekly developer meeting and there was consensus to merge it.

@k8s-ci-robot k8s-ci-robot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Jul 16, 2020
@alvaroaleman
Copy link
Member

/retest

@k8s-ci-robot k8s-ci-robot merged commit 57ed2a3 into kubernetes-sigs:master Jul 17, 2020
@joelanford joelanford deleted the boolean-predicates branch July 23, 2020 12:24
@joelanford
Copy link
Member Author

/milestone v0.6.x

@k8s-ci-robot
Copy link
Contributor

@joelanford: You must be a member of the kubernetes-sigs/controller-runtime-maintainers GitHub team to set the milestone. If you believe you should be able to issue the /milestone command, please contact your Controller Runtime Maintainers and have them propose you as an additional delegate for this responsibility.

In response to this:

/milestone v0.6.x

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@joelanford
Copy link
Member Author

^^^ @vincepri can we get this into the next v0.6.x release?

@vincepri
Copy link
Member

/milestone v0.6.x

@joelanford Yes, it'll definitely be 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants