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

Fix noaccess retries #12

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
18 changes: 16 additions & 2 deletions src/kubectl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use crate::cli::KubectlPathBuf;
use crate::config::{ConfigId, OperationalConfig, PortForwardConfig, RetryDelay};
use anyhow::anyhow;
use serde::Deserialize;
use std::env::current_dir;
use std::io::{BufRead, Read};
Expand Down Expand Up @@ -248,11 +249,23 @@ impl Kubectl {
// Wait for the child process to finish
let status = child.wait();
let status = match status {
Ok(status) => status,
Ok(status) => {
match status.code().unwrap() {
1 => {
// Kill the process if the exit code is 1
out_tx
.send(ChildEvent::Exit(id, status, RestartPolicy::None))
.ok();
break 'new_process Err(anyhow!("Command returned status code 1"));
}
_ => {}
};
status
}
Err(e) => {
out_tx.send(ChildEvent::Error(id, ChildError::Wait(e))).ok();
// TODO: Break out of this loop if the error is unfixable?
continue 'new_process;
// TODO: Break out of this loop if the error is unfixable?
}
};

Expand Down Expand Up @@ -310,6 +323,7 @@ pub enum ChildEvent {
#[derive(Debug)]
pub enum RestartPolicy {
WillRestartIn(RetryDelay),
None,
}

#[derive(Debug, thiserror::Error)]
Expand Down
8 changes: 7 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -251,13 +251,19 @@ fn start_output_loop_thread(out_rx: Receiver<ChildEvent>) -> JoinHandle<()> {
"{id}: Process exited with {} - will retry in {}",
status, delay
);
} else {
} else if delay == RetryDelay::NONE {
Copy link
Owner

Choose a reason for hiding this comment

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

It seems the newly added if statement here is either unnecessary or incorrect. Unnecessary because positive delay times are already captured above, incorrect because it leaves out the hypothetical negative delay times ("less that NONE"). What was the reason for adding it?

eprintln!(
"{id}: Process exited with {} - retrying immediately",
status
);
}
}
RestartPolicy::None => {
eprintln!(
"{id}: Process exited with {} - shutting process down",
status
);
}
}
}
ChildEvent::Error(id, error) => {
Expand Down