Skip to content

Add Choice CRD#1529

Merged
knative-prow-robot merged 6 commits into
knative:masterfrom
lionelvillard:choice
Jul 29, 2019
Merged

Add Choice CRD#1529
knative-prow-robot merged 6 commits into
knative:masterfrom
lionelvillard:choice

Conversation

@lionelvillard
Copy link
Copy Markdown
Contributor

@lionelvillard lionelvillard commented Jul 10, 2019

Fixes #1525

This PR only provides the wiring shown in the design document. Currently there is no guarantee that only one branch will be executed. It's up to the user to provide "proper" filter functions.

(moved open issues to design document)

Proposed Changes

  • Add new Choice CRD

Release Note

A Choice CRD has been added for defining functions to execute based on some condition.

@knative-prow-robot knative-prow-robot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Jul 10, 2019
@googlebot googlebot added the cla: yes Indicates the PR's author has signed the CLA. label Jul 10, 2019
@knative-prow-robot knative-prow-robot added the size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. label Jul 10, 2019
@knative-prow-robot
Copy link
Copy Markdown
Contributor

Hi @lionelvillard. Thanks for your PR.

I'm waiting for a knative member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Details

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.

@knative-prow-robot knative-prow-robot added the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label Jul 10, 2019
@lionelvillard lionelvillard changed the title WIP: add Choice CRD Add Choice CRD Jul 11, 2019
@knative-prow-robot knative-prow-robot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Jul 11, 2019
@lionelvillard
Copy link
Copy Markdown
Contributor Author

lionelvillard commented Jul 11, 2019

Removing WIP. The limitations have been captured in the design document and can be addressed in other PRs.

@lionelvillard
Copy link
Copy Markdown
Contributor Author

/ok-to-test

@knative-prow-robot knative-prow-robot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Jul 11, 2019
@lionelvillard lionelvillard force-pushed the choice branch 3 times, most recently from c7479bd to 95b6a80 Compare July 17, 2019 14:49
@lionelvillard
Copy link
Copy Markdown
Contributor Author

@vaikas-google can you take a look at this?

Copy link
Copy Markdown
Contributor

@vaikas vaikas left a comment

Choose a reason for hiding this comment

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

Thanks and my most sincere apologies for this having taken sooooo long... life... 😞
Here's some thoughts and questions about the shape of the API while I'm trying to understand all the everythings going on here.


// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object

// ChoiceList is a collection of Sequences.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: looks like copy / paste error here?

Comment thread config/300-choice.yaml Outdated
- name: Reason
type: string
JSONPath: ".status.conditions[?(@.type==\"Ready\")].reason"
- name: Hostname
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

should we be trying to use the URL now that it's seemingly mature in the v1beta1 of serving?

// ChannelTemplate specifies which Channel CRD to use
ChannelTemplate ChannelTemplateSpec `json:"channelTemplate"`

// Reply is a Reference to where the result of the last Subscriber of a given branch gets sent to.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The comment 'a given branch' would imply that this is per branch, but it seems like by setting this each branch will "terminate" here. Is this really what we want, or should the reply be maybe overrideable at the Case level and if not specified, use the Reply here and then all Cases will terminate to this Reply?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

in the design document I described both cases (Single vs multiple prongs section) as being mutually exclusive, either use a global Reply or per branch. I don't see any problems to have the case reply overriding the global reply, wrt. to composability for instance. Also error-handling will be much easier to implement.

Comment thread pkg/reconciler/choice/choice.go Outdated
// Reconciling choice is pretty straightforward, it does the following things:
// 1. Create a channel fronting the whole choice
// 2. For each of the Cases:
// 2.1 create a Subscription to the previous Channel and subscribe the filter
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

"previous Channel" -> channel in step 1? As in, for Sequence it made sense to refer to previous channel, but here there's only one channel fronting the choice, then all Cases subscribe to it?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

yup bad comment.

Comment thread pkg/reconciler/choice/choice.go Outdated
// 1. Create a channel fronting the whole choice
// 2. For each of the Cases:
// 2.1 create a Subscription to the previous Channel and subscribe the filter
// 2.2 create a Subscription to the filter Channel and subcribe the subscriber
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

can't step 4 be done here and set the reply as part of this step?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

... time passes... looks like there's no step 4 and it's instead done as part of the step 2.2 above?

// * Conditions - the latest available observations of a resource's current state.
duckv1beta1.Status `json:",inline"`

// ChoiceStatuses is an array of corresponding Subscription statuses.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Wonder if it would be better to have a ChoiseCaseStatus and then an array here. I think it's little more complicated than just subscriptionstatus/channelstatus, because each Case actually has 2 subscriptions? It has one that subscribes the filter to the "ingress" channel, and then there's a subscription created from filter (and I'd assume a channel between the filter / "actual" subscriber), so at the very least it seems like you'd need to represent state of 2 subscriptions in each CaseStatus as well as probably one channel (between filter / "actual" subscription) and maybe a Channel after the "actual" subscriber that a Reply gets subscribed to?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

