Skip to content

Conversation

juanxiu
Copy link
Contributor

@juanxiu juanxiu commented Oct 4, 2025

What does this PR do / why we need it:
This PR implements sync operation termination support for ArgoCD Agent, allowing users to abort running sync operations that were previously unstoppable.

Problem

Currently, when users trigger sync operations on Applications in ArgoCD Agent, there was no way to abort them once started. This is because the .status.operationState.phase field (which indicates "Terminating" state) was not propagated from the Principal to the Agents.

Solution:

  • Added a new OperationTerminate event type for signaling sync abort requests
  • Principal now detects when .status.operationState.phase changes to "Terminating" and sends this event to the targeted Agent
  • Agent receives the event and updates the local Application status to "Terminating", allowing the ArgoCD Application Controller to abort the sync operation

Key Changes:

  1. Event System: Added OperationTerminate event type in internal/event/event.go
  2. Principal Logic: Enhanced principal/callbacks.go to detect terminating state changes and send events
  3. Principal Event Handling: Added OperationTerminate event processing in principal/event.go
  4. Agent Processing: Implemented sync termination handler in agent/inbound.go

Which issue(s) this PR fixes:

Fixes #565

How to test changes / Special notes to the reviewer:

Testing Approach

Due to TLS certificate complexity in the full environment, we implemented comprehensive unit tests to validate the core logic:

Unit Tests Added:

  1. Principal Callback Tests (principal/callbacks_operation_terminate_test.go):

    • 8 scenarios covering all phase transitions (Running/Succeeded/Failed → Terminating)
    • Edge cases: nil operation states, already terminating states
    • Validates shouldSendOperationTerminateEvent function logic
  2. Principal Event Processing Tests (principal/event_operation_terminate_test.go):

    • Agent mode validation (Managed vs Autonomous)
    • Event type handling verification
    • Mock-based dependency isolation
  3. Agent Inbound Tests (agent/inbound_operation_terminate_test.go):

    • Success/failure scenarios with mocks
    • Operation termination handling verification
    • Mode-specific event processing
  4. Integration Tests (test_sync_termination_integration_test.go):

    • Complete sync termination workflow validation
    • Event flow and structure verification
    • Agent mode behavior validation

Checklist

  • Documentation update is required by this PR (and has been updated) OR no documentation update is required.

@codecov-commenter
Copy link

codecov-commenter commented Oct 4, 2025

Codecov Report

❌ Patch coverage is 14.70588% with 58 lines in your changes missing coverage. Please review.
✅ Project coverage is 45.45%. Comparing base (f6e8e9b) to head (ee02bc8).

Files with missing lines Patch % Lines
agent/inbound.go 0.00% 43 Missing ⚠️
principal/event.go 0.00% 10 Missing ⚠️
principal/callbacks.go 66.66% 4 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #595      +/-   ##
==========================================
- Coverage   45.62%   45.45%   -0.18%     
==========================================
  Files          90       90              
  Lines       12021    12089      +68     
==========================================
+ Hits         5485     5495      +10     
- Misses       6091     6148      +57     
- Partials      445      446       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@juanxiu juanxiu force-pushed the issue/#565 branch 2 times, most recently from 30003ff to cce8ea6 Compare October 4, 2025 06:31
- Add OperationTerminate event type for sync abort signaling
- Implement Terminating state detection in principal callbacks
- Add OperationTerminate event handling in principal event processor
- Implement sync termination handler in agent inbound processor
- Support operation state update to Terminating phase

Signed-off-by: yeonsoo <[email protected]>

test: add unit tests for sync termination feature

- Add Principal callback tests for OperationTerminate event detection
- Add Principal event processing tests for OperationTerminate events
- Add Agent operation termination tests in separate files
- Add integration tests for complete sync termination flow
- Cover all phase transition scenarios and edge cases
- Verify agent mode-specific event handling behavior

Signed-off-by: yeonsoo <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow sync operations to be terminated from the control plane
2 participants