Skip to content

Commit

Permalink
bug: fix deletion of all gatewayclasses (#2659)
Browse files Browse the repository at this point in the history
fix deletion of all gatewayclasses

* when no gatewayclasses exist, delete the key from the provider
  resources and clean all up IRs in the gateway-api layer
* also fixed the finalizer logic

Signed-off-by: Arko Dasgupta <arko@tetrate.io>
  • Loading branch information
arkodg authored Feb 20, 2024
1 parent cf46fbe commit 579b3b4
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 10 deletions.
11 changes: 11 additions & 0 deletions internal/gatewayapi/runner/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down Expand Up @@ -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.
Expand Down
18 changes: 8 additions & 10 deletions internal/provider/kubernetes/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand All @@ -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
}
Expand Down Expand Up @@ -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
}
}
}
Expand Down

0 comments on commit 579b3b4

Please sign in to comment.