Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 26 additions & 12 deletions cmd/webhook/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ import (
configsv1alpha1 "knative.dev/eventing/pkg/apis/configs/v1alpha1"
eventingduckv1alpha1 "knative.dev/eventing/pkg/apis/duck/v1alpha1"
"knative.dev/eventing/pkg/apis/eventing"
"knative.dev/eventing/pkg/apis/eventing/v1alpha1"
baseeventingv1alpha1 "knative.dev/eventing/pkg/apis/eventing/v1alpha1"
eventingv1alpha1 "knative.dev/eventing/pkg/apis/eventing/v1alpha1"
"knative.dev/eventing/pkg/apis/eventing/v1beta1"
baseeventingv1beta1 "knative.dev/eventing/pkg/apis/eventing/v1beta1"
flowsv1alpha1 "knative.dev/eventing/pkg/apis/flows/v1alpha1"
legacysourcesv1alpha1 "knative.dev/eventing/pkg/apis/legacysources/v1alpha1"
messagingv1alpha1 "knative.dev/eventing/pkg/apis/messaging/v1alpha1"
Expand Down Expand Up @@ -201,8 +201,10 @@ func NewLegacySinkBindingWebhook(ctx context.Context, cmw configmap.Watcher) *co

func NewConversionController(ctx context.Context, cmw configmap.Watcher) *controller.Impl {
var (
v1alpha1_ = v1alpha1.SchemeGroupVersion.Version
v1beta1_ = v1beta1.SchemeGroupVersion.Version
eventingv1alpha1_ = baseeventingv1alpha1.SchemeGroupVersion.Version
eventingv1beta1_ = baseeventingv1beta1.SchemeGroupVersion.Version
// messagingv1alpha1_ = basemessagingv1alpha1.SchemeGroupVersion.Version
// messagingv1beta1_ = basemessagingv1beta1.SchemeGroupVersion.Version
)

return conversion.NewConversionController(ctx,
Expand All @@ -211,22 +213,34 @@ func NewConversionController(ctx context.Context, cmw configmap.Watcher) *contro

// Specify the types of custom resource definitions that should be converted
map[schema.GroupKind]conversion.GroupKindConversion{
v1beta1.Kind("Trigger"): {
// eventing
baseeventingv1beta1.Kind("Trigger"): {
DefinitionName: eventing.TriggersResource.String(),
HubVersion: v1alpha1_,
HubVersion: eventingv1alpha1_,
Zygotes: map[string]conversion.ConvertibleObject{
v1alpha1_: &v1alpha1.Trigger{},
v1beta1_: &v1beta1.Trigger{},
eventingv1alpha1_: &baseeventingv1alpha1.Trigger{},
eventingv1beta1_: &baseeventingv1beta1.Trigger{},
},
},
v1beta1.Kind("Broker"): {
baseeventingv1beta1.Kind("Broker"): {
DefinitionName: eventing.BrokersResource.String(),
HubVersion: v1alpha1_,
HubVersion: eventingv1alpha1_,
Zygotes: map[string]conversion.ConvertibleObject{
v1alpha1_: &v1alpha1.Broker{},
v1beta1_: &v1beta1.Broker{},
eventingv1alpha1_: &baseeventingv1alpha1.Broker{},
eventingv1beta1_: &baseeventingv1beta1.Broker{},
},
},
// messaging
/*
basemessagingv1beta1.Kind("Subscription"): {
DefinitionName: messaging.TriggersResource.String(),
HubVersion: messagingv1alpha1_,
Zygotes: map[string]conversion.ConvertibleObject{
messagingv1alpha1_: &basemessagingv1alpha1.Subscription{},
messagingv1beta1_: &basemessagingv1beta1.Subscription{},
},
},
*/
},

// A function that infuses the context passed to ConvertUp/ConvertDown/SetDefaults with custom metadata.
Expand Down
173 changes: 97 additions & 76 deletions config/core/resources/subscription.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ metadata:
knative.dev/crd-install: "true"
spec:
group: messaging.knative.dev
preserveUnknownFields: false
names:
kind: Subscription
plural: subscriptions
Expand All @@ -33,6 +34,13 @@ spec:
scope: Namespaced
subresources:
status: {}
conversion:
strategy: None
# strategy: Webhook
# webhookClientConfig:
# service:
# name: eventing-webhook
# namespace: knative-eventing
additionalPrinterColumns:
- name: Ready
type: string
Expand All @@ -43,85 +51,98 @@ spec:
- name: Age
type: date
JSONPath: .metadata.creationTimestamp
validation:
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.

sorry. 😐

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.

LOL :)

openAPIV3Schema:
type: object
properties:
spec:
required:
- channel
type: object
properties:
channel:
type: object
description: "Channel that forwards incoming events to the subscription."
required:
- apiVersion
- kind
- name
properties:
apiVersion:
type: string
minLength: 1
kind:
type: string
name:
type: string
minLength: 1
subscriber:
type: object
description: "the subscriber that (optionally) processes events."
properties:
uri:
type: string
description: "the target URI or, if ref is provided, a relative URI reference that will be combined with ref to produce a target URI."
minLength: 1
ref:
type: object
description: "a reference to a Kubernetes object from which to retrieve the target URI."
required:
- apiVersion
- kind
- name
properties:
apiVersion:
type: string
minLength: 1
kind:
type: string
minLength: 1
name:
type: string
minLength: 1
namespace:
type: string
minLength: 1
reply:
type: object
description: "the destination that (optionally) receive events."
properties:
uri:
type: string
description: "the target URI or, if ref is provided, a relative URI reference that will be combined with ref to produce a target URI."
minLength: 1
ref:
type: object
description: "a reference to a Kubernetes object from which to retrieve the target URI."
required:
- apiVersion
- kind
- name
properties:
apiVersion:
type: string
minLength: 1
kind:
type: string
minLength: 1
name:
type: string
minLength: 1
namespace:
type: string
minLength: 1
delivery:
description: "Subscription delivery options. More information: https://knative.dev/docs/eventing/event-delivery."
type: object
x-kubernetes-preserve-unknown-fields: true
status:
type: object
x-kubernetes-preserve-unknown-fields: true
versions:
- name: v1alpha1
served: true
storage: true
schema:
openAPIV3Schema:
type: object
properties:
spec:
required:
- channel
type: object
properties:
channel:
type: object
description: "Channel that forwards incoming events to the subscription."
required:
- apiVersion
- kind
- name
properties:
apiVersion:
type: string
minLength: 1
kind:
type: string
name:
type: string
minLength: 1
subscriber:
type: object
description: "the subscriber that (optionally) processes events."
properties:
uri:
type: string
description: "the target URI or, if ref is provided, a relative URI reference that will be combined with ref to produce a target URI."
minLength: 1
ref:
type: object
description: "a reference to a Kubernetes object from which to retrieve the target URI."
required:
- apiVersion
- kind
- name
properties:
apiVersion:
type: string
minLength: 1
kind:
type: string
minLength: 1
name:
type: string
minLength: 1
reply:
type: object
description: "the destination that (optionally) receive events."
properties:
uri:
type: string
description: "the target URI or, if ref is provided, a relative URI reference that will be combined with ref to produce a target URI."
minLength: 1
ref:
type: object
description: "a reference to a Kubernetes object from which to retrieve the target URI."
required:
- apiVersion
- kind
- name
properties:
apiVersion:
type: string
minLength: 1
kind:
type: string
minLength: 1
name:
type: string
minLength: 1
- name: v1beta1
served: false
served: true
storage: false
10 changes: 10 additions & 0 deletions pkg/apis/messaging/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,16 @@ limitations under the License.

package messaging

import "k8s.io/apimachinery/pkg/runtime/schema"

const (
GroupName = "messaging.knative.dev"
)

var (
// SubscriptionssResource respresents a Knative Subscription
TriggersResource = schema.GroupResource{
Group: GroupName,
Resource: "subscriptions",
}
)
81 changes: 81 additions & 0 deletions pkg/apis/messaging/v1alpha1/subscription_conversion.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
/*
Copyright 2020 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 (
"context"
"fmt"

duckv1alpha1 "knative.dev/eventing/pkg/apis/duck/v1alpha1"
duckv1beta1 "knative.dev/eventing/pkg/apis/duck/v1beta1"
"knative.dev/eventing/pkg/apis/messaging/v1beta1"
"knative.dev/pkg/apis"
)

// ConvertUp implements apis.Convertible.
// Converts source (from v1alpha1.Subscription) into v1beta1.Subscription
func (source *Subscription) ConvertUp(ctx context.Context, obj apis.Convertible) error {
switch sink := obj.(type) {
case *v1beta1.Subscription:
sink.ObjectMeta = source.ObjectMeta
sink.Spec.Channel = source.Spec.Channel
if source.Spec.Delivery != nil {
sink.Spec.Delivery = &duckv1beta1.DeliverySpec{}
if err := source.Spec.Delivery.ConvertUp(ctx, sink.Spec.Delivery); err != nil {
return err
}
}
sink.Spec.Subscriber = source.Spec.Subscriber
sink.Spec.Reply = source.Spec.Reply

sink.Status.Status = source.Status.Status
sink.Status.PhysicalSubscription.SubscriberURI = source.Status.PhysicalSubscription.SubscriberURI
sink.Status.PhysicalSubscription.ReplyURI = source.Status.PhysicalSubscription.ReplyURI
sink.Status.PhysicalSubscription.DeadLetterSinkURI = source.Status.PhysicalSubscription.DeadLetterSinkURI
return nil
default:
return fmt.Errorf("Unknown conversion, got: %T", sink)

}
}

// ConvertDown implements apis.Convertible.
// Converts obj from v1beta1.Subscription into v1alpha1.Subscription
func (sink *Subscription) ConvertDown(ctx context.Context, obj apis.Convertible) error {
switch source := obj.(type) {
case *v1beta1.Subscription:
sink.ObjectMeta = source.ObjectMeta
sink.Spec.Channel = source.Spec.Channel
if source.Spec.Delivery != nil {
sink.Spec.Delivery = &duckv1alpha1.DeliverySpec{}
if err := sink.Spec.Delivery.ConvertDown(ctx, source.Spec.Delivery); err != nil {
return err
}
}
sink.Spec.Subscriber = source.Spec.Subscriber
sink.Spec.Reply = source.Spec.Reply

sink.Status.Status = source.Status.Status
sink.Status.PhysicalSubscription.SubscriberURI = source.Status.PhysicalSubscription.SubscriberURI
sink.Status.PhysicalSubscription.ReplyURI = source.Status.PhysicalSubscription.ReplyURI
sink.Status.PhysicalSubscription.DeadLetterSinkURI = source.Status.PhysicalSubscription.DeadLetterSinkURI

return nil
default:
return fmt.Errorf("Unknown conversion, got: %T", source)
}
}
Loading