yup agree. The flat array was just to get started.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

We might also want to propagate the Reply status to make it clear which one has been applied (global reply or case reply).

@lionelvillard lionelvillard force-pushed the choice branch 3 times, most recently from e4e0d87 to 4e259bd Compare July 26, 2019 13:20
Copy link
Copy Markdown
Contributor

@vaikas vaikas left a comment

Choose a reason for hiding this comment

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

one small change (unless you want to add the default channel behaviour now?)

Cases []ChoiceCase `json:"cases"`

// ChannelTemplate specifies which Channel CRD to use
ChannelTemplate eventingduckv1alpha1.ChannelTemplateSpec `json:"channelTemplate"`
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Take a look at:
#1569
Might as well add the default channel support to make these easier to use.
TODO & issue would be fine for now if you don't want to add it. But I'd at least change this to a pointer for now to make the transition easier.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

done.

// FilterSubscriptionStatus corresponds to the filter subscription status.
FilterSubscriptionStatus ChoiceSubscriptionStatus `json:"filterSubscriptionStatus"`

// ChannelStatus corresponds to the filter channel status.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: FilterChannelStatus

var _ runtime.Object = (*Choice)(nil)
var _ webhook.GenericCRD = (*Choice)(nil)

type ChoiceSpec struct {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Please file a tracking bug for documenting the usage and examples. Feel free to use something like this as a starting point:
https://github.com/knative/docs/blob/master/docs/eventing/sequence.md

Also, there's a pointer to a simple transformer that might be useful to use in the examples:
instead of step numbers, you could bake in the "branch name" or something:
https://github.com/vaikas-google/transformer

@knative-metrics-robot
Copy link
Copy Markdown

The following is the coverage report on pkg/.
Say /test pull-knative-eventing-go-coverage to re-run this coverage report

File Old Coverage New Coverage Delta
pkg/apis/messaging/v1alpha1/choice_defaults.go Do not exist 100.0%
pkg/apis/messaging/v1alpha1/choice_lifecycle.go Do not exist 98.3%
pkg/apis/messaging/v1alpha1/choice_types.go Do not exist 100.0%
pkg/apis/messaging/v1alpha1/choice_validation.go Do not exist 85.7%
pkg/reconciler/choice/choice.go Do not exist 72.4%
pkg/reconciler/choice/controller.go Do not exist 100.0%

// with a reference to the Addressable duck type. If the resource does not meet this contract,
// it will be reflected in the Subscription's status.
// +optional
Reply *corev1.ObjectReference `json:"reply,omitempty"`
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Does it make sense for choice to support multi-leg Subscriber/Reply?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I was going back and forth on this one and I think one good use case is error-handling, which can be done by having one leg sending the reply to an error sink when the event is an error (TBD).

Copy link
Copy Markdown
Contributor

@vaikas vaikas left a comment

Choose a reason for hiding this comment

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

Could you create an issue to add an e2e test for choice, like:
https://github.com/knative/eventing/blob/master/test/e2e/sequence_test.go

// provided, until one pass (returns true)
Cases []ChoiceCase `json:"cases"`

// ChannelTemplate specifies which Channel CRD to use
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for changing this, could you also add a comment here about the default behaviour since it's an API file.

@vaikas
Copy link
Copy Markdown
Contributor

vaikas commented Jul 29, 2019

/approve
leaving lgtm to @n3wscott since he had comments. Doc changes and e2e tests can be done in a followup PR.

@knative-prow-robot
Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: lionelvillard, vaikas-google

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

The pull request process is described here

Details 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

@knative-prow-robot knative-prow-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jul 29, 2019
@n3wscott
Copy link
Copy Markdown
Contributor

/lgtm

I would like to play with this, there might be changes in the future but given our limitations today I think this is a good starting spot.

@knative-prow-robot knative-prow-robot added the lgtm Indicates that a PR is ready to be merged. label Jul 29, 2019
@knative-prow-robot knative-prow-robot merged commit ecd7c29 into knative:master Jul 29, 2019
@lionelvillard lionelvillard deleted the choice branch January 20, 2020 14:59
pierDipi pushed a commit to pierDipi/eventing that referenced this pull request Dec 7, 2021
Signed-off-by: Matthias Wessendorf <mwessend@redhat.com>

Co-authored-by: Matthias Wessendorf <mwessend@redhat.com>
creydr pushed a commit to creydr/knative-eventing that referenced this pull request Feb 12, 2026
Signed-off-by: red-hat-konflux-kflux-prd-rh02 <190377777+red-hat-konflux-kflux-prd-rh02[bot]@users.noreply.github.com>
Co-authored-by: red-hat-konflux-kflux-prd-rh02[bot] <190377777+red-hat-konflux-kflux-prd-rh02[bot]@users.noreply.github.com>
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. cla: yes Indicates the PR's author has signed the CLA. lgtm Indicates that a PR is ready to be merged. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Be able to easily define branches

6 participants