Skip to content

Conversation

Flash0615
Copy link
Contributor

Summary

Replace broadcast simulation with real xline/etcd watch implementation.

Changes

  • Add XlineStore abstraction layer
  • Implement atomic snapshot + watch operations
  • Add comprehensive test coverage
  • Support proper reconnection handling

Breaking Changes

  • Watch API now requires xline endpoints instead of broadcast channels

Testing

  • Unit tests:Passing
  • Integration tests

Replace broadcast simulation with xline watch for pods and nodes.

Signed-off-by: Haojun Xie <[email protected]>
>> Replace broadcast simulation with xline watch for pods and nodes.

Signed-off-by: Haojun Xie <[email protected]>
Replace broadcast simulation with real xline/etcd watch implementation.
Adds XlineStore abstraction and atomic snapshot+revision operations.

Breaking change: requires xline endpoints instead of broadcast channels.

Signed-off-by: Haojun Xie <[email protected]>
@genedna genedna requested review from Copilot and tcytan September 2, 2025 01:24
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR replaces the broadcast-based pod watching mechanism with a native Xline/etcd watch implementation, providing more reliable and efficient state synchronization for the Kubernetes-like orchestration system.

  • Replace broadcast channels with atomic snapshot + watch operations using etcd client
  • Add comprehensive test coverage for watch operations including edge cases
  • Implement proper reconnection handling and cleanup mechanisms

Reviewed Changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
project/rks/tests/test_xline.rs Refactored test structure with shared store loading and unique pod naming
project/rks/tests/test_watch.rs Added comprehensive watch functionality tests covering CRUD operations and edge cases
project/rks/src/server.rs Major refactor removing broadcast channels, implementing native watch streams, improved logging
project/rks/src/network/manager.rs Added XlineStore initialization in tests
project/rks/src/network/ip.rs Marked flaky test as ignored
project/rks/src/main.rs Added logger initialization
project/rks/src/commands/delete.rs Removed broadcast dependency, simplified delete logic
project/rks/src/commands/create.rs Enhanced error handling and removed broadcast dependency
project/rks/src/api/xlinestore.rs Expanded API with snapshot, watch, and configuration methods
project/rks/Cargo.toml Added futures-util and time dependencies

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment on lines 14 to 15
Arc::new(tokio::runtime::Handle::current().block_on(async {
XlineStore::new(&endpoints).await.expect("connect xline failed")
Copy link
Preview

Copilot AI Sep 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using block_on within an async context can cause deadlocks or panics. Since load_store() is called from async test functions, the XlineStore creation should remain async rather than blocking on the current runtime.

Copilot uses AI. Check for mistakes.

Comment on lines +198 to +199
let pod_name = String::from_utf8_lossy(kv.key())
.replace("/registry/pods/", "");
Copy link
Preview

Copilot AI Sep 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This key parsing logic is fragile and could produce incorrect pod names if the key doesn't start with the expected prefix. Use proper prefix stripping: String::from_utf8_lossy(kv.key()).strip_prefix(\"/registry/pods/\").unwrap_or(\"\").to_string()

Suggested change
let pod_name = String::from_utf8_lossy(kv.key())
.replace("/registry/pods/", "");
.strip_prefix("/registry/pods/")
.unwrap_or("")
.to_string();

Copilot uses AI. Check for mistakes.

) -> Result<()> {
let _ = tx.send(RksMessage::DeletePod(pod_name.clone()));
xline_store.delete_pod(&pod_name).await?;
println!("[user_delete] deleted pod {} (written to xline)",pod_name);
Copy link
Preview

Copilot AI Sep 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing space before the opening parenthesis. Should be: println!(\"[user_delete] deleted pod {} (written to xline)\", pod_name);

Copilot uses AI. Check for mistakes.

@genedna genedna requested review from Copilot and InChh and removed request for tcytan September 16, 2025 01:34
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Copilot reviewed 12 out of 13 changed files in this pull request and generated 7 comments.


Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

.iter()
.map(|s| s.as_str())
.collect();
Arc::new(tokio::runtime::Handle::current().block_on(async {
Copy link
Preview

Copilot AI Sep 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using block_on within an async context can cause deadlocks or performance issues. Consider making load_store async and awaiting it in the test functions instead.

Copilot uses AI. Check for mistakes.

Comment on lines +46 to +50
let resp = timeout(Duration::from_secs(5), stream.next())
.await
.unwrap()
.unwrap()
.unwrap();
Copy link
Preview

Copilot AI Sep 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Chained .unwrap() calls make error handling difficult to debug. Consider using expect() with descriptive messages or proper error handling for better debugging experience.

Copilot uses AI. Check for mistakes.

Comment on lines +174 to +176
if let Ok(pod_task) = serde_yaml::from_str::<PodTask>(&pod_yaml)
&& pod_task.spec.node_name.as_deref() == Some(&node_id)
{
Copy link
Preview

Copilot AI Sep 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] The let-chain pattern can be hard to read. Consider breaking this into separate if let statements or using match for better readability.

Suggested change
if let Ok(pod_task) = serde_yaml::from_str::<PodTask>(&pod_yaml)
&& pod_task.spec.node_name.as_deref() == Some(&node_id)
{
if let Ok(pod_task) = serde_yaml::from_str::<PodTask>(&pod_yaml) {
if pod_task.spec.node_name.as_deref() == Some(&node_id) {

Copilot uses AI. Check for mistakes.

etcd_client::EventType::Delete => {
if let Some(kv) = event.prev_kv() {
let pod_name = String::from_utf8_lossy(kv.key())
.replace("/registry/pods/", "");
Copy link
Preview

Copilot AI Sep 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using string replacement for key parsing is fragile. Consider using a more robust approach like splitting on '/' and taking the last component, or defining a constant for the prefix.

Suggested change
.replace("/registry/pods/", "");
.rsplit('/')
.next()
.unwrap_or("")
.to_string();

Copilot uses AI. Check for mistakes.

@@ -1,63 +1,77 @@
#![allow(dead_code)]
#![allow(unused)]
Copy link
Preview

Copilot AI Sep 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using #![allow(unused)] at the module level suppresses important warnings. Consider removing this and addressing unused code warnings individually or using more specific allows like #[allow(dead_code)] on specific items.

Suggested change
#![allow(unused)]

Copilot uses AI. Check for mistakes.

@@ -1,9 +1,9 @@
#![allow(unused)]
Copy link
Preview

Copilot AI Sep 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using #![allow(unused)] at the module level suppresses important warnings. Consider removing this and addressing unused code warnings individually.

Suggested change
#![allow(unused)]

Copilot uses AI. Check for mistakes.

@@ -1,10 +1,11 @@
#![allow(unused)]
Copy link
Preview

Copilot AI Sep 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using #![allow(unused)] at the module level suppresses important warnings. Consider removing this and addressing unused code warnings individually.

Suggested change
#![allow(unused)]

Copilot uses AI. Check for mistakes.

@InChh InChh added this pull request to the merge queue Sep 16, 2025
Merged via the queue into rk8s-dev:main with commit 458cdc9 Sep 16, 2025
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants