From b912e8a9e9939ef844b9fea59252035fa5894d26 Mon Sep 17 00:00:00 2001 From: Dan Levin Date: Mon, 20 Nov 2023 17:06:13 +0100 Subject: [PATCH 1/3] Introduce force-execute option to prevent linkerd-await from terminating in the absence of a linkerd-proxy Signed-off-by: Dan Levin --- src/main.rs | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index d77587a..d087eeb 100644 --- a/src/main.rs +++ b/src/main.rs @@ -33,6 +33,14 @@ struct Args { )] shutdown: bool, + #[clap( + short = 'F', + long = "force-exec", + help = "Runs CMD even if the proxy is not yet ready prior to timeout", + requires("CMD") + )] + force: bool, + #[clap( short = 'v', long = "verbose", @@ -66,6 +74,7 @@ async fn main() { port, backoff, shutdown, + force, verbose, timeout, cmd, @@ -100,7 +109,12 @@ async fn main() { "linkerd-proxy failed to become ready within {:?} timeout", timeout ); - std::process::exit(EX_UNAVAILABLE) + + // If force-execute is configured, don't exit, but rather continue to execute command and try proxy shutdown + if !force { + std::process::exit(EX_UNAVAILABLE) + } + } } if shutdown { From 0a588704d32d54abd8637dcf8f837a11ed68d403 Mon Sep 17 00:00:00 2001 From: Dan Levin Date: Tue, 5 Dec 2023 21:51:59 +0100 Subject: [PATCH 2/3] Implement a boolean flag as a directive to treat timeouts as non-fatal and continue executing the command and/or shutting down Signed-off-by: Dan Levin --- src/main.rs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/main.rs b/src/main.rs index d087eeb..1a3cc0b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -34,12 +34,11 @@ struct Args { shutdown: bool, #[clap( - short = 'F', - long = "force-exec", - help = "Runs CMD even if the proxy is not yet ready prior to timeout", + long = "timeout-non-fatal", + help = "Allows the command or shutdown to execute independently of the status of the proxy. (Normally linkerd-await will exit immediately if the proxy is not yet ready prior to timeout.)", requires("CMD") )] - force: bool, + timeoutnonfatal: bool, #[clap( short = 'v', @@ -74,7 +73,7 @@ async fn main() { port, backoff, shutdown, - force, + timeoutnonfatal, verbose, timeout, cmd, @@ -110,8 +109,9 @@ async fn main() { timeout ); - // If force-execute is configured, don't exit, but rather continue to execute command and try proxy shutdown - if !force { + // If timeoutfatal is true, exit. Otherwise, continue to execute command and try proxy shutdown + let timeoutfatal = !timeoutnonfatal; + if timeoutfatal { std::process::exit(EX_UNAVAILABLE) } From 6cd93b928f843e7a7052d39e6e1cdda00e6d7a04 Mon Sep 17 00:00:00 2001 From: Oliver Gould Date: Mon, 11 Dec 2023 20:48:45 +0000 Subject: [PATCH 3/3] Update flag to be `--timeout-fatal=false` Via https://github.com/clap-rs/clap/issues/1649#issuecomment-1837123432 --- src/main.rs | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/src/main.rs b/src/main.rs index 1a3cc0b..f31e3b6 100644 --- a/src/main.rs +++ b/src/main.rs @@ -33,13 +33,6 @@ struct Args { )] shutdown: bool, - #[clap( - long = "timeout-non-fatal", - help = "Allows the command or shutdown to execute independently of the status of the proxy. (Normally linkerd-await will exit immediately if the proxy is not yet ready prior to timeout.)", - requires("CMD") - )] - timeoutnonfatal: bool, - #[clap( short = 'v', long = "verbose", @@ -56,6 +49,18 @@ struct Args { )] timeout: Option, + #[clap( + long, + help = "Controls whether a readiness timeout failure prevents CMD from running", + default_value("true"), + default_missing_value("true"), + num_args(0..=1), + require_equals(true), + action = clap::ArgAction::Set, + requires("CMD") + )] + timeout_fatal: bool, + #[clap(name = "CMD", help = "The command to run after linkerd is ready")] cmd: Option, @@ -73,9 +78,9 @@ async fn main() { port, backoff, shutdown, - timeoutnonfatal, verbose, timeout, + timeout_fatal, cmd, args, } = Args::parse(); @@ -109,12 +114,12 @@ async fn main() { timeout ); - // If timeoutfatal is true, exit. Otherwise, continue to execute command and try proxy shutdown - let timeoutfatal = !timeoutnonfatal; - if timeoutfatal { + // Continue running the command when timeouts are configured + // to be non-fatal. + if timeout_fatal { std::process::exit(EX_UNAVAILABLE) } - + } } if shutdown {