Skip to content
This repository was archived by the owner on Nov 28, 2022. It is now read-only.
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
144 changes: 138 additions & 6 deletions cmd/webhook/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,32 +41,59 @@ 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"
"knative.dev/eventing/pkg/apis/flows"
flowsv1 "knative.dev/eventing/pkg/apis/flows/v1"
flowsv1beta1 "knative.dev/eventing/pkg/apis/flows/v1beta1"
"knative.dev/eventing/pkg/apis/messaging"
channeldefaultconfig "knative.dev/eventing/pkg/apis/messaging/config"
messagingv1 "knative.dev/eventing/pkg/apis/messaging/v1"
messagingv1beta1 "knative.dev/eventing/pkg/apis/messaging/v1beta1"
"knative.dev/eventing/pkg/apis/sources"
pingdefaultconfig "knative.dev/eventing/pkg/apis/sources/config"
sourcesv1 "knative.dev/eventing/pkg/apis/sources/v1"
sourcesv1alpha1 "knative.dev/eventing/pkg/apis/sources/v1alpha1"
sourcesv1alpha2 "knative.dev/eventing/pkg/apis/sources/v1alpha2"
sourcesv1beta1 "knative.dev/eventing/pkg/apis/sources/v1beta1"
sourcesv1beta2 "knative.dev/eventing/pkg/apis/sources/v1beta2"
"knative.dev/eventing/pkg/reconciler/sinkbinding"
)

