Skip to content

Commit

Permalink
Add conversion webhook
Browse files Browse the repository at this point in the history
Signed-off-by: Pierangelo Di Pilato <[email protected]>
  • Loading branch information
pierDipi committed Oct 9, 2024
1 parent fdf07ee commit b110c48
Show file tree
Hide file tree
Showing 18 changed files with 1,467 additions and 0 deletions.
31 changes: 31 additions & 0 deletions control-plane/cmd/webhook-kafka/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,14 @@ import (
"knative.dev/pkg/webhook"
"knative.dev/pkg/webhook/certificates"
"knative.dev/pkg/webhook/resourcesemantics"
"knative.dev/pkg/webhook/resourcesemantics/conversion"
"knative.dev/pkg/webhook/resourcesemantics/defaulting"
"knative.dev/pkg/webhook/resourcesemantics/validation"

eventingcorev1 "knative.dev/eventing/pkg/apis/eventing/v1"
"knative.dev/eventing/pkg/apis/feature"

sourcesv1 "knative.dev/eventing-kafka-broker/control-plane/pkg/apis/sources/v1"
sourcesv1beta1 "knative.dev/eventing-kafka-broker/control-plane/pkg/apis/sources/v1beta1"

messagingv1beta1 "knative.dev/eventing-kafka-broker/control-plane/pkg/apis/messaging/v1beta1"
Expand All @@ -53,6 +55,7 @@ const (
var types = map[schema.GroupVersionKind]resourcesemantics.GenericCRD{
eventingv1alpha1.SchemeGroupVersion.WithKind("KafkaSink"): &eventingv1alpha1.KafkaSink{},
sourcesv1beta1.SchemeGroupVersion.WithKind("KafkaSource"): &sourcesv1beta1.KafkaSource{},
sourcesv1.SchemeGroupVersion.WithKind("KafkaSource"): &sourcesv1.KafkaSource{},
messagingv1beta1.SchemeGroupVersion.WithKind("KafkaChannel"): &messagingv1beta1.KafkaChannel{},
eventingcorev1.SchemeGroupVersion.WithKind("Broker"): &eventingv1.BrokerStub{},
kafkainternals.SchemeGroupVersion.WithKind("ConsumerGroup"): &kafkainternals.ConsumerGroup{},
Expand Down Expand Up @@ -144,6 +147,33 @@ func NewValidationAdmissionController(ctx context.Context, cmw configmap.Watcher
)
}

func NewConversionController(ctx context.Context, _ configmap.Watcher) *controller.Impl {

ctxFunc := func(ctx context.Context) context.Context {
return ctx
}

return conversion.NewConversionController(
ctx,

// The path on which to serve the webhook
"/resource-conversion",

map[schema.GroupKind]conversion.GroupKindConversion{
sourcesv1.Kind("KafkaSource"): {
DefinitionName: "kafkasources.sources.knative.dev",
HubVersion: sourcesv1beta1.SchemeGroupVersion.Version,
Zygotes: map[string]conversion.ConvertibleObject{
sourcesv1beta1.SchemeGroupVersion.Version: &sourcesv1beta1.KafkaSource{},
sourcesv1.SchemeGroupVersion.Version: &sourcesv1.KafkaSource{},
},
},
},
// A function that infuses the context passed to ConvertTo/ConvertFrom/SetDefaults with custom metadata.
ctxFunc,
)
}

func main() {

// Set up a signal context with our webhook options
Expand All @@ -159,5 +189,6 @@ func main() {
NewDefaultingAdmissionController,
NewPodDefaultingAdmissionController,
NewValidationAdmissionController,
NewConversionController,
)
}

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

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

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

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

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

Loading

0 comments on commit b110c48

Please sign in to comment.