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

[release-v1.11] Cherry pick eventtype autocreate fixes #7201

Merged
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
18 changes: 16 additions & 2 deletions cmd/broker/ingress/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,12 +131,26 @@ func main() {
logger.Fatal("Error setting up trace publishing", zap.Error(err))
}

featureStore := feature.NewStore(logging.FromContext(ctx).Named("feature-config-store"))
var featureStore *feature.Store
var handler *ingress.Handler

featureStore = feature.NewStore(logging.FromContext(ctx).Named("feature-config-store"), func(name string, value interface{}) {
featureFlags := value.(feature.Flags)
if featureFlags.IsEnabled(feature.EvenTypeAutoCreate) && featureStore != nil && handler != nil {
autoCreate := &eventtype.EventTypeAutoHandler{
EventTypeLister: eventtypeinformer.Get(ctx).Lister(),
EventingClient: eventingclient.Get(ctx).EventingV1beta2(),
FeatureStore: featureStore,
Logger: logger,
}
handler.EvenTypeHandler = autoCreate
}
})
featureStore.WatchConfigs(configMapWatcher)

reporter := ingress.NewStatsReporter(env.ContainerName, kmeta.ChildName(env.PodName, uuid.New().String()))

handler, err := ingress.NewHandler(logger, reporter, broker.TTLDefaulter(logger, int32(env.MaxTTL)), brokerInformer)
handler, err = ingress.NewHandler(logger, reporter, broker.TTLDefaulter(logger, int32(env.MaxTTL)), brokerInformer)
if err != nil {
logger.Fatal("Error creating Handler", zap.Error(err))
}
Expand Down
9 changes: 8 additions & 1 deletion pkg/broker/ingress/ingress_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,13 +249,20 @@ func (h *Handler) ServeHTTP(writer http.ResponseWriter, request *http.Request) {
}

func toKReference(broker *eventingv1.Broker) *duckv1.KReference {
return &duckv1.KReference{
kref := &duckv1.KReference{
Kind: broker.Kind,
Namespace: broker.Namespace,
Name: broker.Name,
APIVersion: broker.APIVersion,
Address: broker.Status.Address.Name,
}
if kref.Kind == "" {
kref.Kind = "Broker"
}
if kref.APIVersion == "" {
kref.APIVersion = "eventing.knative.dev/v1"
}
return kref
}

func (h *Handler) receive(ctx context.Context, headers http.Header, event *cloudevents.Event, brokerNamespace, brokerName string) (int, time.Duration) {
Expand Down
15 changes: 10 additions & 5 deletions pkg/reconciler/inmemorychannel/dispatcher/inmemorychannel.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,17 +93,22 @@ func (r *Reconciler) reconcile(ctx context.Context, imc *v1.InMemoryChannel) rec
return err
}
var eventTypeAutoHandler *eventtype.EventTypeAutoHandler
var channelReference *duckv1.KReference
var channelRef *duckv1.KReference
var UID *types.UID
if r.featureStore.IsEnabled(feature.EvenTypeAutoCreate) {
if ownerReferences := imc.GetOwnerReferences(); r.featureStore.IsEnabled(feature.EvenTypeAutoCreate) &&
(len(ownerReferences) == 0 ||
ownerReferences[0].Kind != "Broker") {
logging.FromContext(ctx).Info("EventType autocreate is enabled, creating handler")
eventTypeAutoHandler = &eventtype.EventTypeAutoHandler{
EventTypeLister: r.eventTypeLister,
EventingClient: r.eventingClient,
FeatureStore: r.featureStore,
Logger: logging.FromContext(ctx).Desugar(),
}
channelReference = toKReference(imc)

channelRef = toKReference(imc)
UID = &imc.UID

}

// First grab the host based MultiChannelFanoutMessage httpHandler
Expand All @@ -116,7 +121,7 @@ func (r *Reconciler) reconcile(ctx context.Context, imc *v1.InMemoryChannel) rec
config.FanoutConfig,
r.reporter,
eventTypeAutoHandler,
channelReference,
channelRef,
UID,
)
if err != nil {
Expand Down Expand Up @@ -145,7 +150,7 @@ func (r *Reconciler) reconcile(ctx context.Context, imc *v1.InMemoryChannel) rec
config.FanoutConfig,
r.reporter,
eventTypeAutoHandler,
channelReference,
channelRef,
UID,
channel.ResolveMessageChannelFromPath(channel.ParseChannelFromPath),
)
Expand Down