var ourTypes = map[schema.GroupVersionKind]resourcesemantics.GenericCRD{
// For group eventing.knative.dev.
// v1beta1
eventingv1beta1.SchemeGroupVersion.WithKind("Broker"): &eventingv1beta1.Broker{},
eventingv1beta1.SchemeGroupVersion.WithKind("Trigger"): &eventingv1beta1.Trigger{},
eventingv1beta1.SchemeGroupVersion.WithKind("EventType"): &eventingv1beta1.EventType{},
// v1
eventingv1.SchemeGroupVersion.WithKind("Broker"): &eventingv1.Broker{},
eventingv1.SchemeGroupVersion.WithKind("Trigger"): &eventingv1.Trigger{},

// For group messaging.knative.dev.
// v1beta1
messagingv1beta1.SchemeGroupVersion.WithKind("InMemoryChannel"): &messagingv1beta1.InMemoryChannel{},
messagingv1beta1.SchemeGroupVersion.WithKind("Channel"): &messagingv1beta1.Channel{},
messagingv1beta1.SchemeGroupVersion.WithKind("Subscription"): &messagingv1beta1.Subscription{},
// v1
messagingv1.SchemeGroupVersion.WithKind("Channel"): &messagingv1.Channel{},
messagingv1.SchemeGroupVersion.WithKind("Subscription"): &messagingv1.Subscription{},

// For group sources.knative.dev.
// v1alpha1
sourcesv1alpha1.SchemeGroupVersion.WithKind("ApiServerSource"): &sourcesv1alpha1.ApiServerSource{},
sourcesv1alpha1.SchemeGroupVersion.WithKind("SinkBinding"): &sourcesv1alpha1.SinkBinding{},
// v1alpha2
sourcesv1alpha2.SchemeGroupVersion.WithKind("ApiServerSource"): &sourcesv1alpha2.ApiServerSource{},
sourcesv1alpha2.SchemeGroupVersion.WithKind("PingSource"): &sourcesv1alpha2.PingSource{},
sourcesv1alpha2.SchemeGroupVersion.WithKind("SinkBinding"): &sourcesv1alpha2.SinkBinding{},
sourcesv1alpha2.SchemeGroupVersion.WithKind("ContainerSource"): &sourcesv1alpha2.ContainerSource{},
// v1beta1
sourcesv1beta1.SchemeGroupVersion.WithKind("ApiServerSource"): &sourcesv1beta1.ApiServerSource{},
sourcesv1beta1.SchemeGroupVersion.WithKind("PingSource"): &sourcesv1beta1.PingSource{},
sourcesv1beta1.SchemeGroupVersion.WithKind("SinkBinding"): &sourcesv1beta1.SinkBinding{},
sourcesv1beta1.SchemeGroupVersion.WithKind("ContainerSource"): &sourcesv1beta1.ContainerSource{},
// v1beta2
sourcesv1beta2.SchemeGroupVersion.WithKind("PingSource"): &sourcesv1beta2.PingSource{},
// v1
Expand All @@ -76,6 +103,9 @@ var ourTypes = map[schema.GroupVersionKind]resourcesemantics.GenericCRD{
sourcesv1.SchemeGroupVersion.WithKind("ContainerSource"): &sourcesv1.ContainerSource{},

// For group flows.knative.dev
// v1beta1
flowsv1beta1.SchemeGroupVersion.WithKind("Parallel"): &flowsv1beta1.Parallel{},
flowsv1beta1.SchemeGroupVersion.WithKind("Sequence"): &flowsv1beta1.Sequence{},
// v1
flowsv1.SchemeGroupVersion.WithKind("Parallel"): &flowsv1.Parallel{},
flowsv1.SchemeGroupVersion.WithKind("Sequence"): &flowsv1.Sequence{},
Expand Down Expand Up @@ -207,8 +237,17 @@ func NewConversionController(ctx context.Context, cmw configmap.Watcher) *contro
}

var (
sourcesv1beta2_ = sourcesv1beta2.SchemeGroupVersion.Version
sourcesv1_ = sourcesv1.SchemeGroupVersion.Version
eventingv1beta1_ = eventingv1beta1.SchemeGroupVersion.Version
eventingv1_ = eventingv1.SchemeGroupVersion.Version
messagingv1beta1_ = messagingv1beta1.SchemeGroupVersion.Version
messagingv1_ = messagingv1.SchemeGroupVersion.Version
flowsv1beta1_ = flowsv1beta1.SchemeGroupVersion.Version
flowsv1_ = flowsv1.SchemeGroupVersion.Version
sourcesv1alpha1_ = sourcesv1alpha1.SchemeGroupVersion.Version
sourcesv1alpha2_ = sourcesv1alpha2.SchemeGroupVersion.Version
sourcesv1beta1_ = sourcesv1beta1.SchemeGroupVersion.Version
sourcesv1beta2_ = sourcesv1beta2.SchemeGroupVersion.Version
sourcesv1_ = sourcesv1.SchemeGroupVersion.Version
)

return conversion.NewConversionController(ctx,
Expand All @@ -217,13 +256,106 @@ 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{
// Eventing
eventingv1.Kind("Trigger"): {
DefinitionName: eventing.TriggersResource.String(),
HubVersion: eventingv1beta1_,
Zygotes: map[string]conversion.ConvertibleObject{
eventingv1beta1_: &eventingv1beta1.Trigger{},
eventingv1_: &eventingv1.Trigger{},
},
},
eventingv1.Kind("Broker"): {
DefinitionName: eventing.BrokersResource.String(),
HubVersion: eventingv1beta1_,
Zygotes: map[string]conversion.ConvertibleObject{
eventingv1beta1_: &eventingv1beta1.Broker{},
eventingv1_: &eventingv1.Broker{},
},
},

// Messaging
messagingv1.Kind("Channel"): {
DefinitionName: messaging.ChannelsResource.String(),
HubVersion: messagingv1beta1_,
Zygotes: map[string]conversion.ConvertibleObject{
messagingv1beta1_: &messagingv1beta1.Channel{},
messagingv1_: &messagingv1.Channel{},
},
},
messagingv1.Kind("InMemoryChannel"): {
DefinitionName: messaging.InMemoryChannelsResource.String(),
HubVersion: messagingv1beta1_,
Zygotes: map[string]conversion.ConvertibleObject{
messagingv1beta1_: &messagingv1beta1.InMemoryChannel{},
messagingv1_: &messagingv1.InMemoryChannel{},
},
},
messagingv1.Kind("Subscription"): {
DefinitionName: messaging.SubscriptionsResource.String(),
HubVersion: messagingv1beta1_,
Zygotes: map[string]conversion.ConvertibleObject{
messagingv1beta1_: &messagingv1beta1.Subscription{},
messagingv1_: &messagingv1.Subscription{},
},
},

// flows
flowsv1.Kind("Sequence"): {
DefinitionName: flows.SequenceResource.String(),
HubVersion: flowsv1beta1_,
Zygotes: map[string]conversion.ConvertibleObject{
flowsv1beta1_: &flowsv1beta1.Sequence{},
flowsv1_: &flowsv1.Sequence{},
},
},
flowsv1.Kind("Parallel"): {
DefinitionName: flows.ParallelResource.String(),
HubVersion: flowsv1beta1_,
Zygotes: map[string]conversion.ConvertibleObject{
flowsv1beta1_: &flowsv1beta1.Parallel{},
flowsv1_: &flowsv1.Parallel{},
},
},

// Sources
sourcesv1.Kind("PingSource"): {
sourcesv1.Kind("ApiServerSource"): {
DefinitionName: sources.ApiServerSourceResource.String(),
HubVersion: sourcesv1alpha1_,
Zygotes: map[string]conversion.ConvertibleObject{
sourcesv1alpha1_: &sourcesv1alpha1.ApiServerSource{},
sourcesv1alpha2_: &sourcesv1alpha2.ApiServerSource{},
sourcesv1beta1_: &sourcesv1beta1.ApiServerSource{},
sourcesv1_: &sourcesv1.ApiServerSource{},
},
},
sourcesv1beta1.Kind("PingSource"): {
DefinitionName: sources.PingSourceResource.String(),
HubVersion: sourcesv1beta2_,
HubVersion: sourcesv1alpha2_,
Zygotes: map[string]conversion.ConvertibleObject{
sourcesv1alpha2_: &sourcesv1alpha2.PingSource{},
sourcesv1beta1_: &sourcesv1beta1.PingSource{},
sourcesv1beta2_: &sourcesv1beta2.PingSource{},
sourcesv1_: &sourcesv1.PingSource{},
},
},
sourcesv1.Kind("SinkBinding"): {
DefinitionName: sources.SinkBindingResource.String(),
HubVersion: sourcesv1alpha1_,
Zygotes: map[string]conversion.ConvertibleObject{
sourcesv1alpha1_: &sourcesv1alpha1.SinkBinding{},
sourcesv1alpha2_: &sourcesv1alpha2.SinkBinding{},
sourcesv1beta1_: &sourcesv1beta1.SinkBinding{},
sourcesv1_: &sourcesv1.SinkBinding{},
},
},
sourcesv1.Kind("ContainerSource"): {
DefinitionName: sources.ContainerSourceResource.String(),
HubVersion: sourcesv1alpha2_,
Zygotes: map[string]conversion.ConvertibleObject{
sourcesv1beta2_: &sourcesv1beta2.PingSource{},
sourcesv1_: &sourcesv1.PingSource{},
sourcesv1alpha2_: &sourcesv1alpha2.ContainerSource{},
sourcesv1beta1_: &sourcesv1beta1.ContainerSource{},
sourcesv1_: &sourcesv1.ContainerSource{},
},
},
},
Expand Down
14 changes: 11 additions & 3 deletions config/channels/in-memory-channel/resources/in-memory-channel.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,14 @@ metadata:
spec:
group: messaging.knative.dev
versions:
- name: v1
- &version
name: v1beta1
served: true
storage: true
storage: false
subresources:
status: {}
schema:
openAPIV3Schema:
openAPIV3Schema: &openAPIV3Schema
description: 'InMemoryChannel is a resource representing an in memory channel'
type: object
properties:
Expand Down Expand Up @@ -222,6 +223,13 @@ spec:
- name: Reason
type: string
jsonPath: ".status.conditions[?(@.type==\"Ready\")].reason"
- << : *version
name: v1
served: true
storage: true
schema:
openAPIV3Schema:
<<: *openAPIV3Schema
names:
kind: InMemoryChannel
plural: inmemorychannels
Expand Down
Loading