Repository navigation
Remove deleted resources from gateways that have not re-registered - #4466
HiranyaKavishani wants to merge 1 commit into
Conversation
The gateway registry is held only in memory. After an operator restart it is empty until each gateway reconciles again, and RestApi and generic resource deletion found their gateways only through the registry. A resource deleted in that window lost its finalizer while it stayed deployed on the gateway. Record every gateway a RestApi or generic resource is sent to in the gateway.api-platform.wso2.com/deployed-to-gateways annotation, written before the deploy call. On deletion, clean up the recorded gateways plus the registered gateways that select the resource: - registered: delete as before; errors now keep the finalizer (RestApi used to drop them) and a 404 counts as deleted - not registered, but the APIGateway, or a Gateway of a managed class, still exists: keep the finalizer and requeue until it registers - gateway object gone or being deleted: nothing left to remove The record is not forwarded to the gateway in payload annotations. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Warning Review limit reachedThis review ran on the open-source allowance, not this organization's plan, because the pull request author doesn't have an assigned seat. Waiting won't change this — ask an organization admin to assign them a seat, or add seats in Billing if every seat is already assigned, then retry. Next included review available in 46 minutes. View limit details
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #4466 +/- ##
==========================================
- Coverage 68.10% 67.40% -0.71%
==========================================
Files 1361 1346 -15
Lines 210436 219052 +8616
Branches 6750 6750
==========================================
+ Hits 143326 147645 +4319
- Misses 58010 62170 +4160
- Partials 9100 9237 +137
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Purpose
The gateway operator keeps its gateway registry (
internal/registry/gateway_registry.go) only in memory. After an operator restart the registry is empty until each gateway reconciles and registers again. RestApi deletion (cleanupAPIDeployments) and generic-resource deletion (cleanupAllGateways) found their gateways only throughregistry.FindMatchingGateways, so a resource deleted in that window found no gateway, its finalizer was removed, and the API or resource stayed deployed on the gateway.The gap was raised in review on #4446 and is fixed here separately so that PR stays focused.
Goals
Approach
gateway.api-platform.wso2.com/deployed-to-gatewaysannotation: a JSON object mappingnamespace/nameto the gateway kind (APIGatewayorGateway). This follows the deployed-gateways annotation HTTPRoute already uses. Writing it before the deploy call means a deploy that reaches the gateway is never left unrecorded. The patch uses an optimistic lock so a stale cache cannot drop an earlier entry.requeueGatewayNotRegistered) until it registers.RestApiReconcilernow calls the gateway REST API through the samerestAPIClientinterface as the HTTPRoute reconciler, so tests can stand in a fake.Trade-off: deletion of a resource whose gateway object exists but never registers again (for example a gateway whose runtime stays broken) waits until the gateway registers or is deleted, the same as HTTPRoute deletion does today.
User stories
As a platform operator, when I delete an API or a management resource while the operator is restarting, it is removed from the gateway instead of staying live without a backing CR.
Documentation
N/A. Internal controller behaviour; no user-facing configuration changes.
Automation tests
Security checks
Database changes
Samples
N/A
Related PRs
cleanupAPIDeploymentsinrestapi_controller.go); expect a small conflict with whichever merges first.Test environment
Go unit tests on macOS (darwin/arm64),
GOWORK=off.🤖 Generated with Claude Code