From 63756e0fc30c94f9f39a8d0968bb168c299e5c17 Mon Sep 17 00:00:00 2001 From: Shubham Chauhan Date: Mon, 21 Nov 2022 02:42:56 +0530 Subject: [PATCH] update subscriber for gapi objs Signed-off-by: Shubham Chauhan --- internal/gatewayapi/runner/runner.go | 30 ++++++++-------------- internal/provider/kubernetes/controller.go | 1 - 2 files changed, 10 insertions(+), 21 deletions(-) diff --git a/internal/gatewayapi/runner/runner.go b/internal/gatewayapi/runner/runner.go index 0f902c3aeca9..290192779b90 100644 --- a/internal/gatewayapi/runner/runner.go +++ b/internal/gatewayapi/runner/runner.go @@ -45,30 +45,20 @@ func (r *Runner) Start(ctx context.Context) error { } func (r *Runner) subscribeAndTranslate(ctx context.Context) { - // Subscribe to resources - resourcesCh := r.ProviderResources.GatewayAPIResources.Subscribe(ctx) + message.HandleSubscription(r.ProviderResources.GatewayAPIResources.Subscribe(ctx), + func(update message.Update[string, *gatewayapi.Resources]) { + val := update.Value - for ctx.Err() == nil { - var in *gatewayapi.Resources - // Receive subscribed resource notifications - - <-resourcesCh - r.Logger.Info("received a notification") - - // Load all resources required for translation - in = r.ProviderResources.GetResources() + if update.Delete || val == nil { + return + } - switch { - case in == nil: - // Envoy Gateway startup. - continue - default: // Translate and publish IRs. t := &gatewayapi.Translator{ - GatewayClassName: v1beta1.ObjectName(r.ProviderResources.GetResourcesKey()), + GatewayClassName: v1beta1.ObjectName(update.Key), } // Translate to IR - result := t.Translate(in) + result := t.Translate(val) yamlXdsIR, _ := yaml.Marshal(&result.XdsIR) r.Logger.WithValues("output", "xds-ir").Info(string(yamlXdsIR)) @@ -121,8 +111,8 @@ func (r *Runner) subscribeAndTranslate(ctx context.Context) { key := utils.NamespacedName(tlsRoute) r.ProviderResources.TLSRouteStatuses.Store(key, tlsRoute) } - } - } + }, + ) r.Logger.Info("shutting down") } diff --git a/internal/provider/kubernetes/controller.go b/internal/provider/kubernetes/controller.go index e640b9b50621..c90e43fb85f1 100644 --- a/internal/provider/kubernetes/controller.go +++ b/internal/provider/kubernetes/controller.go @@ -157,7 +157,6 @@ func (r *gatewayAPIReconciler) Reconcile(ctx context.Context, request reconcile. continue } - r.log.Info("HEYO3 ADDING MATCH") cc.addMatch(&gatewayClasses.Items[i]) } }