kubernetes-operator icon indicating copy to clipboard operation
kubernetes-operator copied to clipboard

Fix TwingateConnector operator stuck in update loop

Open Copilot opened this issue 9 months ago • 1 comments

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:

  1. Modified the connector_update method in TwingateConnectorAPI to:

    • Handle "does not exist" errors in GraphQL mutations
    • Return None instead of raising an exception when a connector is not found
    • Log a warning message to indicate the connector was likely deleted
  2. Updated the twingate_connector_update handler 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
  3. 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.

Copilot avatar May 20 '25 07:05 Copilot

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 Coverage Status
Change from base Build 15118261747: 0.0%
Covered Lines: 1097
Relevant Lines: 1120

💛 - Coveralls

coveralls avatar May 20 '25 07:05 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.

github-actions[bot] avatar Jun 05 '25 14:06 github-actions[bot]