Skip to content
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

zds: fix retrying a bad netns #1284

Merged
merged 1 commit into from
Aug 28, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions src/inpod/statemanager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,8 @@ impl WorkloadProxyManagerState {
.await
{
Ok(()) => {
// If the workload is already pending, make sure we drop it, so we don't retry.
self.pending_workloads.remove(workload_uid);
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm beginning to think we should probably key all of the workload stores with UID + NetNSID to avoid future goofiness like this.

Copy link
Member Author

Choose a reason for hiding this comment

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

one nice part about UID is it means we will never have multiple Proxy running for a given pod. I would worry if we have netns ID as a key we could end up with some leaky Proxy instances somehow maybe?

Might be possible, but needs care

self.update_proxy_count_metrics();
Ok(())
}
Expand Down Expand Up @@ -493,6 +495,46 @@ mod tests {
assert_eq!(m.proxies_started.get_or_create(&()).get(), 1);
}

#[tokio::test]
async fn workload_added_while_pending() {
// Regression test for https://github.com/istio/istio/issues/52858
// Workload is added and fails, so put on the pending queue. Then it is added and succeeds.
// The bug is that when we retry with the failed netns, we (1) never succeed and (2) drop the running proxy.
let fixture = fixture!();
let m = fixture.metrics.clone();
let mut state = fixture.state;
let ns1 = new_netns();
let ns2 = new_netns();
// to make the proxy fail, bind to its ports in its netns
let _sock = create_proxy_confilct(&ns1);

// Add the pod in netns1
let ret = state
.process_msg(WorkloadMessage::AddWorkload(WorkloadData {
netns: ns1,
workload_uid: uid(0),
workload_info: workload_info(),
}))
.await;
assert!(ret.is_err());
assert!(state.have_pending());

// Add it again with another netns. The original pod should still be present in the retry queue with ns1
state
.process_msg(WorkloadMessage::AddWorkload(WorkloadData {
netns: ns2,
workload_uid: uid(0),
workload_info: workload_info(),
}))
.await
.expect("should start");

state.retry_pending().await;
assert!(!state.have_pending());
state.drain().await;
assert_eq!(m.proxies_started.get_or_create(&()).get(), 1);
}

#[tokio::test]
async fn idemepotency_add_workload_fails_and_then_deleted() {
let fixture = fixture!();
Expand Down