Skip to content
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

More EventType v1beta2 work #6903

Merged
merged 3 commits into from
May 3, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
18 changes: 16 additions & 2 deletions cmd/webhook/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,10 @@ import (
"knative.dev/pkg/webhook/resourcesemantics/validation"

defaultconfig "knative.dev/eventing/pkg/apis/config"
"knative.dev/eventing/pkg/apis/eventing"
eventingv1 "knative.dev/eventing/pkg/apis/eventing/v1"
eventingv1beta1 "knative.dev/eventing/pkg/apis/eventing/v1beta1"
eventingv1beta2 "knative.dev/eventing/pkg/apis/eventing/v1beta2"
flowsv1 "knative.dev/eventing/pkg/apis/flows/v1"
channeldefaultconfig "knative.dev/eventing/pkg/apis/messaging/config"
messagingv1 "knative.dev/eventing/pkg/apis/messaging/v1"
Expand All @@ -66,6 +68,7 @@ var ourTypes = map[schema.GroupVersionKind]resourcesemantics.GenericCRD{
// For group eventing.knative.dev.
// v1beta1
eventingv1beta1.SchemeGroupVersion.WithKind("EventType"): &eventingv1beta1.EventType{},
eventingv1beta2.SchemeGroupVersion.WithKind("EventType"): &eventingv1beta2.EventType{},
matzew marked this conversation as resolved.
Show resolved Hide resolved
// v1
eventingv1.SchemeGroupVersion.WithKind("Broker"): &eventingv1.Broker{},
eventingv1.SchemeGroupVersion.WithKind("Trigger"): &eventingv1.Trigger{},
Expand Down Expand Up @@ -227,8 +230,10 @@ func NewConversionController(ctx context.Context, cmw configmap.Watcher) *contro
}

var (
sourcesv1beta2_ = sourcesv1beta2.SchemeGroupVersion.Version
sourcesv1_ = sourcesv1.SchemeGroupVersion.Version
sourcesv1beta2_ = sourcesv1beta2.SchemeGroupVersion.Version
sourcesv1_ = sourcesv1.SchemeGroupVersion.Version
eventingv1beta1_ = eventingv1beta1.SchemeGroupVersion.Version
eventingv1beta2_ = eventingv1beta2.SchemeGroupVersion.Version
)

return conversion.NewConversionController(ctx,
Expand All @@ -246,6 +251,15 @@ func NewConversionController(ctx context.Context, cmw configmap.Watcher) *contro
sourcesv1_: &sourcesv1.PingSource{},
},
},
// Eventing
eventingv1beta2.Kind("EventType"): {
DefinitionName: eventing.EventTypesResource.String(),
HubVersion: eventingv1beta1_,
Zygotes: map[string]conversion.ConvertibleObject{
eventingv1beta1_: &eventingv1beta1.EventType{},
eventingv1beta2_: &eventingv1beta2.EventType{},
},
},
},

// A function that infuses the context passed to ConvertTo/ConvertFrom/SetDefaults with custom metadata.
Expand Down
48 changes: 43 additions & 5 deletions pkg/apis/eventing/v1beta1/eventtype_conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,55 @@ package v1beta1

import (
"context"
"fmt"

"knative.dev/eventing/pkg/apis/eventing/v1beta2"

"knative.dev/pkg/apis"
)

// ConvertTo implements apis.Convertible
func (source *EventType) ConvertTo(ctx context.Context, to apis.Convertible) error {
return fmt.Errorf("v1beta1 is the highest known version, got: %T", to)
func (source *EventType) ConvertTo(ctx context.Context, obj apis.Convertible) error {
switch sink := obj.(type) {
Copy link
Member

Choose a reason for hiding this comment

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

nit: Isn't the name sink a bit misleading in our case? (instead of using to/from).

Copy link
Member Author

Choose a reason for hiding this comment

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

case *v1beta2.EventType:
sink.ObjectMeta = source.ObjectMeta
sink.Status = v1beta2.EventTypeStatus{
Status: source.Status.Status,
}
sink.Spec = v1beta2.EventTypeSpec{
Type: source.Spec.Type,
Source: source.Spec.Source,
Schema: source.Spec.Schema,
SchemaData: source.Spec.SchemaData,
Broker: source.Spec.Broker,
Description: source.Spec.Description,
}

return nil
default:
return apis.ConvertToViaProxy(ctx, source, &v1beta2.EventType{}, sink)
}
}

// ConvertFrom implements apis.Convertible
func (sink *EventType) ConvertFrom(ctx context.Context, from apis.Convertible) error {
return fmt.Errorf("v1beta1 is the highest known version, got: %T", from)
func (sink *EventType) ConvertFrom(ctx context.Context, obj apis.Convertible) error {
switch source := obj.(type) {
case *v1beta2.EventType:
sink.ObjectMeta = source.ObjectMeta
sink.Status = EventTypeStatus{
Status: source.Status.Status,
}

sink.Spec = EventTypeSpec{
Type: source.Spec.Type,
Source: source.Spec.Source,
Schema: source.Spec.Schema,
SchemaData: source.Spec.SchemaData,
Broker: source.Spec.Broker,
Description: source.Spec.Description,
}

return nil
default:
return apis.ConvertFromViaProxy(ctx, source, &v1beta2.EventType{}, sink)
}
}