-
Notifications
You must be signed in to change notification settings - Fork 27
feat: Implement Xline native watch mechanism for rks #137
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
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]>
There was a problem hiding this 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.
project/rks/tests/test_watch.rs
Outdated
Arc::new(tokio::runtime::Handle::current().block_on(async { | ||
XlineStore::new(&endpoints).await.expect("connect xline failed") |
There was a problem hiding this comment.
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.
let pod_name = String::from_utf8_lossy(kv.key()) | ||
.replace("/registry/pods/", ""); |
There was a problem hiding this comment.
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()
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.
project/rks/src/commands/delete.rs
Outdated
) -> 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); |
There was a problem hiding this comment.
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.
Signed-off-by: InChh <[email protected]>
There was a problem hiding this 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.
project/rks/tests/test_watch.rs
Outdated
.iter() | ||
.map(|s| s.as_str()) | ||
.collect(); | ||
Arc::new(tokio::runtime::Handle::current().block_on(async { |
There was a problem hiding this comment.
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.
let resp = timeout(Duration::from_secs(5), stream.next()) | ||
.await | ||
.unwrap() | ||
.unwrap() | ||
.unwrap(); |
There was a problem hiding this comment.
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.
if let Ok(pod_task) = serde_yaml::from_str::<PodTask>(&pod_yaml) | ||
&& pod_task.spec.node_name.as_deref() == Some(&node_id) | ||
{ |
There was a problem hiding this comment.
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.
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/", ""); |
There was a problem hiding this comment.
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.
.replace("/registry/pods/", ""); | |
.rsplit('/') | |
.next() | |
.unwrap_or("") | |
.to_string(); |
Copilot uses AI. Check for mistakes.
project/rks/src/api/xlinestore.rs
Outdated
@@ -1,63 +1,77 @@ | |||
#![allow(dead_code)] | |||
#![allow(unused)] |
There was a problem hiding this comment.
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.
#![allow(unused)] |
Copilot uses AI. Check for mistakes.
project/rks/src/commands/delete.rs
Outdated
@@ -1,9 +1,9 @@ | |||
#![allow(unused)] |
There was a problem hiding this comment.
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.
#![allow(unused)] |
Copilot uses AI. Check for mistakes.
project/rks/src/commands/create.rs
Outdated
@@ -1,10 +1,11 @@ | |||
#![allow(unused)] |
There was a problem hiding this comment.
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.
#![allow(unused)] |
Copilot uses AI. Check for mistakes.
# Conflicts: # project/rks/BUCK
Summary
Replace broadcast simulation with real xline/etcd watch implementation.
Changes
Breaking Changes
Testing