diff --git a/internal/gatewayapi/runner/runner.go b/internal/gatewayapi/runner/runner.go index a40cdaedef5..ac2ec3140a0 100644 --- a/internal/gatewayapi/runner/runner.go +++ b/internal/gatewayapi/runner/runner.go @@ -52,7 +52,10 @@ func (r *Runner) subscribeAndTranslate(ctx context.Context) { func(update message.Update[string, *gatewayapi.GatewayClassResources], errChan chan error) { r.Logger.Info("received an update") val := update.Value + // There is only 1 key which is the controller name + // so when a delete is triggered, delete all IR keys if update.Delete || val == nil { + r.deleteAllIRKeys() return } @@ -165,6 +168,14 @@ func (r *Runner) subscribeAndTranslate(ctx context.Context) { r.Logger.Info("shutting down") } +// deleteAllIRKeys deletes all XdsIR and InfraIR +func (r *Runner) deleteAllIRKeys() { + for key := range r.InfraIR.LoadAll() { + r.InfraIR.Delete(key) + r.XdsIR.Delete(key) + } +} + // getIRKeysToDelete returns the list of IR keys to delete // based on the difference between the current keys and the // new keys parameters passed to the function. diff --git a/internal/provider/kubernetes/controller.go b/internal/provider/kubernetes/controller.go index 8d53b7f071c..af42d4c178b 100644 --- a/internal/provider/kubernetes/controller.go +++ b/internal/provider/kubernetes/controller.go @@ -154,9 +154,6 @@ func (r *gatewayAPIReconciler) Reconcile(ctx context.Context, _ reconcile.Reques !slice.ContainsString(gwClass.Finalizers, gatewayClassFinalizer) { r.log.Info("gatewayclass marked for deletion") cc.removeMatch(&gwClass) - - // Delete the gatewayclass from the watchable map. - r.resources.GatewayAPIResources.Delete(gwClass.Name) continue } @@ -167,6 +164,7 @@ func (r *gatewayAPIReconciler) Reconcile(ctx context.Context, _ reconcile.Reques // The gatewayclass was already deleted/finalized and there are stale queue entries. acceptedGCs := cc.matchedClasses if acceptedGCs == nil { + r.resources.GatewayAPIResources.Delete(string(r.classController)) r.log.Info("no accepted gatewayclass") return reconcile.Result{}, nil } @@ -352,13 +350,13 @@ func (r *gatewayAPIReconciler) Reconcile(ctx context.Context, _ reconcile.Reques r.log.Error(err, fmt.Sprintf("failed to remove finalizer from gatewayclass %s", acceptedGC.Name)) return reconcile.Result{}, err - } else { - // finalize the accepted GatewayClass. - if err := r.addFinalizer(ctx, acceptedGC); err != nil { - r.log.Error(err, fmt.Sprintf("failed adding finalizer to gatewayclass %s", - acceptedGC.Name)) - return reconcile.Result{}, err - } + } + } else { + // finalize the accepted GatewayClass. + if err := r.addFinalizer(ctx, acceptedGC); err != nil { + r.log.Error(err, fmt.Sprintf("failed adding finalizer to gatewayclass %s", + acceptedGC.Name)) + return reconcile.Result{}, err } } }