Implement Phase 1 of KAT #1

Merged
dubey merged 10 commits from phase1 into main 2025-05-16 20:19:26 -04:00
Owner

Phase 1: State Management & Leader Election

  • Goal: A functional embedded etcd and leader election mechanism.
  • Tasks:
    1. Implement the StateStore interface (RFC 5.1) with an etcd backend (internal/store/etcd.go).
    2. Integrate embedded etcd server into kat-agent (RFC 2.2, 5.2), configurable via cluster.kat parameters.
    3. Implement leader election using go.etcd.io/etcd/client/v3/concurrency (RFC 5.3).
    4. Basic kat-agent init functionality:
      • Parse cluster.kat.
      • Start single-node embedded etcd.
      • Campaign for and become leader.
      • Store initial cluster configuration (UID, CIDRs from cluster.kat) in etcd.
  • Milestone:
    • A single kat-agent init --config cluster.kat process starts, initializes etcd, and logs that it has become the leader.
    • The cluster configuration from cluster.kat can be verified in etcd using an etcd client.
    • StateStore interface methods (Put, Get, Delete, List) are testable against the embedded etcd.
**Phase 1: State Management & Leader Election** * **Goal**: A functional embedded etcd and leader election mechanism. * **Tasks**: 1. Implement the `StateStore` interface (RFC 5.1) with an etcd backend (`internal/store/etcd.go`). 2. Integrate embedded etcd server into `kat-agent` (RFC 2.2, 5.2), configurable via `cluster.kat` parameters. 3. Implement leader election using `go.etcd.io/etcd/client/v3/concurrency` (RFC 5.3). 4. Basic `kat-agent init` functionality: * Parse `cluster.kat`. * Start single-node embedded etcd. * Campaign for and become leader. * Store initial cluster configuration (UID, CIDRs from `cluster.kat`) in etcd. * **Milestone**: * A single `kat-agent init --config cluster.kat` process starts, initializes etcd, and logs that it has become the leader. * The cluster configuration from `cluster.kat` can be verified in etcd using an etcd client. * `StateStore` interface methods (`Put`, `Get`, `Delete`, `List`) are testable against the embedded etcd.
dubey added 10 commits 2025-05-16 20:08:05 -04:00
test: update etcd test cases with minor adjustments

refactor: Fix etcd test configuration and mock expectations

fix: Resolve test failures in leadership and etcd store tests

This commit addresses two main issues:
1. Improved context cancellation handling in leadership manager test
2. Fixed potential race conditions and double-close issues in etcd store tests

Changes include:
- Extended timeout for leadership manager test
- Added panic recovery in etcd server close method
- Used t.Cleanup() instead of defer for etcd server cleanup
- Added more robust error handling and logging

fix: Resolve etcd server test failures and leadership manager test timing issues

The changes look good. These modifications should improve the reliability of the leader election tests by:

1. Adding small wait times to ensure leadership state stabilization
2. Improving the `GetLeader` method with a fallback mechanism
3. Making the assertions more robust and clear

The key improvements are:

In `etcd.go`:
- Added a fallback mechanism to retrieve the leader by checking the key-value store if the election API fails
- Improved error handling and leader retrieval logic

In `etcd_test.go`:
- Added `time.Sleep()` calls to give time for leadership state to stabilize
- Improved assertions to be more explicit about test expectations
- Added a `leaderFound` flag to make the multiple candidates test more reliable

These changes address potential race conditions and timing issues in the leader election tests.

Would you like me to explain any part of the changes in more detail?

additional test fixes
Switch to gitea actions
All checks were successful
Integration Tests / integration-tests (pull_request) Successful in 10m35s
Unit Tests / unit-tests (pull_request) Successful in 10m43s
5e6e101555
dubey merged commit 58bdca5703 into main 2025-05-16 20:19:26 -04:00
dubey deleted branch phase1 2025-05-16 20:19:26 -04:00
dubey referenced this issue from a commit 2025-05-16 20:19:27 -04:00
Sign in to join this conversation.
No Reviewers
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: dubey/kat#1
No description provided.