Skip to content
Closed
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
40 changes: 40 additions & 0 deletions cmd/webhook/experimental.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// +build js_trigger_filter

package main

import (
"k8s.io/apimachinery/pkg/runtime/schema"
"knative.dev/pkg/webhook/resourcesemantics"
"knative.dev/pkg/webhook/resourcesemantics/conversion"

"knative.dev/eventing/pkg/apis/eventing"
eventingv1 "knative.dev/eventing/pkg/apis/eventing/v1"
eventingv1beta1 "knative.dev/eventing/pkg/apis/eventing/v1beta1"
eventingv1experimental "knative.dev/eventing/pkg/apis/eventing/v1experimental"
)

func AdditionalCRD() map[schema.GroupVersionKind]resourcesemantics.GenericCRD {
return map[schema.GroupVersionKind]resourcesemantics.GenericCRD{
eventingv1experimental.SchemeGroupVersion.WithKind("Trigger"): &eventingv1experimental.Trigger{},
}
}

func AdditionalConversions() map[schema.GroupKind]conversion.GroupKindConversion {
var (
eventingv1beta1_ = eventingv1beta1.SchemeGroupVersion.Version
eventingv1_ = eventingv1.SchemeGroupVersion.Version
eventingv1experimental_ = eventingv1experimental.SchemeGroupVersion.Version
)

return map[schema.GroupKind]conversion.GroupKindConversion{
eventingv1.Kind("Trigger"): {
DefinitionName: eventing.TriggersResource.String(),
HubVersion: eventingv1experimental_,
Zygotes: map[string]conversion.ConvertibleObject{
eventingv1beta1_: &eventingv1beta1.Trigger{},
eventingv1_: &eventingv1.Trigger{},
eventingv1experimental_: &eventingv1experimental.Trigger{},
},
},
}
}
196 changes: 104 additions & 92 deletions cmd/webhook/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,12 @@ var ourTypes = map[schema.GroupVersionKind]resourcesemantics.GenericCRD{

var callbacks = map[schema.GroupVersionKind]validation.Callback{}

func init() {
for k, v := range AdditionalCRD() {
ourTypes[k] = v
}
}

func NewDefaultingAdmissionController(ctx context.Context, cmw configmap.Watcher) *controller.Impl {
// Decorate contexts with the current state of the config.
store := defaultconfig.NewStore(logging.FromContext(ctx).Named("config-store"))
Expand Down Expand Up @@ -248,113 +254,119 @@ func NewConversionController(ctx context.Context, cmw configmap.Watcher) *contro
sourcesv1_ = sourcesv1.SchemeGroupVersion.Version
)

return conversion.NewConversionController(ctx,
// The path on which to serve the webhook
"/resource-conversion",

// 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{},
},
conversions := 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{},
},
},
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{},
},
// 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("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{},
},
},
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{},
},
// 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{},
},
},
flowsv1.Kind("Parallel"): {
DefinitionName: flows.ParallelResource.String(),
HubVersion: flowsv1beta1_,
Zygotes: map[string]conversion.ConvertibleObject{
flowsv1beta1_: &flowsv1beta1.Parallel{},
flowsv1_: &flowsv1.Parallel{},
},
},

// Sources
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{},
},
// Sources
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: sourcesv1alpha2_,
Zygotes: map[string]conversion.ConvertibleObject{
sourcesv1alpha2_: &sourcesv1alpha2.PingSource{},
sourcesv1beta1_: &sourcesv1beta1.PingSource{},
},
},
sourcesv1beta1.Kind("PingSource"): {
DefinitionName: sources.PingSourceResource.String(),
HubVersion: sourcesv1alpha2_,
Zygotes: map[string]conversion.ConvertibleObject{
sourcesv1alpha2_: &sourcesv1alpha2.PingSource{},
sourcesv1beta1_: &sourcesv1beta1.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("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{
sourcesv1alpha2_: &sourcesv1alpha2.ContainerSource{},
sourcesv1beta1_: &sourcesv1beta1.ContainerSource{},
sourcesv1_: &sourcesv1.ContainerSource{},
},
},
sourcesv1.Kind("ContainerSource"): {
DefinitionName: sources.ContainerSourceResource.String(),
HubVersion: sourcesv1alpha2_,
Zygotes: map[string]conversion.ConvertibleObject{
sourcesv1alpha2_: &sourcesv1alpha2.ContainerSource{},
sourcesv1beta1_: &sourcesv1beta1.ContainerSource{},
sourcesv1_: &sourcesv1.ContainerSource{},
},
},
}

