-
Notifications
You must be signed in to change notification settings - Fork 630
Create new Subscription in pkg/apis/eventing as per the new spec. #421
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
Merged
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
313b88b
Rename Subscription fields to: from,to,processor
758ae8c
make things refs
dc67d24
address pr feedback, remove left over cruft
a20d789
add the contracts we expect each object reference to fulfill
7e2d059
use Sinkable contract for the To ref
28be0a6
update tests to refs
0c3fcd7
more tests
785ddbc
moar tests
973d77c
add test for Subscription object
b8a8e49
processor -> call
38983f0
Revert changes to pkg/channels, move everything over to pkg/eventing
c9fc3b7
add tests
add1e88
address pr feedback
6a6778a
rename meta_v1 to metav1
9237900
address PR comments
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| /* | ||
| Copyright 2018 The Knative Authors | ||
|
|
||
| Licensed under the Apache License, Version 2.0 (the "License"); | ||
| you may not use this file except in compliance with the License. | ||
| You may obtain a copy of the License at | ||
|
|
||
| http://www.apache.org/licenses/LICENSE-2.0 | ||
|
|
||
| Unless required by applicable law or agreed to in writing, software | ||
| distributed under the License is distributed on an "AS IS" BASIS, | ||
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| See the License for the specific language governing permissions and | ||
| limitations under the License. | ||
| */ | ||
|
|
||
| package eventing | ||
|
|
||
| const ( | ||
| GroupName = "eventing.knative.dev" | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| /* | ||
| Copyright 2018 The Knative Authors | ||
| Licensed under the Apache License, Version 2.0 (the "License"); | ||
| you may not use this file except in compliance with the License. | ||
| You may obtain a copy of the License at | ||
| http://www.apache.org/licenses/LICENSE-2.0 | ||
| Unless required by applicable law or agreed to in writing, software | ||
| distributed under the License is distributed on an "AS IS" BASIS, | ||
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| See the License for the specific language governing permissions and | ||
| limitations under the License. | ||
| */ | ||
| // +k8s:deepcopy-gen=package | ||
| // Package v1alpha1 is the v1alpha1 version of the API. | ||
| // +groupName=eventing.knative.dev | ||
| package v1alpha1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| /* | ||
| Copyright 2018 The Knative Authors | ||
|
|
||
| Licensed under the Apache License, Version 2.0 (the "License"); | ||
| you may not use this file except in compliance with the License. | ||
| You may obtain a copy of the License at | ||
|
|
||
| http://www.apache.org/licenses/LICENSE-2.0 | ||
|
|
||
| Unless required by applicable law or agreed to in writing, software | ||
| distributed under the License is distributed on an "AS IS" BASIS, | ||
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| See the License for the specific language governing permissions and | ||
| limitations under the License. | ||
| */ | ||
|
|
||
| package v1alpha1 | ||
|
|
||
| import ( | ||
| "github.com/knative/eventing/pkg/apis/eventing" | ||
|
|
||
| metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
| "k8s.io/apimachinery/pkg/runtime" | ||
| "k8s.io/apimachinery/pkg/runtime/schema" | ||
| ) | ||
|
|
||
| // SchemeGroupVersion is group version used to register these objects | ||
| var SchemeGroupVersion = schema.GroupVersion{Group: eventing.GroupName, Version: "v1alpha1"} | ||
|
|
||
| // Kind takes an unqualified kind and returns back a Group qualified GroupKind | ||
| func Kind(kind string) schema.GroupKind { | ||
| return SchemeGroupVersion.WithKind(kind).GroupKind() | ||
| } | ||
|
|
||
| // Resource takes an unqualified resource and returns a Group qualified GroupResource | ||
| func Resource(resource string) schema.GroupResource { | ||
| return SchemeGroupVersion.WithResource(resource).GroupResource() | ||
| } | ||
|
|
||
| var ( | ||
| SchemeBuilder = runtime.NewSchemeBuilder(addKnownTypes) | ||
| AddToScheme = SchemeBuilder.AddToScheme | ||
| ) | ||
|
|
||
| // Adds the list of known types to Scheme. | ||
| func addKnownTypes(scheme *runtime.Scheme) error { | ||
| scheme.AddKnownTypes(SchemeGroupVersion, | ||
| &Subscription{}, | ||
| &SubscriptionList{}, | ||
| ) | ||
| metav1.AddToGroupVersion(scheme, SchemeGroupVersion) | ||
| return nil | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| /* | ||
| Copyright 2018 The Knative Authors | ||
|
|
||
| Licensed under the Apache License, Version 2.0 (the "License"); | ||
| you may not use this file except in compliance with the License. | ||
| You may obtain a copy of the License at | ||
|
|
||
| http://www.apache.org/licenses/LICENSE-2.0 | ||
|
|
||
| Unless required by applicable law or agreed to in writing, software | ||
| distributed under the License is distributed on an "AS IS" BASIS, | ||
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| See the License for the specific language governing permissions and | ||
| limitations under the License. | ||
| */ | ||
|
|
||
| package v1alpha1 | ||
|
|
||
| func (s *Subscription) SetDefaults() { | ||
| s.Spec.SetDefaults() | ||
| } | ||
|
|
||
| func (ss *SubscriptionSpec) SetDefaults() { | ||
| // TODO anything? | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,210 @@ | ||
| /* | ||
| * Copyright 2018 The Knative Authors | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package v1alpha1 | ||
|
|
||
| import ( | ||
| "encoding/json" | ||
|
|
||
| "github.com/knative/pkg/apis" | ||
| "github.com/knative/pkg/webhook" | ||
| "k8s.io/api/core/v1" | ||
| corev1 "k8s.io/api/core/v1" | ||
| metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
| "k8s.io/apimachinery/pkg/runtime" | ||
| ) | ||
|
|
||
| // +genclient | ||
| // +genclient:noStatus | ||
| // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object | ||
| // +k8s:defaulter-gen=true | ||
|
|
||
| // Subscription routes events received on a Channel to a DNS name and | ||
| // corresponds to the subscriptions.channels.knative.dev CRD. | ||
| type Subscription struct { | ||
| metav1.TypeMeta `json:",inline"` | ||
| metav1.ObjectMeta `json:"metadata"` | ||
| Spec SubscriptionSpec `json:"spec"` | ||
| Status SubscriptionStatus `json:"status,omitempty"` | ||
| } | ||
|
|
||
| // Check that Subscription can be validated, can be defaulted, and has immutable fields. | ||
| var _ apis.Validatable = (*Subscription)(nil) | ||
| var _ apis.Defaultable = (*Subscription)(nil) | ||
| var _ apis.Immutable = (*Subscription)(nil) | ||
| var _ runtime.Object = (*Subscription)(nil) | ||
| var _ webhook.GenericCRD = (*Subscription)(nil) | ||
|
|
||
| // SubscriptionSpec specifies the Channel for incoming events, a Call target for | ||
| // processing those events and where to put the result of the processing. Only | ||
| // From (where the events are coming from) is always required. You can optionally | ||
| // only Process the events (results in no output events) by leaving out the Result. | ||
| // You can also perform an identity transformation on the invoming events by leaving | ||
| // out the Call and only specifying Result. | ||
| // | ||
| // The following are all valid specifications: | ||
| // from --[call]--> result | ||
| // Sink, no outgoing events: | ||
| // from -- call | ||
| // no-op function (identity transformation): | ||
| // from --> result | ||
| type SubscriptionSpec struct { | ||
| // TODO: Generation used to not work correctly with CRD. They were scrubbed | ||
| // by the APIserver (https://github.com/kubernetes/kubernetes/issues/58778) | ||
| // So, we add Generation here. Once the above bug gets rolled out to production | ||
| // clusters, remove this and use ObjectMeta.Generation instead. | ||
| // +optional | ||
| Generation int64 `json:"generation,omitempty"` | ||
|
|
||
| // Reference to an object that will be used to create the subscription | ||
| // for receiving events. The object must have spec.subscriptions | ||
| // list which will then be modified accordingly. | ||
| // | ||
| // This object must fulfill the Subscribable contract. | ||
| // | ||
| // You can specify only the following fields of the ObjectReference: | ||
| // - Kind | ||
| // - APIVersion | ||
| // - Name | ||
| // Currently Kind must be "Channel" and | ||
| // APIVersion must be "channels.knative.dev/v1alpha1" | ||
| // | ||
| // This field is immutable. We have no good answer on what happens to | ||
| // the events that are currently in the channel being consumed from | ||
| // and what the semantics there should be. For now, you can always | ||
| // delete the Subscription and recreate it to point to a different | ||
| // channel, giving the user more control over what semantics should | ||
| // be used (drain the channel first, possibly have events dropped, | ||
| // etc.) | ||
| From corev1.ObjectReference `json:"from"` | ||
|
|
||
| // Call is reference to (optional) function for processing events. | ||
| // Events from the From channel will be delivered here and replies | ||
| // are sent to a channel as specified by the Result. | ||
| // +optional | ||
| Call *Callable `json:"call,omitempty"` | ||
|
|
||
| // Result specifies (optionally) how to handle events returned from | ||
| // the Call target. | ||
| // +optional | ||
| Result *ResultStrategy `json:"result,omitempty"` | ||
| } | ||
|
|
||
| // Callable specifies the reference to an object that's expected to | ||
| // provide the resolved target of the action. | ||
| // Currently we inspect the objects Status and see if there's a predefined | ||
| // Status field that we will then use to dispatch events to be processed by | ||
| // the target. Currently must resolve to a k8s service or Istio virtual | ||
| // service. | ||
| // Note that in the future we should try to utilize subresources (/resolve ?) to | ||
| // make this cleaner, but CRDs do not support subresources yet, so we need | ||
| // to rely on a specified Status field today. By relying on this behaviour | ||
| // we can utilize a dynamic client instead of having to understand all | ||
| // kinds of different types of objects. As long as they adhere to this | ||
| // particular contract, they can be used as a Target. | ||
| // | ||
| // This ensures that we can support external targets and for ease of use | ||
| // we also allow for an URI to be specified. | ||
| // There of course is also a requirement for the resolved Callable to | ||
| // behave properly at the data plane level. | ||
| // TODO: Add a pointer to a real spec for this. | ||
| // For now, this means: Receive an event payload, and respond with one of: | ||
| // success and an optional response event, or failure. | ||
| // Delivery failures may be retried by the from Channel | ||
| type Callable struct { | ||
| // Only one of these can be specified | ||
|
|
||
| // Reference to an object that will be used to find the target | ||
| // endpoint. | ||
| // For example, this could be a reference to a Route resource | ||
| // or a Knative Service resource. | ||
| // TODO: Specify the required fields the target object must | ||
| // have in the status. | ||
| // You can specify only the following fields of the ObjectReference: | ||
| // - Kind | ||
| // - APIVersion | ||
| // - Name | ||
| // +optional | ||
| Target *corev1.ObjectReference `json:"target,omitempty"` | ||
|
|
||
| // Reference to a 'known' endpoint where no resolving is done. | ||
| // http://k8s-service for example | ||
| // http://myexternalhandler.example.com/foo/bar | ||
| // +optional | ||
| TargetURI *string `json:"targetURI,omitempty"` | ||
| } | ||
|
|
||
| type ResultStrategy struct { | ||
| // This object must fulfill the Sinkable contract. | ||
| // | ||
| // TODO: Specify the required fields the target object must | ||
| // have in the status. | ||
| // You can specify only the following fields of the ObjectReference: | ||
| // - Kind | ||
| // - APIVersion | ||
| // - Name | ||
| // +optional | ||
| Target *corev1.ObjectReference `json:"target,omitempty"` | ||
| } | ||
|
|
||
| type SubscriptionConditionType string | ||
|
|
||
| const ( | ||
| // SubscriptionReady is when the From,Call and Result have been reconciled successfully. | ||
| SubscriptionReady SubscriptionConditionType = "Ready" | ||
| ) | ||
|
|
||
| // SubscriptionCondition describes the state of a subscription at a point in time. | ||
| type SubscriptionCondition struct { | ||
| // Type of subscription condition. | ||
| Type SubscriptionConditionType `json:"type"` | ||
| // Status of the condition, one of True, False, Unknown. | ||
| Status v1.ConditionStatus `json:"status"` | ||
| // The reason for the condition's last transition. | ||
| Reason string `json:"reason,omitempty"` | ||
| // A human readable message indicating details about the transition. | ||
| Message string `json:"message,omitempty"` | ||
| } | ||
|
|
||
| // SubscriptionStatus (computed) for a subscription | ||
| type SubscriptionStatus struct { | ||
| // Represents the latest available observations of a subscription's current state. | ||
| // +patchMergeKey=type | ||
| // +patchStrategy=merge | ||
| Conditions []SubscriptionCondition `json:"conditions,omitempty" patchStrategy:"merge" patchMergeKey:"type"` | ||
| } | ||
|
|
||
| func (ss *SubscriptionStatus) GetCondition(t SubscriptionConditionType) *SubscriptionCondition { | ||
|
Member
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. @n3wscott has a PR to pkg that will generate a bunch of this, so no need to go overboard here. |
||
| for _, cond := range ss.Conditions { | ||
| if cond.Type == t { | ||
| return &cond | ||
| } | ||
| } | ||
| return nil | ||
| } | ||
|
|
||
| func (s *Subscription) GetSpecJSON() ([]byte, error) { | ||
| return json.Marshal(s.Spec) | ||
| } | ||
|
|
||
| // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object | ||
|
|
||
| // SubscriptionList returned in list operations | ||
| type SubscriptionList struct { | ||
| metav1.TypeMeta `json:",inline"` | ||
| metav1.ListMeta `json:"metadata"` | ||
| Items []Subscription `json:"items"` | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 we need this file if we don't default anything?
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.
For consistency with other files, I'm leaving this in for now. If you feel strongly, I can remove.