-
Notifications
You must be signed in to change notification settings - Fork 601
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
Create new Subscription in pkg/apis/eventing as per the new spec. #421
Changes from 1 commit
313b88b
758ae8c
dc67d24
a20d789
7e2d059
28be0a6
0c3fcd7
785ddbc
973d77c
b8a8e49
38983f0
c9fc3b7
add1e88
6a6778a
9237900
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -47,8 +47,14 @@ var _ apis.Immutable = (*Subscription)(nil) | |
var _ runtime.Object = (*Subscription)(nil) | ||
var _ webhook.GenericCRD = (*ClusterBus)(nil) | ||
|
||
// SubscriptionSpec specifies the Channel and Subscriber and the configuration | ||
// arguments for the Subscription. | ||
// SubscriptionSpec specifies the Channel for incoming events, a handler and the Channel | ||
// for outgoing messages. | ||
// from --[transform]--> to | ||
// Note that the following are valid configurations also: | ||
// Sink, no outgoing events: | ||
// from -- transform | ||
// no-op function (identity transformation): | ||
// from --> to | ||
type SubscriptionSpec struct { | ||
// TODO: Generation does not work correctly with CRD. They are scrubbed | ||
// by the APIserver (https://github.com/kubernetes/kubernetes/issues/58778) | ||
|
@@ -57,14 +63,17 @@ type SubscriptionSpec struct { | |
// +optional | ||
Generation int64 `json:"generation,omitempty"` | ||
|
||
// Channel is the name of the channel to subscribe to. | ||
Channel string `json:"channel"` | ||
// From is the name of the channel to subscribe to for receiving events | ||
// to be transformed. | ||
From string `json:"from"` | ||
|
||
// Subscriber is the name of the subscriber service DNS name. | ||
Subscriber string `json:"subscriber"` | ||
// Processor is the processor service DNS name. Events | ||
// from the From channel will be delivered here and replies are sent | ||
// to To channel. | ||
Processor string `json:"processor,omitempty"` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How about There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. since kubernetes resource yaml describes the desired declarative state to be reconciled by a controller, I personally prefer to avoid using verbs that suggest the yaml is defining the imperative logic There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. From conversation in Slack, I'd like to see names which provide the following:
Mostly, we seem to think
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here's an option where there's always a to/from pair at top-level. If both
The downside is that it adds a level of nesting in the config, but that might be worth the tradeoff since these resources would typically be generated from higher level resources and/or CLIs. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What's the upside of adding this extra level of nesting, since to: block will still have the same behaviour as if we kept it the top level? |
||
|
||
// Target service DNS name for replies returned by the subscriber. | ||
ReplyTo string `json:"replyTo,omitempty"` | ||
// To is the name of the channel to send transformed events | ||
To string `json:"to,omitempty"` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How about |
||
|
||
// Arguments is a list of configuration arguments for the Subscription. The | ||
// Arguments for a channel must contain values for each of the Parameters | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,14 +27,14 @@ func (s *Subscription) Validate() *apis.FieldError { | |
} | ||
|
||
func (ss *SubscriptionSpec) Validate() *apis.FieldError { | ||
if ss.Channel == "" { | ||
fe := apis.ErrMissingField("channel") | ||
fe.Details = "the Subscription must reference a Channel" | ||
if ss.From == "" { | ||
fe := apis.ErrMissingField("from") | ||
fe.Details = "the Subscription must reference a from channel" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should probably also ensure that the (In general, it feels like there should be a function to validate an There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. le sigh :) Yes, there's bunch of more work to be done here :) Thanks for the comments, I just don't want to keep churning these things until we settle on the shape and the names. I'm going to add validation for now that it can only be a Channel for now as discussed in Slack yesterday, and later on we can relax. |
||
return fe | ||
} | ||
if ss.Subscriber == "" { | ||
fe := apis.ErrMissingField("subscriber") | ||
fe.Details = "the Subscription must reference a Subscriber" | ||
if ss.To == "" && ss.Processor == "" { | ||
fe := apis.ErrMissingField("to", "processor") | ||
fe.Details = "the Subscription must reference a to channel or a processor" | ||
return fe | ||
} | ||
return nil | ||
|
@@ -49,7 +49,7 @@ func (current *Subscription) CheckImmutableFields(og apis.Immutable) *apis.Field | |
return nil | ||
} | ||
|
||
ignoreArguments := cmpopts.IgnoreFields(SubscriptionSpec{}, "Subscriber", "Arguments") | ||
ignoreArguments := cmpopts.IgnoreFields(SubscriptionSpec{}, "Processor", "Arguments") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
if diff := cmp.Diff(original.Spec, current.Spec, ignoreArguments); diff != "" { | ||
return &apis.FieldError{ | ||
Message: "Immutable fields changed (-old +new)", | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,34 +30,48 @@ func TestSubscriptionSpecValidation(t *testing.T) { | |
}{{ | ||
name: "valid", | ||
c: &SubscriptionSpec{ | ||
Channel: "bar", | ||
Subscriber: "foo", | ||
From: "fromChannel", | ||
Processor: "processor", | ||
}, | ||
want: nil, | ||
}, { | ||
name: "valid with arguments", | ||
c: &SubscriptionSpec{ | ||
Channel: "bar", | ||
Subscriber: "foo", | ||
Arguments: &[]Argument{{Name: "foo", Value: "bar"}}, | ||
From: "fromChannel", | ||
Processor: "processor", | ||
Arguments: &[]Argument{{Name: "foo", Value: "bar"}}, | ||
}, | ||
want: nil, | ||
}, { | ||
name: "missing subscriber", | ||
name: "missing processor and to", | ||
c: &SubscriptionSpec{ | ||
Channel: "foo", | ||
From: "fromChannel", | ||
}, | ||
want: func() *apis.FieldError { | ||
fe := apis.ErrMissingField("subscriber") | ||
fe.Details = "the Subscription must reference a Subscriber" | ||
fe := apis.ErrMissingField("to", "processor") | ||
fe.Details = "the Subscription must reference a to channel or a processor" | ||
return fe | ||
}(), | ||
}, { | ||
name: "missing to", | ||
c: &SubscriptionSpec{ | ||
From: "fromChannel", | ||
To: "toChannel", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should this be "processor", or should "to" be left off? (This matches the next test case right now.) |
||
}, | ||
want: nil, | ||
}, { | ||
name: "missing processor", | ||
c: &SubscriptionSpec{ | ||
From: "fromChannel", | ||
To: "toChannel", | ||
}, | ||
want: nil, | ||
}, { | ||
name: "empty", | ||
c: &SubscriptionSpec{}, | ||
want: func() *apis.FieldError { | ||
fe := apis.ErrMissingField("channel") | ||
fe.Details = "the Subscription must reference a Channel" | ||
fe := apis.ErrMissingField("from") | ||
fe.Details = "the Subscription must reference a from channel" | ||
return fe | ||
}(), | ||
}} | ||
|
@@ -66,7 +80,7 @@ func TestSubscriptionSpecValidation(t *testing.T) { | |
t.Run(test.name, func(t *testing.T) { | ||
got := test.c.Validate() | ||
if diff := cmp.Diff(test.want, got); diff != "" { | ||
t.Errorf("validateChannel (-want, +got) = %v", diff) | ||
t.Errorf("validateFrom (-want, +got) = %v", diff) | ||
} | ||
}) | ||
} | ||
|
@@ -82,48 +96,48 @@ func TestSubscriptionImmutable(t *testing.T) { | |
name: "valid", | ||
c: &Subscription{ | ||
Spec: SubscriptionSpec{ | ||
Channel: "foo", | ||
From: "foo", | ||
}, | ||
}, | ||
og: &Subscription{ | ||
Spec: SubscriptionSpec{ | ||
Channel: "foo", | ||
From: "foo", | ||
}, | ||
}, | ||
want: nil, | ||
}, { | ||
name: "valid, new subscriber", | ||
name: "valid, new processor", | ||
c: &Subscription{ | ||
Spec: SubscriptionSpec{ | ||
Channel: "foo", | ||
Subscriber: "bar", | ||
From: "foo", | ||
Processor: "newProcessor", | ||
}, | ||
}, | ||
og: &Subscription{ | ||
Spec: SubscriptionSpec{ | ||
Channel: "foo", | ||
Subscriber: "baz", | ||
From: "foo", | ||
Processor: "processor", | ||
}, | ||
}, | ||
want: nil, | ||
}, { | ||
name: "channel changed", | ||
name: "from changed", | ||
c: &Subscription{ | ||
Spec: SubscriptionSpec{ | ||
Channel: "foo", | ||
From: "fromChannel", | ||
}, | ||
}, | ||
og: &Subscription{ | ||
Spec: SubscriptionSpec{ | ||
Channel: "bar", | ||
From: "newFromChannel", | ||
}, | ||
}, | ||
want: &apis.FieldError{ | ||
Message: "Immutable fields changed (-old +new)", | ||
Paths: []string{"spec"}, | ||
Details: `{v1alpha1.SubscriptionSpec}.Channel: | ||
-: "bar" | ||
+: "foo" | ||
Details: `{v1alpha1.SubscriptionSpec}.From: | ||
-: "newFromChannel" | ||
+: "fromChannel" | ||
`, | ||
}, | ||
}} | ||
|
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.
no longer a DNS name
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.
done