Fix TwingateConnector operator stuck in update loop
Problem
When a TwingateConnector object gets properly synced to Twingate and receives an id value, if someone deletes it from the admin side, the operator gets stuck in a loop trying every minute to sync the connector. This happens because the update operation fails with:
"connectorUpdate mutation failed - Field 'id' Connector with id '<id>' does not exist."
Solution
I've implemented the following changes to address this issue:
-
Modified the
connector_updatemethod inTwingateConnectorAPIto:- Handle "does not exist" errors in GraphQL mutations
- Return
Noneinstead of raising an exception when a connector is not found - Log a warning message to indicate the connector was likely deleted
-
Updated the
twingate_connector_updatehandler to:- Detect when an update operation returns
None(connector doesn't exist) - Reset the connector ID and recreate the connector with the same configuration
- Generate new tokens for the recreated connector
- Create a new secret containing the tokens
- Create/replace the deployment for the connector
- Return success with a message indicating the connector was recreated
- Detect when an update operation returns
-
Added a test case that verifies:
- The handler correctly detects when a connector doesn't exist
- It properly recreates the connector
- It sets up all necessary resources
This provides automatic recovery when a connector is deleted from the Twingate admin side but still exists in Kubernetes, preventing the operator from getting stuck in an update loop.
Fixes #596.
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.
Pull Request Test Coverage Report for Build 15131082693
Details
- 0 of 0 changed or added relevant lines in 0 files are covered.
- No unchanged relevant lines lost coverage.
- Overall coverage remained the same at 96.407%
| Totals | |
|---|---|
| Change from base Build 15118261747: | 0.0% |
| Covered Lines: | 1097 |
| Relevant Lines: | 1120 |
💛 - Coveralls
This pull request is stale because it has been open 15 days with no activity. Remove stale label or comment or this will be closed in 5 days.