Skip to content

Commit 42ec23e

Browse files
authored
Make CMD optional (#23)
`CMD` is not required if the use-case of `linkerd-await` is only to wait for readiness but do nothing afterwards. In linkerd/linkerd2#5967 this is the case. `linkerd-await` is executed as a container hook and the only thing that it needs to do is prevent the hook from finishing until the proxy is ready. Once it is ready, it exits without running any additional commands. Signed-off-by: Kevin Leimkuhler <[email protected]>
1 parent 37ecfca commit 42ec23e

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

src/main.rs

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,15 @@ struct Opt {
2929
#[structopt(
3030
short = "S",
3131
long = "shutdown",
32-
help = "Forks the program and triggers proxy shutdown on completion"
32+
help = "Forks the program and triggers proxy shutdown on completion",
33+
requires("CMD")
3334
)]
3435
shutdown: bool,
3536

36-
#[structopt(name = "CMD")]
37-
cmd: String,
37+
#[structopt(name = "CMD", help = "The command to run after linkerd is ready")]
38+
cmd: Option<String>,
3839

39-
#[structopt(name = "ARGS")]
40+
#[structopt(name = "ARGS", help = "Arguments to pass to CMD if specified")]
4041
args: Vec<String>,
4142
}
4243

@@ -64,7 +65,10 @@ async fn main() {
6465
await_ready(authority.clone(), backoff).await;
6566

6667
if shutdown {
67-
// If shutdown is configured, fork the process and proxy SIGTERM.
68+
let cmd = cmd.expect("Command must be specified with --shutdown");
69+
70+
// If shutdown is configured, fork the process and proxy
71+
// SIGTERM.
6872
let ex = fork_with_sigterm(cmd, args).await;
6973

7074
// Once the process completes, issue a shutdown request to the
@@ -85,9 +89,11 @@ async fn main() {
8589
}
8690
}
8791

88-
// If Linkerd shutdown is not configured, exec the process directly so that
89-
// the we don't have to bother with signal proxying, etc.
90-
exec(cmd, args);
92+
if let Some(cmd) = cmd {
93+
// If Linkerd shutdown is not configured, exec the process directly so
94+
// that the we don't have to bother with signal proxying, etc.
95+
exec(cmd, args);
96+
}
9197
}
9298

9399
fn linkerd_disabled_reason() -> Option<String> {

0 commit comments

Comments
 (0)