Skip to content
4 changes: 3 additions & 1 deletion Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion hack/update-codegen.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ CODEGEN_PKG=${CODEGEN_PKG:-$(cd ${REPO_ROOT_DIR}; ls -d -1 ./vendor/k8s.io/code-
# instead of the $GOPATH directly. For normal projects this can be dropped.
${CODEGEN_PKG}/generate-groups.sh "deepcopy,client,informer,lister" \
github.com/knative/eventing/pkg/client github.com/knative/eventing/pkg/apis \
"channels:v1alpha1 feeds:v1alpha1 flows:v1alpha1" \
"channels:v1alpha1 feeds:v1alpha1 flows:v1alpha1 eventing:v1alpha1" \
--go-header-file ${REPO_ROOT_DIR}/hack/boilerplate/boilerplate.go.txt

# Make sure our dependencies are up-to-date
Expand Down
21 changes: 21 additions & 0 deletions pkg/apis/eventing/register.go
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"
)
16 changes: 16 additions & 0 deletions pkg/apis/eventing/v1alpha1/doc.go
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
53 changes: 53 additions & 0 deletions pkg/apis/eventing/v1alpha1/register.go
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
}
25 changes: 25 additions & 0 deletions pkg/apis/eventing/v1alpha1/subscription_defaults.go
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?
Copy link
Copy Markdown
Member

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?

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.

For consistency with other files, I'm leaving this in for now. If you feel strongly, I can remove.

}
210 changes: 210 additions & 0 deletions pkg/apis/eventing/v1alpha1/subscription_types.go
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 {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The 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"`
}
Loading