for k, v := range AdditionalConversions() {
conversions[k] = v
}

return conversion.NewConversionController(ctx,
// The path on which to serve the webhook
"/resource-conversion",

// Specify the types of custom resource definitions that should be converted
conversions,

// A function that infuses the context passed to ConvertTo/ConvertFrom/SetDefaults with custom metadata.
ctxFunc,
Expand Down
17 changes: 17 additions & 0 deletions cmd/webhook/stable.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// +build !js_trigger_filter

package main

import (
"k8s.io/apimachinery/pkg/runtime/schema"
"knative.dev/pkg/webhook/resourcesemantics"
"knative.dev/pkg/webhook/resourcesemantics/conversion"
)

func AdditionalCRD() map[schema.GroupVersionKind]resourcesemantics.GenericCRD {
return map[schema.GroupVersionKind]resourcesemantics.GenericCRD{}
}

func AdditionalConversions() map[schema.GroupKind]conversion.GroupKindConversion {
return map[schema.GroupKind]conversion.GroupKindConversion{}
}
67 changes: 66 additions & 1 deletion config/core/resources/trigger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,71 @@ spec:
description: 'Status represents the current state of the Trigger. This data may be out of date.'
type: object
x-kubernetes-preserve-unknown-fields: true
- <<: *version
name: v1experimental
served: true
storage: false
schema:
openAPIV3Schema:
type: object
description: 'Trigger represents a request to have events delivered to a subscriber from a Broker''s event pool.'
properties:
spec:
description: 'Spec defines the desired state of the Trigger.'
required:
- subscriber
- broker
type: object
properties:
broker:
type: string
description: 'Broker that this trigger receives events from.'
filter:
type: object
description: 'Filter is the filter to apply against all events from
the Broker. Only events that pass this filter will be sent to
the Subscriber. If not specified, will default to allowing all
events.'
properties:
attributes:
type: object
description: 'Map of CloudEvents attributes used for filtering events. If not specified, will default to all events'
additionalProperties:
type: string
expression:
type: string
description: 'JS expression'
subscriber:
type: object
description: 'the destination that should receive events.'
properties:
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
namespace:
type: string
minLength: 1
name:
type: string
minLength: 1
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.'
status:
description: 'Status represents the current state of the Trigger. This data may be out of date.'
type: object
x-kubernetes-preserve-unknown-fields: true
names:
kind: Trigger
plural: triggers
Expand All @@ -168,7 +233,7 @@ spec:
conversion:
strategy: Webhook
webhook:
conversionReviewVersions: ["v1", "v1beta1"]
conversionReviewVersions: ["v1experimental", "v1", "v1beta1"]
clientConfig:
service:
name: eventing-webhook
Expand Down
13 changes: 13 additions & 0 deletions experimental_trigger.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
apiVersion: eventing.knative.dev/v1experimental
kind: Trigger
metadata:
name: my-service-trigger
spec:
broker: default
filter:
expression: "helloworld"
subscriber:
ref:
apiVersion: serving.knative.dev/v1
kind: Service
name: my-service
6 changes: 6 additions & 0 deletions hack/update-codegen.sh
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@ ${CODEGEN_PKG}/generate-groups.sh "deepcopy,client,informer,lister" \
"eventing:v1beta1 eventing:v1 messaging:v1beta1 messaging:v1 flows:v1beta1 flows:v1 sources:v1alpha1 sources:v1alpha2 sources:v1beta1 sources:v1 configs:v1alpha1" \
--go-header-file ${REPO_ROOT_DIR}/hack/boilerplate/boilerplate.go.txt

${CODEGEN_PKG}/generate-groups.sh "deepcopy" \
knative.dev/eventing/pkg/client knative.dev/eventing/pkg/apis \
"eventing:v1experimental" \
--go-header-file ${REPO_ROOT_DIR}/hack/boilerplate/boilerplate.go.txt \
--build-tag js_trigger_filter

# Deep copy config
${GOPATH}/bin/deepcopy-gen \
-O zz_generated.deepcopy \
Expand Down
Loading