From 6244e5eedb1feffb5f069416a08177aba58e2776 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20M=C3=BCller?= Date: Fri, 21 Aug 2026 12:26:11 +0200 Subject: [PATCH 1/7] fix: wait_for_termination returns actual exit status --- crates/stackable-operator/CHANGELOG.md | 7 +++ .../src/crd/git_sync/v1alpha1_impl.rs | 27 +++++++-- .../src/crd/git_sync/v1alpha2_impl.rs | 45 ++++++++++---- .../src/product_logging/framework.rs | 4 +- crates/stackable-operator/src/utils/bash.rs | 58 +++++++++++++++++-- 5 files changed, 120 insertions(+), 21 deletions(-) diff --git a/crates/stackable-operator/CHANGELOG.md b/crates/stackable-operator/CHANGELOG.md index 2531f7406..59c4ba393 100644 --- a/crates/stackable-operator/CHANGELOG.md +++ b/crates/stackable-operator/CHANGELOG.md @@ -23,6 +23,13 @@ All notable changes to this project will be documented in this file. It was only needed when upgrading from SDP <= 26.3 to 26.7. The `DeleteRandomSecret` error variant is removed as well ([#1338]). +### Fixed + +- `wait_for_termination` in `COMMON_BASH_TRAP_FUNCTIONS` now returns the exit status of the process + it waited for instead of always returning `0` and the shell no longer aborts when SIGTERM arrives + before the child process ID is known to ensure graceful shut down. ([#1265]). + +[#1265]: https://github.com/stackabletech/operator-rs/pull/1265 [#1326]: https://github.com/stackabletech/operator-rs/pull/1326 [#1338]: https://github.com/stackabletech/operator-rs/pull/1338 [#1339]: https://github.com/stackabletech/operator-rs/pull/1339 diff --git a/crates/stackable-operator/src/crd/git_sync/v1alpha1_impl.rs b/crates/stackable-operator/src/crd/git_sync/v1alpha1_impl.rs index 2b575929c..a85a4ddbd 100644 --- a/crates/stackable-operator/src/crd/git_sync/v1alpha1_impl.rs +++ b/crates/stackable-operator/src/crd/git_sync/v1alpha1_impl.rs @@ -498,7 +498,7 @@ mod tests { handle_term_signal() { - if [ "${term_child_pid}" ]; then + if [ -n "${term_child_pid:-}" ]; then kill -TERM "${term_child_pid}" 2>/dev/null else term_kill_needed="yes" @@ -513,9 +513,14 @@ mod tests { kill -TERM "${term_child_pid}" 2>/dev/null fi wait ${term_child_pid} 2>/dev/null + term_child_status=$? trap - TERM - wait ${term_child_pid} 2>/dev/null + if [ "${term_child_status}" -gt 128 ]; then + wait ${term_child_pid} 2>/dev/null + term_child_status=$? + fi set -e + return ${term_child_status} } prepare_signal_handlers @@ -567,7 +572,7 @@ volumeMounts: handle_term_signal() { - if [ "${term_child_pid}" ]; then + if [ -n "${term_child_pid:-}" ]; then kill -TERM "${term_child_pid}" 2>/dev/null else term_kill_needed="yes" @@ -582,9 +587,14 @@ volumeMounts: kill -TERM "${term_child_pid}" 2>/dev/null fi wait ${term_child_pid} 2>/dev/null + term_child_status=$? trap - TERM - wait ${term_child_pid} 2>/dev/null + if [ "${term_child_status}" -gt 128 ]; then + wait ${term_child_pid} 2>/dev/null + term_child_status=$? + fi set -e + return ${term_child_status} } prepare_signal_handlers @@ -641,7 +651,7 @@ volumeMounts: handle_term_signal() { - if [ "${term_child_pid}" ]; then + if [ -n "${term_child_pid:-}" ]; then kill -TERM "${term_child_pid}" 2>/dev/null else term_kill_needed="yes" @@ -656,9 +666,14 @@ volumeMounts: kill -TERM "${term_child_pid}" 2>/dev/null fi wait ${term_child_pid} 2>/dev/null + term_child_status=$? trap - TERM - wait ${term_child_pid} 2>/dev/null + if [ "${term_child_status}" -gt 128 ]; then + wait ${term_child_pid} 2>/dev/null + term_child_status=$? + fi set -e + return ${term_child_status} } prepare_signal_handlers diff --git a/crates/stackable-operator/src/crd/git_sync/v1alpha2_impl.rs b/crates/stackable-operator/src/crd/git_sync/v1alpha2_impl.rs index 4fdd76e0e..3adf0d8c4 100644 --- a/crates/stackable-operator/src/crd/git_sync/v1alpha2_impl.rs +++ b/crates/stackable-operator/src/crd/git_sync/v1alpha2_impl.rs @@ -629,7 +629,7 @@ mod tests { handle_term_signal() { - if [ "${term_child_pid}" ]; then + if [ -n "${term_child_pid:-}" ]; then kill -TERM "${term_child_pid}" 2>/dev/null else term_kill_needed="yes" @@ -644,9 +644,14 @@ mod tests { kill -TERM "${term_child_pid}" 2>/dev/null fi wait ${term_child_pid} 2>/dev/null + term_child_status=$? trap - TERM - wait ${term_child_pid} 2>/dev/null + if [ "${term_child_status}" -gt 128 ]; then + wait ${term_child_pid} 2>/dev/null + term_child_status=$? + fi set -e + return ${term_child_status} } prepare_signal_handlers @@ -698,7 +703,7 @@ volumeMounts: handle_term_signal() { - if [ "${term_child_pid}" ]; then + if [ -n "${term_child_pid:-}" ]; then kill -TERM "${term_child_pid}" 2>/dev/null else term_kill_needed="yes" @@ -713,9 +718,14 @@ volumeMounts: kill -TERM "${term_child_pid}" 2>/dev/null fi wait ${term_child_pid} 2>/dev/null + term_child_status=$? trap - TERM - wait ${term_child_pid} 2>/dev/null + if [ "${term_child_status}" -gt 128 ]; then + wait ${term_child_pid} 2>/dev/null + term_child_status=$? + fi set -e + return ${term_child_status} } prepare_signal_handlers @@ -772,7 +782,7 @@ volumeMounts: handle_term_signal() { - if [ "${term_child_pid}" ]; then + if [ -n "${term_child_pid:-}" ]; then kill -TERM "${term_child_pid}" 2>/dev/null else term_kill_needed="yes" @@ -787,9 +797,14 @@ volumeMounts: kill -TERM "${term_child_pid}" 2>/dev/null fi wait ${term_child_pid} 2>/dev/null + term_child_status=$? trap - TERM - wait ${term_child_pid} 2>/dev/null + if [ "${term_child_status}" -gt 128 ]; then + wait ${term_child_pid} 2>/dev/null + term_child_status=$? + fi set -e + return ${term_child_status} } prepare_signal_handlers @@ -1084,7 +1099,7 @@ name: content-from-git-2 handle_term_signal() { - if [ "${term_child_pid}" ]; then + if [ -n "${term_child_pid:-}" ]; then kill -TERM "${term_child_pid}" 2>/dev/null else term_kill_needed="yes" @@ -1099,9 +1114,14 @@ name: content-from-git-2 kill -TERM "${term_child_pid}" 2>/dev/null fi wait ${term_child_pid} 2>/dev/null + term_child_status=$? trap - TERM - wait ${term_child_pid} 2>/dev/null + if [ "${term_child_status}" -gt 128 ]; then + wait ${term_child_pid} 2>/dev/null + term_child_status=$? + fi set -e + return ${term_child_status} } prepare_signal_handlers @@ -1294,7 +1314,7 @@ secret: handle_term_signal() { - if [ "${term_child_pid}" ]; then + if [ -n "${term_child_pid:-}" ]; then kill -TERM "${term_child_pid}" 2>/dev/null else term_kill_needed="yes" @@ -1309,9 +1329,14 @@ secret: kill -TERM "${term_child_pid}" 2>/dev/null fi wait ${term_child_pid} 2>/dev/null + term_child_status=$? trap - TERM - wait ${term_child_pid} 2>/dev/null + if [ "${term_child_status}" -gt 128 ]; then + wait ${term_child_pid} 2>/dev/null + term_child_status=$? + fi set -e + return ${term_child_status} } prepare_signal_handlers diff --git a/crates/stackable-operator/src/product_logging/framework.rs b/crates/stackable-operator/src/product_logging/framework.rs index 35c7bab02..3750acf7a 100644 --- a/crates/stackable-operator/src/product_logging/framework.rs +++ b/crates/stackable-operator/src/product_logging/framework.rs @@ -1386,8 +1386,10 @@ sinks: /// {remove_vector_shutdown_file_command} /// prepare_signal_handlers /// my-application start & -/// wait_for_termination $! +/// product_exit_code=0 +/// wait_for_termination $! || product_exit_code=$? /// {create_vector_shutdown_file_command} +/// exit \"${{product_exit_code}}\" /// ", /// remove_vector_shutdown_file_command = /// remove_vector_shutdown_file_command(STACKABLE_LOG_DIR), diff --git a/crates/stackable-operator/src/utils/bash.rs b/crates/stackable-operator/src/utils/bash.rs index b93b77173..e6762e7e5 100644 --- a/crates/stackable-operator/src/utils/bash.rs +++ b/crates/stackable-operator/src/utils/bash.rs @@ -1,7 +1,8 @@ /// This is a bash snippet, which adds two functions out of interest: /// /// 1. `prepare_signal_handlers` call this first to set up the needed traps -/// 2. `wait_for_termination` waits for the PID you passed as the first argument to terminate +/// 2. `wait_for_termination` waits for the PID you passed as the first argument to terminate and +/// returns its exit status /// /// An example use could be /// ```text @@ -9,8 +10,10 @@ /// echo "Run before startup" /// prepare_signal_handlers /// {hadoop_home}/bin/hdfs {role} & -/// wait_for_termination $! +/// product_exit_code=0 +/// wait_for_termination $! || product_exit_code=$? /// echo "Run after termination" +/// exit "${product_exit_code}" /// ``` pub const COMMON_BASH_TRAP_FUNCTIONS: &str = r#" prepare_signal_handlers() @@ -22,7 +25,7 @@ prepare_signal_handlers() handle_term_signal() { - if [ "${term_child_pid}" ]; then + if [ -n "${term_child_pid:-}" ]; then kill -TERM "${term_child_pid}" 2>/dev/null else term_kill_needed="yes" @@ -37,8 +40,55 @@ wait_for_termination() kill -TERM "${term_child_pid}" 2>/dev/null fi wait ${term_child_pid} 2>/dev/null + term_child_status=$? trap - TERM - wait ${term_child_pid} 2>/dev/null + if [ "${term_child_status}" -gt 128 ]; then + wait ${term_child_pid} 2>/dev/null + term_child_status=$? + fi set -e + return ${term_child_status} } "#; + +#[cfg(test)] +mod tests { + use std::process::Command; + + use super::*; + + fn container_command_exit_code(script: &str) -> i32 { + Command::new("/bin/bash") + .args(["-euo", "pipefail", "-c", script]) + .status() + .expect("bash can be executed in the test environment") + .code() + .expect("the shell terminated regularly and not by a signal") + } + + #[test] + fn crash_of_child_process() { + let exit_code = container_command_exit_code(&format!( + "{COMMON_BASH_TRAP_FUNCTIONS} +prepare_signal_handlers +bash -c 'exit 42' & +wait_for_termination $!" + )); + + assert_eq!(42, exit_code); + } + + #[test] + fn graceful_shutdown_of_child_process() { + let exit_code = container_command_exit_code(&format!( + "{COMMON_BASH_TRAP_FUNCTIONS} +prepare_signal_handlers +bash -c 'trap \"exit 7\" TERM; sleep 10 & wait $!' & +child_pid=$! +(sleep 0.2; kill -TERM $$) & +wait_for_termination $child_pid" + )); + + assert_eq!(7, exit_code); + } +} From d8121788a884e8e6d51d02487619b171438475a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20M=C3=BCller?= Date: Wed, 2 Sep 2026 17:31:42 +0200 Subject: [PATCH 2/7] comment magic number 128 --- crates/stackable-operator/src/utils/bash.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/crates/stackable-operator/src/utils/bash.rs b/crates/stackable-operator/src/utils/bash.rs index e6762e7e5..0b2e32da2 100644 --- a/crates/stackable-operator/src/utils/bash.rs +++ b/crates/stackable-operator/src/utils/bash.rs @@ -15,6 +15,14 @@ /// echo "Run after termination" /// exit "${product_exit_code}" /// ``` +// A `wait` status above 128 can mean two things: +// 1. bash reports a signal death as `128 + signal` +// 2. an in-progress `wait` abort with such a status when a trapped signal arrives +// +// We wait a second time to get the actual child status, which immediately returns the +// status again in case 1. In case 2 the child is still running and we do need to wait. +// +// See https://www.gnu.org/software/bash/manual/html_node/Signals.html pub const COMMON_BASH_TRAP_FUNCTIONS: &str = r#" prepare_signal_handlers() { From c08d18004dc4d755da4d84c24d7f27fe5d8717c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20M=C3=BCller?= Date: Fri, 25 Sep 2026 09:27:00 +0200 Subject: [PATCH 3/7] indicate breaking change in changelog --- crates/stackable-operator/CHANGELOG.md | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/crates/stackable-operator/CHANGELOG.md b/crates/stackable-operator/CHANGELOG.md index 59c4ba393..f1ea765a7 100644 --- a/crates/stackable-operator/CHANGELOG.md +++ b/crates/stackable-operator/CHANGELOG.md @@ -25,9 +25,10 @@ All notable changes to this project will be documented in this file. ### Fixed -- `wait_for_termination` in `COMMON_BASH_TRAP_FUNCTIONS` now returns the exit status of the process - it waited for instead of always returning `0` and the shell no longer aborts when SIGTERM arrives - before the child process ID is known to ensure graceful shut down. ([#1265]). +- BREAKING: `wait_for_termination` in `COMMON_BASH_TRAP_FUNCTIONS` now returns the exit status of the process + it waited for instead of always returning `0` ([#1265]). +- `handle_term_signal` in `COMMON_BASH_TRAP_FUNCTIONS` no longer aborts under `set -u` when SIGTERM arrives + before the child process ID is known ([#1265]). [#1265]: https://github.com/stackabletech/operator-rs/pull/1265 [#1326]: https://github.com/stackabletech/operator-rs/pull/1326 From 3a3248ccc53d705e24e5ca524c97a291f788a7da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20M=C3=BCller?= Date: Fri, 25 Sep 2026 10:41:50 +0200 Subject: [PATCH 4/7] test additional cases for crash / term cases --- crates/stackable-operator/src/utils/bash.rs | 48 +++++++++++++++++---- 1 file changed, 40 insertions(+), 8 deletions(-) diff --git a/crates/stackable-operator/src/utils/bash.rs b/crates/stackable-operator/src/utils/bash.rs index 0b2e32da2..6163256fa 100644 --- a/crates/stackable-operator/src/utils/bash.rs +++ b/crates/stackable-operator/src/utils/bash.rs @@ -65,18 +65,22 @@ mod tests { use super::*; - fn container_command_exit_code(script: &str) -> i32 { - Command::new("/bin/bash") + fn run_container_command(script: &str) -> (i32, String) { + let output = Command::new("/bin/bash") .args(["-euo", "pipefail", "-c", script]) - .status() - .expect("bash can be executed in the test environment") + .output() + .expect("bash can be executed in the test environment"); + let exit_code = output + .status .code() - .expect("the shell terminated regularly and not by a signal") + .expect("the shell terminated regularly and not by a signal"); + let stdout = String::from_utf8(output.stdout).expect("the script only prints UTF-8"); + (exit_code, stdout) } #[test] fn crash_of_child_process() { - let exit_code = container_command_exit_code(&format!( + let (exit_code, _) = run_container_command(&format!( "{COMMON_BASH_TRAP_FUNCTIONS} prepare_signal_handlers bash -c 'exit 42' & @@ -88,10 +92,10 @@ wait_for_termination $!" #[test] fn graceful_shutdown_of_child_process() { - let exit_code = container_command_exit_code(&format!( + let (exit_code, _) = run_container_command(&format!( "{COMMON_BASH_TRAP_FUNCTIONS} prepare_signal_handlers -bash -c 'trap \"exit 7\" TERM; sleep 10 & wait $!' & +bash -c 'trap \"exit 7\" TERM; sleep 10 >/dev/null 2>&1 & wait $!' & child_pid=$! (sleep 0.2; kill -TERM $$) & wait_for_termination $child_pid" @@ -99,4 +103,32 @@ wait_for_termination $child_pid" assert_eq!(7, exit_code); } + + #[test] + fn crash_with_command_after_the_call() { + let (exit_code, stdout) = run_container_command(&format!( + "{COMMON_BASH_TRAP_FUNCTIONS} +prepare_signal_handlers +bash -c 'exit 42' & +product_exit_code=0 +wait_for_termination $! || product_exit_code=$? +echo tail-ran +exit \"${{product_exit_code}}\"" + )); + assert_eq!(42, exit_code); + assert!(stdout.contains("tail-ran\n")); + } + + #[test] + fn sigterm_before_child_pid_is_known() { + let (exit_code, _) = run_container_command(&format!( + "{COMMON_BASH_TRAP_FUNCTIONS} +prepare_signal_handlers +kill -TERM $$ +sleep 10 & +wait_for_termination $! +" + )); + assert_eq!(143, exit_code); + } } From 7bc52db5ae0b75ff6a3fbba13ab51a2c5990f149 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20M=C3=BCller?= Date: Fri, 25 Sep 2026 12:56:10 +0200 Subject: [PATCH 5/7] use insta for snapshot tests --- Cargo.lock | 1 + crates/stackable-operator/CHANGELOG.md | 11 +- crates/stackable-operator/Cargo.toml | 1 + ..._tests__multiple_git_syncs_containers.snap | 216 +++++++ ...s__multiple_git_syncs_init_containers.snap | 105 ++++ ...l__tests__git_sync_ca_cert_containers.snap | 73 +++ ...sts__git_sync_ca_cert_init_containers.snap | 36 ++ ..._impl__tests__git_sync_ssh_containers.snap | 77 +++ ...__tests__git_sync_ssh_init_containers.snap | 40 ++ ..._tests__multiple_git_syncs_containers.snap | 216 +++++++ ...s__multiple_git_syncs_init_containers.snap | 105 ++++ .../src/crd/git_sync/v1alpha1_impl.rs | 345 +---------- .../src/crd/git_sync/v1alpha2_impl.rs | 581 +----------------- 13 files changed, 898 insertions(+), 909 deletions(-) create mode 100644 crates/stackable-operator/src/crd/git_sync/snapshots/stackable_operator__crd__git_sync__v1alpha1_impl__tests__multiple_git_syncs_containers.snap create mode 100644 crates/stackable-operator/src/crd/git_sync/snapshots/stackable_operator__crd__git_sync__v1alpha1_impl__tests__multiple_git_syncs_init_containers.snap create mode 100644 crates/stackable-operator/src/crd/git_sync/snapshots/stackable_operator__crd__git_sync__v1alpha2_impl__tests__git_sync_ca_cert_containers.snap create mode 100644 crates/stackable-operator/src/crd/git_sync/snapshots/stackable_operator__crd__git_sync__v1alpha2_impl__tests__git_sync_ca_cert_init_containers.snap create mode 100644 crates/stackable-operator/src/crd/git_sync/snapshots/stackable_operator__crd__git_sync__v1alpha2_impl__tests__git_sync_ssh_containers.snap create mode 100644 crates/stackable-operator/src/crd/git_sync/snapshots/stackable_operator__crd__git_sync__v1alpha2_impl__tests__git_sync_ssh_init_containers.snap create mode 100644 crates/stackable-operator/src/crd/git_sync/snapshots/stackable_operator__crd__git_sync__v1alpha2_impl__tests__multiple_git_syncs_containers.snap create mode 100644 crates/stackable-operator/src/crd/git_sync/snapshots/stackable_operator__crd__git_sync__v1alpha2_impl__tests__multiple_git_syncs_init_containers.snap diff --git a/Cargo.lock b/Cargo.lock index 5c259b419..bc579998c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3871,6 +3871,7 @@ dependencies = [ "http", "indexmap", "indoc", + "insta", "java-properties", "jiff 1.0.1", "json-patch", diff --git a/crates/stackable-operator/CHANGELOG.md b/crates/stackable-operator/CHANGELOG.md index f1ea765a7..274540378 100644 --- a/crates/stackable-operator/CHANGELOG.md +++ b/crates/stackable-operator/CHANGELOG.md @@ -16,6 +16,10 @@ All notable changes to this project will be documented in this file. - `ProductImage::resolve` no longer panics on long product versions or image tags containing non-ASCII characters and returns an error instead ([#1339]). +- BREAKING: `wait_for_termination` in `COMMON_BASH_TRAP_FUNCTIONS` now returns the exit status of the process + it waited for instead of always returning `0` ([#1265]). +- `handle_term_signal` in `COMMON_BASH_TRAP_FUNCTIONS` no longer aborts under `set -u` when SIGTERM arrives + before the child process ID is known ([#1265]). ### Removed @@ -23,13 +27,6 @@ All notable changes to this project will be documented in this file. It was only needed when upgrading from SDP <= 26.3 to 26.7. The `DeleteRandomSecret` error variant is removed as well ([#1338]). -### Fixed - -- BREAKING: `wait_for_termination` in `COMMON_BASH_TRAP_FUNCTIONS` now returns the exit status of the process - it waited for instead of always returning `0` ([#1265]). -- `handle_term_signal` in `COMMON_BASH_TRAP_FUNCTIONS` no longer aborts under `set -u` when SIGTERM arrives - before the child process ID is known ([#1265]). - [#1265]: https://github.com/stackabletech/operator-rs/pull/1265 [#1326]: https://github.com/stackabletech/operator-rs/pull/1326 [#1338]: https://github.com/stackabletech/operator-rs/pull/1338 diff --git a/crates/stackable-operator/Cargo.toml b/crates/stackable-operator/Cargo.toml index 9e18ee666..9b6bea85c 100644 --- a/crates/stackable-operator/Cargo.toml +++ b/crates/stackable-operator/Cargo.toml @@ -69,6 +69,7 @@ xml.workspace = true [dev-dependencies] indoc.workspace = true +insta.workspace = true rstest.workspace = true [lints] diff --git a/crates/stackable-operator/src/crd/git_sync/snapshots/stackable_operator__crd__git_sync__v1alpha1_impl__tests__multiple_git_syncs_containers.snap b/crates/stackable-operator/src/crd/git_sync/snapshots/stackable_operator__crd__git_sync__v1alpha1_impl__tests__multiple_git_syncs_containers.snap new file mode 100644 index 000000000..686f34002 --- /dev/null +++ b/crates/stackable-operator/src/crd/git_sync/snapshots/stackable_operator__crd__git_sync__v1alpha1_impl__tests__multiple_git_syncs_containers.snap @@ -0,0 +1,216 @@ +--- +source: crates/stackable-operator/src/crd/git_sync/v1alpha1_impl.rs +expression: "serde_yaml::to_string(&git_sync_resources.git_sync_containers).unwrap()" +--- +- args: + - |- + mkdir --parents /stackable/log/git-sync-0 && exec > >(tee /stackable/log/git-sync-0/container.stdout.log) 2> >(tee /stackable/log/git-sync-0/container.stderr.log >&2) + + prepare_signal_handlers() + { + unset term_child_pid + unset term_kill_needed + trap 'handle_term_signal' TERM + } + + handle_term_signal() + { + if [ -n "${term_child_pid:-}" ]; then + kill -TERM "${term_child_pid}" 2>/dev/null + else + term_kill_needed="yes" + fi + } + + wait_for_termination() + { + set +e + term_child_pid=$1 + if [[ -v term_kill_needed ]]; then + kill -TERM "${term_child_pid}" 2>/dev/null + fi + wait ${term_child_pid} 2>/dev/null + term_child_status=$? + trap - TERM + if [ "${term_child_status}" -gt 128 ]; then + wait ${term_child_pid} 2>/dev/null + term_child_status=$? + fi + set -e + return ${term_child_status} + } + + prepare_signal_handlers + /stackable/git-sync --depth=1 --git-config='safe.directory:/tmp/git' --link=current --one-time=false --period=20s --ref=main --repo=https://github.com/stackabletech/repo1 --root=/tmp/git & + wait_for_termination $! + command: + - /bin/bash + - -x + - -euo + - pipefail + - -c + env: + - name: GITSYNC_USERNAME + value: overridden-username + - name: VAR1 + value: value1 + image: oci.stackable.tech/sdp/product:latest + imagePullPolicy: Always + name: git-sync-0 + resources: + limits: + cpu: 200m + memory: 64Mi + requests: + cpu: 100m + memory: 64Mi + volumeMounts: + - mountPath: /tmp/git + name: content-from-git-0 + - mountPath: /stackable/log + name: log-volume + - mountPath: /mnt/extra-volume + name: extra-volume +- args: + - |- + mkdir --parents /stackable/log/git-sync-1 && exec > >(tee /stackable/log/git-sync-1/container.stdout.log) 2> >(tee /stackable/log/git-sync-1/container.stderr.log >&2) + + prepare_signal_handlers() + { + unset term_child_pid + unset term_kill_needed + trap 'handle_term_signal' TERM + } + + handle_term_signal() + { + if [ -n "${term_child_pid:-}" ]; then + kill -TERM "${term_child_pid}" 2>/dev/null + else + term_kill_needed="yes" + fi + } + + wait_for_termination() + { + set +e + term_child_pid=$1 + if [[ -v term_kill_needed ]]; then + kill -TERM "${term_child_pid}" 2>/dev/null + fi + wait ${term_child_pid} 2>/dev/null + term_child_status=$? + trap - TERM + if [ "${term_child_status}" -gt 128 ]; then + wait ${term_child_pid} 2>/dev/null + term_child_status=$? + fi + set -e + return ${term_child_status} + } + + prepare_signal_handlers + /stackable/git-sync --depth=3 --git-config='safe.directory:/tmp/git,http.sslCAInfo:/tmp/ca-cert/ca.crt' --link=current --one-time=false --period=60s --ref=trunk --repo=https://github.com/stackabletech/repo2 --rev=HEAD --root=/tmp/git & + wait_for_termination $! + command: + - /bin/bash + - -x + - -euo + - pipefail + - -c + env: + - name: GITSYNC_PASSWORD + valueFrom: + secretKeyRef: + key: password + name: git-credentials + - name: GITSYNC_USERNAME + value: overridden-username + - name: VAR1 + value: value1 + image: oci.stackable.tech/sdp/product:latest + imagePullPolicy: Always + name: git-sync-1 + resources: + limits: + cpu: 200m + memory: 64Mi + requests: + cpu: 100m + memory: 64Mi + volumeMounts: + - mountPath: /tmp/git + name: content-from-git-1 + - mountPath: /stackable/log + name: log-volume + - mountPath: /mnt/extra-volume + name: extra-volume +- args: + - |- + mkdir --parents /stackable/log/git-sync-2 && exec > >(tee /stackable/log/git-sync-2/container.stdout.log) 2> >(tee /stackable/log/git-sync-2/container.stderr.log >&2) + + prepare_signal_handlers() + { + unset term_child_pid + unset term_kill_needed + trap 'handle_term_signal' TERM + } + + handle_term_signal() + { + if [ -n "${term_child_pid:-}" ]; then + kill -TERM "${term_child_pid}" 2>/dev/null + else + term_kill_needed="yes" + fi + } + + wait_for_termination() + { + set +e + term_child_pid=$1 + if [[ -v term_kill_needed ]]; then + kill -TERM "${term_child_pid}" 2>/dev/null + fi + wait ${term_child_pid} 2>/dev/null + term_child_status=$? + trap - TERM + if [ "${term_child_status}" -gt 128 ]; then + wait ${term_child_pid} 2>/dev/null + term_child_status=$? + fi + set -e + return ${term_child_status} + } + + prepare_signal_handlers + /stackable/git-sync --depth=1 --git-config='safe.directory:/tmp/git,key:value,safe.directory:/safe-dir' --link=current --one-time=false --period=20s --ref=feat/git-sync --repo=https://github.com/stackabletech/repo3 --root=/tmp/git & + wait_for_termination $! + command: + - /bin/bash + - -x + - -euo + - pipefail + - -c + env: + - name: GITSYNC_USERNAME + value: overridden-username + - name: VAR1 + value: value1 + image: oci.stackable.tech/sdp/product:latest + imagePullPolicy: Always + name: git-sync-2 + resources: + limits: + cpu: 200m + memory: 64Mi + requests: + cpu: 100m + memory: 64Mi + volumeMounts: + - mountPath: /tmp/git + name: content-from-git-2 + - mountPath: /stackable/log + name: log-volume + - mountPath: /mnt/extra-volume + name: extra-volume diff --git a/crates/stackable-operator/src/crd/git_sync/snapshots/stackable_operator__crd__git_sync__v1alpha1_impl__tests__multiple_git_syncs_init_containers.snap b/crates/stackable-operator/src/crd/git_sync/snapshots/stackable_operator__crd__git_sync__v1alpha1_impl__tests__multiple_git_syncs_init_containers.snap new file mode 100644 index 000000000..91530caf5 --- /dev/null +++ b/crates/stackable-operator/src/crd/git_sync/snapshots/stackable_operator__crd__git_sync__v1alpha1_impl__tests__multiple_git_syncs_init_containers.snap @@ -0,0 +1,105 @@ +--- +source: crates/stackable-operator/src/crd/git_sync/v1alpha1_impl.rs +expression: "serde_yaml::to_string(&git_sync_resources.git_sync_init_containers).unwrap()" +--- +- args: + - |- + mkdir --parents /stackable/log/git-sync-0-init && exec > >(tee /stackable/log/git-sync-0-init/container.stdout.log) 2> >(tee /stackable/log/git-sync-0-init/container.stderr.log >&2) + /stackable/git-sync --depth=1 --git-config='safe.directory:/tmp/git' --link=current --one-time=true --period=20s --ref=main --repo=https://github.com/stackabletech/repo1 --root=/tmp/git + command: + - /bin/bash + - -x + - -euo + - pipefail + - -c + env: + - name: GITSYNC_USERNAME + value: overridden-username + - name: VAR1 + value: value1 + image: oci.stackable.tech/sdp/product:latest + imagePullPolicy: Always + name: git-sync-0-init + resources: + limits: + cpu: 200m + memory: 64Mi + requests: + cpu: 100m + memory: 64Mi + volumeMounts: + - mountPath: /tmp/git + name: content-from-git-0 + - mountPath: /stackable/log + name: log-volume + - mountPath: /mnt/extra-volume + name: extra-volume +- args: + - |- + mkdir --parents /stackable/log/git-sync-1-init && exec > >(tee /stackable/log/git-sync-1-init/container.stdout.log) 2> >(tee /stackable/log/git-sync-1-init/container.stderr.log >&2) + /stackable/git-sync --depth=3 --git-config='safe.directory:/tmp/git,http.sslCAInfo:/tmp/ca-cert/ca.crt' --link=current --one-time=true --period=60s --ref=trunk --repo=https://github.com/stackabletech/repo2 --rev=HEAD --root=/tmp/git + command: + - /bin/bash + - -x + - -euo + - pipefail + - -c + env: + - name: GITSYNC_PASSWORD + valueFrom: + secretKeyRef: + key: password + name: git-credentials + - name: GITSYNC_USERNAME + value: overridden-username + - name: VAR1 + value: value1 + image: oci.stackable.tech/sdp/product:latest + imagePullPolicy: Always + name: git-sync-1-init + resources: + limits: + cpu: 200m + memory: 64Mi + requests: + cpu: 100m + memory: 64Mi + volumeMounts: + - mountPath: /tmp/git + name: content-from-git-1 + - mountPath: /stackable/log + name: log-volume + - mountPath: /mnt/extra-volume + name: extra-volume +- args: + - |- + mkdir --parents /stackable/log/git-sync-2-init && exec > >(tee /stackable/log/git-sync-2-init/container.stdout.log) 2> >(tee /stackable/log/git-sync-2-init/container.stderr.log >&2) + /stackable/git-sync --depth=1 --git-config='safe.directory:/tmp/git,key:value,safe.directory:/safe-dir' --link=current --one-time=true --period=20s --ref=feat/git-sync --repo=https://github.com/stackabletech/repo3 --root=/tmp/git + command: + - /bin/bash + - -x + - -euo + - pipefail + - -c + env: + - name: GITSYNC_USERNAME + value: overridden-username + - name: VAR1 + value: value1 + image: oci.stackable.tech/sdp/product:latest + imagePullPolicy: Always + name: git-sync-2-init + resources: + limits: + cpu: 200m + memory: 64Mi + requests: + cpu: 100m + memory: 64Mi + volumeMounts: + - mountPath: /tmp/git + name: content-from-git-2 + - mountPath: /stackable/log + name: log-volume + - mountPath: /mnt/extra-volume + name: extra-volume diff --git a/crates/stackable-operator/src/crd/git_sync/snapshots/stackable_operator__crd__git_sync__v1alpha2_impl__tests__git_sync_ca_cert_containers.snap b/crates/stackable-operator/src/crd/git_sync/snapshots/stackable_operator__crd__git_sync__v1alpha2_impl__tests__git_sync_ca_cert_containers.snap new file mode 100644 index 000000000..5530066b6 --- /dev/null +++ b/crates/stackable-operator/src/crd/git_sync/snapshots/stackable_operator__crd__git_sync__v1alpha2_impl__tests__git_sync_ca_cert_containers.snap @@ -0,0 +1,73 @@ +--- +source: crates/stackable-operator/src/crd/git_sync/v1alpha2_impl.rs +expression: "serde_yaml::to_string(&git_sync_resources.git_sync_containers).unwrap()" +--- +- args: + - |- + mkdir --parents /stackable/log/git-sync-0 && exec > >(tee /stackable/log/git-sync-0/container.stdout.log) 2> >(tee /stackable/log/git-sync-0/container.stderr.log >&2) + + prepare_signal_handlers() + { + unset term_child_pid + unset term_kill_needed + trap 'handle_term_signal' TERM + } + + handle_term_signal() + { + if [ -n "${term_child_pid:-}" ]; then + kill -TERM "${term_child_pid}" 2>/dev/null + else + term_kill_needed="yes" + fi + } + + wait_for_termination() + { + set +e + term_child_pid=$1 + if [[ -v term_kill_needed ]]; then + kill -TERM "${term_child_pid}" 2>/dev/null + fi + wait ${term_child_pid} 2>/dev/null + term_child_status=$? + trap - TERM + if [ "${term_child_status}" -gt 128 ]; then + wait ${term_child_pid} 2>/dev/null + term_child_status=$? + fi + set -e + return ${term_child_status} + } + + prepare_signal_handlers + /stackable/git-sync --depth=3 --git-config='http.sslCAInfo:/stackable/gitca-0/ca.crt,safe.directory:/tmp/git' --link=current --one-time=false --period=60s --ref=trunk --repo=ssh://git@github.com/stackabletech/repo.git --rev=HEAD --root=/tmp/git & + wait_for_termination $! + command: + - /bin/bash + - -x + - -euo + - pipefail + - -c + env: + - name: VAR1 + value: value1 + image: oci.stackable.tech/sdp/product:latest + imagePullPolicy: Always + name: git-sync-0 + resources: + limits: + cpu: 200m + memory: 64Mi + requests: + cpu: 100m + memory: 64Mi + volumeMounts: + - mountPath: /tmp/git + name: content-from-git-0 + - mountPath: /stackable/log + name: log-volume + - mountPath: /mnt/extra-volume + name: extra-volume + - mountPath: /stackable/gitca-0 + name: ca-cert-0 diff --git a/crates/stackable-operator/src/crd/git_sync/snapshots/stackable_operator__crd__git_sync__v1alpha2_impl__tests__git_sync_ca_cert_init_containers.snap b/crates/stackable-operator/src/crd/git_sync/snapshots/stackable_operator__crd__git_sync__v1alpha2_impl__tests__git_sync_ca_cert_init_containers.snap new file mode 100644 index 000000000..e0f787ed1 --- /dev/null +++ b/crates/stackable-operator/src/crd/git_sync/snapshots/stackable_operator__crd__git_sync__v1alpha2_impl__tests__git_sync_ca_cert_init_containers.snap @@ -0,0 +1,36 @@ +--- +source: crates/stackable-operator/src/crd/git_sync/v1alpha2_impl.rs +expression: "serde_yaml::to_string(&git_sync_resources.git_sync_init_containers).unwrap()" +--- +- args: + - |- + mkdir --parents /stackable/log/git-sync-0-init && exec > >(tee /stackable/log/git-sync-0-init/container.stdout.log) 2> >(tee /stackable/log/git-sync-0-init/container.stderr.log >&2) + /stackable/git-sync --depth=3 --git-config='http.sslCAInfo:/stackable/gitca-0/ca.crt,safe.directory:/tmp/git' --link=current --one-time=true --period=60s --ref=trunk --repo=ssh://git@github.com/stackabletech/repo.git --rev=HEAD --root=/tmp/git + command: + - /bin/bash + - -x + - -euo + - pipefail + - -c + env: + - name: VAR1 + value: value1 + image: oci.stackable.tech/sdp/product:latest + imagePullPolicy: Always + name: git-sync-0-init + resources: + limits: + cpu: 200m + memory: 64Mi + requests: + cpu: 100m + memory: 64Mi + volumeMounts: + - mountPath: /tmp/git + name: content-from-git-0 + - mountPath: /stackable/log + name: log-volume + - mountPath: /mnt/extra-volume + name: extra-volume + - mountPath: /stackable/gitca-0 + name: ca-cert-0 diff --git a/crates/stackable-operator/src/crd/git_sync/snapshots/stackable_operator__crd__git_sync__v1alpha2_impl__tests__git_sync_ssh_containers.snap b/crates/stackable-operator/src/crd/git_sync/snapshots/stackable_operator__crd__git_sync__v1alpha2_impl__tests__git_sync_ssh_containers.snap new file mode 100644 index 000000000..2a19a5be4 --- /dev/null +++ b/crates/stackable-operator/src/crd/git_sync/snapshots/stackable_operator__crd__git_sync__v1alpha2_impl__tests__git_sync_ssh_containers.snap @@ -0,0 +1,77 @@ +--- +source: crates/stackable-operator/src/crd/git_sync/v1alpha2_impl.rs +expression: "serde_yaml::to_string(&git_sync_resources.git_sync_containers).unwrap()" +--- +- args: + - |- + mkdir --parents /stackable/log/git-sync-0 && exec > >(tee /stackable/log/git-sync-0/container.stdout.log) 2> >(tee /stackable/log/git-sync-0/container.stderr.log >&2) + + prepare_signal_handlers() + { + unset term_child_pid + unset term_kill_needed + trap 'handle_term_signal' TERM + } + + handle_term_signal() + { + if [ -n "${term_child_pid:-}" ]; then + kill -TERM "${term_child_pid}" 2>/dev/null + else + term_kill_needed="yes" + fi + } + + wait_for_termination() + { + set +e + term_child_pid=$1 + if [[ -v term_kill_needed ]]; then + kill -TERM "${term_child_pid}" 2>/dev/null + fi + wait ${term_child_pid} 2>/dev/null + term_child_status=$? + trap - TERM + if [ "${term_child_status}" -gt 128 ]; then + wait ${term_child_pid} 2>/dev/null + term_child_status=$? + fi + set -e + return ${term_child_status} + } + + prepare_signal_handlers + /stackable/git-sync --depth=3 --git-config='safe.directory:/tmp/git,http.sslCAInfo:/tmp/ca-cert/ca.crt' --link=current --one-time=false --period=60s --ref=trunk --repo=ssh://git@github.com/stackabletech/repo.git --rev=HEAD --root=/tmp/git & + wait_for_termination $! + command: + - /bin/bash + - -x + - -euo + - pipefail + - -c + env: + - name: GITSYNC_SSH_KEY_FILE + value: /stackable/gitssh-0/key + - name: GITSYNC_SSH_KNOWN_HOSTS_FILE + value: /stackable/gitssh-0/knownHosts + - name: VAR1 + value: value1 + image: oci.stackable.tech/sdp/product:latest + imagePullPolicy: Always + name: git-sync-0 + resources: + limits: + cpu: 200m + memory: 64Mi + requests: + cpu: 100m + memory: 64Mi + volumeMounts: + - mountPath: /tmp/git + name: content-from-git-0 + - mountPath: /stackable/log + name: log-volume + - mountPath: /mnt/extra-volume + name: extra-volume + - mountPath: /stackable/gitssh-0 + name: ssh-keys-info-0 diff --git a/crates/stackable-operator/src/crd/git_sync/snapshots/stackable_operator__crd__git_sync__v1alpha2_impl__tests__git_sync_ssh_init_containers.snap b/crates/stackable-operator/src/crd/git_sync/snapshots/stackable_operator__crd__git_sync__v1alpha2_impl__tests__git_sync_ssh_init_containers.snap new file mode 100644 index 000000000..07698da0e --- /dev/null +++ b/crates/stackable-operator/src/crd/git_sync/snapshots/stackable_operator__crd__git_sync__v1alpha2_impl__tests__git_sync_ssh_init_containers.snap @@ -0,0 +1,40 @@ +--- +source: crates/stackable-operator/src/crd/git_sync/v1alpha2_impl.rs +expression: "serde_yaml::to_string(&git_sync_resources.git_sync_init_containers).unwrap()" +--- +- args: + - |- + mkdir --parents /stackable/log/git-sync-0-init && exec > >(tee /stackable/log/git-sync-0-init/container.stdout.log) 2> >(tee /stackable/log/git-sync-0-init/container.stderr.log >&2) + /stackable/git-sync --depth=3 --git-config='safe.directory:/tmp/git,http.sslCAInfo:/tmp/ca-cert/ca.crt' --link=current --one-time=true --period=60s --ref=trunk --repo=ssh://git@github.com/stackabletech/repo.git --rev=HEAD --root=/tmp/git + command: + - /bin/bash + - -x + - -euo + - pipefail + - -c + env: + - name: GITSYNC_SSH_KEY_FILE + value: /stackable/gitssh-0/key + - name: GITSYNC_SSH_KNOWN_HOSTS_FILE + value: /stackable/gitssh-0/knownHosts + - name: VAR1 + value: value1 + image: oci.stackable.tech/sdp/product:latest + imagePullPolicy: Always + name: git-sync-0-init + resources: + limits: + cpu: 200m + memory: 64Mi + requests: + cpu: 100m + memory: 64Mi + volumeMounts: + - mountPath: /tmp/git + name: content-from-git-0 + - mountPath: /stackable/log + name: log-volume + - mountPath: /mnt/extra-volume + name: extra-volume + - mountPath: /stackable/gitssh-0 + name: ssh-keys-info-0 diff --git a/crates/stackable-operator/src/crd/git_sync/snapshots/stackable_operator__crd__git_sync__v1alpha2_impl__tests__multiple_git_syncs_containers.snap b/crates/stackable-operator/src/crd/git_sync/snapshots/stackable_operator__crd__git_sync__v1alpha2_impl__tests__multiple_git_syncs_containers.snap new file mode 100644 index 000000000..3f174326b --- /dev/null +++ b/crates/stackable-operator/src/crd/git_sync/snapshots/stackable_operator__crd__git_sync__v1alpha2_impl__tests__multiple_git_syncs_containers.snap @@ -0,0 +1,216 @@ +--- +source: crates/stackable-operator/src/crd/git_sync/v1alpha2_impl.rs +expression: "serde_yaml::to_string(&git_sync_resources.git_sync_containers).unwrap()" +--- +- args: + - |- + mkdir --parents /stackable/log/git-sync-0 && exec > >(tee /stackable/log/git-sync-0/container.stdout.log) 2> >(tee /stackable/log/git-sync-0/container.stderr.log >&2) + + prepare_signal_handlers() + { + unset term_child_pid + unset term_kill_needed + trap 'handle_term_signal' TERM + } + + handle_term_signal() + { + if [ -n "${term_child_pid:-}" ]; then + kill -TERM "${term_child_pid}" 2>/dev/null + else + term_kill_needed="yes" + fi + } + + wait_for_termination() + { + set +e + term_child_pid=$1 + if [[ -v term_kill_needed ]]; then + kill -TERM "${term_child_pid}" 2>/dev/null + fi + wait ${term_child_pid} 2>/dev/null + term_child_status=$? + trap - TERM + if [ "${term_child_status}" -gt 128 ]; then + wait ${term_child_pid} 2>/dev/null + term_child_status=$? + fi + set -e + return ${term_child_status} + } + + prepare_signal_handlers + /stackable/git-sync --depth=1 --git-config='safe.directory:/tmp/git' --link=current --one-time=false --period=20s --ref=main --repo=https://github.com/stackabletech/repo1 --root=/tmp/git & + wait_for_termination $! + command: + - /bin/bash + - -x + - -euo + - pipefail + - -c + env: + - name: GITSYNC_USERNAME + value: overridden-username + - name: VAR1 + value: value1 + image: oci.stackable.tech/sdp/product:latest + imagePullPolicy: Always + name: git-sync-0 + resources: + limits: + cpu: 200m + memory: 64Mi + requests: + cpu: 100m + memory: 64Mi + volumeMounts: + - mountPath: /tmp/git + name: content-from-git-0 + - mountPath: /stackable/log + name: log-volume + - mountPath: /mnt/extra-volume + name: extra-volume +- args: + - |- + mkdir --parents /stackable/log/git-sync-1 && exec > >(tee /stackable/log/git-sync-1/container.stdout.log) 2> >(tee /stackable/log/git-sync-1/container.stderr.log >&2) + + prepare_signal_handlers() + { + unset term_child_pid + unset term_kill_needed + trap 'handle_term_signal' TERM + } + + handle_term_signal() + { + if [ -n "${term_child_pid:-}" ]; then + kill -TERM "${term_child_pid}" 2>/dev/null + else + term_kill_needed="yes" + fi + } + + wait_for_termination() + { + set +e + term_child_pid=$1 + if [[ -v term_kill_needed ]]; then + kill -TERM "${term_child_pid}" 2>/dev/null + fi + wait ${term_child_pid} 2>/dev/null + term_child_status=$? + trap - TERM + if [ "${term_child_status}" -gt 128 ]; then + wait ${term_child_pid} 2>/dev/null + term_child_status=$? + fi + set -e + return ${term_child_status} + } + + prepare_signal_handlers + /stackable/git-sync --depth=3 --git-config='safe.directory:/tmp/git,http.sslCAInfo:/tmp/ca-cert/ca.crt' --link=current --one-time=false --period=60s --ref=trunk --repo=https://github.com/stackabletech/repo2 --rev=HEAD --root=/tmp/git & + wait_for_termination $! + command: + - /bin/bash + - -x + - -euo + - pipefail + - -c + env: + - name: GITSYNC_PASSWORD + valueFrom: + secretKeyRef: + key: password + name: git-credentials + - name: GITSYNC_USERNAME + value: overridden-username + - name: VAR1 + value: value1 + image: oci.stackable.tech/sdp/product:latest + imagePullPolicy: Always + name: git-sync-1 + resources: + limits: + cpu: 200m + memory: 64Mi + requests: + cpu: 100m + memory: 64Mi + volumeMounts: + - mountPath: /tmp/git + name: content-from-git-1 + - mountPath: /stackable/log + name: log-volume + - mountPath: /mnt/extra-volume + name: extra-volume +- args: + - |- + mkdir --parents /stackable/log/git-sync-2 && exec > >(tee /stackable/log/git-sync-2/container.stdout.log) 2> >(tee /stackable/log/git-sync-2/container.stderr.log >&2) + + prepare_signal_handlers() + { + unset term_child_pid + unset term_kill_needed + trap 'handle_term_signal' TERM + } + + handle_term_signal() + { + if [ -n "${term_child_pid:-}" ]; then + kill -TERM "${term_child_pid}" 2>/dev/null + else + term_kill_needed="yes" + fi + } + + wait_for_termination() + { + set +e + term_child_pid=$1 + if [[ -v term_kill_needed ]]; then + kill -TERM "${term_child_pid}" 2>/dev/null + fi + wait ${term_child_pid} 2>/dev/null + term_child_status=$? + trap - TERM + if [ "${term_child_status}" -gt 128 ]; then + wait ${term_child_pid} 2>/dev/null + term_child_status=$? + fi + set -e + return ${term_child_status} + } + + prepare_signal_handlers + /stackable/git-sync --depth=1 --git-config='safe.directory:/tmp/git,key:value,safe.directory:/safe-dir' --link=current --one-time=false --period=20s --ref=feat/git-sync --repo=https://github.com/stackabletech/repo3 --root=/tmp/git & + wait_for_termination $! + command: + - /bin/bash + - -x + - -euo + - pipefail + - -c + env: + - name: GITSYNC_USERNAME + value: overridden-username + - name: VAR1 + value: value1 + image: oci.stackable.tech/sdp/product:latest + imagePullPolicy: Always + name: git-sync-2 + resources: + limits: + cpu: 200m + memory: 64Mi + requests: + cpu: 100m + memory: 64Mi + volumeMounts: + - mountPath: /tmp/git + name: content-from-git-2 + - mountPath: /stackable/log + name: log-volume + - mountPath: /mnt/extra-volume + name: extra-volume diff --git a/crates/stackable-operator/src/crd/git_sync/snapshots/stackable_operator__crd__git_sync__v1alpha2_impl__tests__multiple_git_syncs_init_containers.snap b/crates/stackable-operator/src/crd/git_sync/snapshots/stackable_operator__crd__git_sync__v1alpha2_impl__tests__multiple_git_syncs_init_containers.snap new file mode 100644 index 000000000..bb2d6c5ee --- /dev/null +++ b/crates/stackable-operator/src/crd/git_sync/snapshots/stackable_operator__crd__git_sync__v1alpha2_impl__tests__multiple_git_syncs_init_containers.snap @@ -0,0 +1,105 @@ +--- +source: crates/stackable-operator/src/crd/git_sync/v1alpha2_impl.rs +expression: "serde_yaml::to_string(&git_sync_resources.git_sync_init_containers).unwrap()" +--- +- args: + - |- + mkdir --parents /stackable/log/git-sync-0-init && exec > >(tee /stackable/log/git-sync-0-init/container.stdout.log) 2> >(tee /stackable/log/git-sync-0-init/container.stderr.log >&2) + /stackable/git-sync --depth=1 --git-config='safe.directory:/tmp/git' --link=current --one-time=true --period=20s --ref=main --repo=https://github.com/stackabletech/repo1 --root=/tmp/git + command: + - /bin/bash + - -x + - -euo + - pipefail + - -c + env: + - name: GITSYNC_USERNAME + value: overridden-username + - name: VAR1 + value: value1 + image: oci.stackable.tech/sdp/product:latest + imagePullPolicy: Always + name: git-sync-0-init + resources: + limits: + cpu: 200m + memory: 64Mi + requests: + cpu: 100m + memory: 64Mi + volumeMounts: + - mountPath: /tmp/git + name: content-from-git-0 + - mountPath: /stackable/log + name: log-volume + - mountPath: /mnt/extra-volume + name: extra-volume +- args: + - |- + mkdir --parents /stackable/log/git-sync-1-init && exec > >(tee /stackable/log/git-sync-1-init/container.stdout.log) 2> >(tee /stackable/log/git-sync-1-init/container.stderr.log >&2) + /stackable/git-sync --depth=3 --git-config='safe.directory:/tmp/git,http.sslCAInfo:/tmp/ca-cert/ca.crt' --link=current --one-time=true --period=60s --ref=trunk --repo=https://github.com/stackabletech/repo2 --rev=HEAD --root=/tmp/git + command: + - /bin/bash + - -x + - -euo + - pipefail + - -c + env: + - name: GITSYNC_PASSWORD + valueFrom: + secretKeyRef: + key: password + name: git-credentials + - name: GITSYNC_USERNAME + value: overridden-username + - name: VAR1 + value: value1 + image: oci.stackable.tech/sdp/product:latest + imagePullPolicy: Always + name: git-sync-1-init + resources: + limits: + cpu: 200m + memory: 64Mi + requests: + cpu: 100m + memory: 64Mi + volumeMounts: + - mountPath: /tmp/git + name: content-from-git-1 + - mountPath: /stackable/log + name: log-volume + - mountPath: /mnt/extra-volume + name: extra-volume +- args: + - |- + mkdir --parents /stackable/log/git-sync-2-init && exec > >(tee /stackable/log/git-sync-2-init/container.stdout.log) 2> >(tee /stackable/log/git-sync-2-init/container.stderr.log >&2) + /stackable/git-sync --depth=1 --git-config='safe.directory:/tmp/git,key:value,safe.directory:/safe-dir' --link=current --one-time=true --period=20s --ref=feat/git-sync --repo=https://github.com/stackabletech/repo3 --root=/tmp/git + command: + - /bin/bash + - -x + - -euo + - pipefail + - -c + env: + - name: GITSYNC_USERNAME + value: overridden-username + - name: VAR1 + value: value1 + image: oci.stackable.tech/sdp/product:latest + imagePullPolicy: Always + name: git-sync-2-init + resources: + limits: + cpu: 200m + memory: 64Mi + requests: + cpu: 100m + memory: 64Mi + volumeMounts: + - mountPath: /tmp/git + name: content-from-git-2 + - mountPath: /stackable/log + name: log-volume + - mountPath: /mnt/extra-volume + name: extra-volume diff --git a/crates/stackable-operator/src/crd/git_sync/v1alpha1_impl.rs b/crates/stackable-operator/src/crd/git_sync/v1alpha1_impl.rs index a85a4ddbd..c4bcfbc37 100644 --- a/crates/stackable-operator/src/crd/git_sync/v1alpha1_impl.rs +++ b/crates/stackable-operator/src/crd/git_sync/v1alpha1_impl.rs @@ -484,349 +484,16 @@ mod tests { assert_eq!(3, git_sync_resources.git_sync_containers.len()); - assert_eq!( - r#"args: -- |- - mkdir --parents /stackable/log/git-sync-0 && exec > >(tee /stackable/log/git-sync-0/container.stdout.log) 2> >(tee /stackable/log/git-sync-0/container.stderr.log >&2) - - prepare_signal_handlers() - { - unset term_child_pid - unset term_kill_needed - trap 'handle_term_signal' TERM - } - - handle_term_signal() - { - if [ -n "${term_child_pid:-}" ]; then - kill -TERM "${term_child_pid}" 2>/dev/null - else - term_kill_needed="yes" - fi - } - - wait_for_termination() - { - set +e - term_child_pid=$1 - if [[ -v term_kill_needed ]]; then - kill -TERM "${term_child_pid}" 2>/dev/null - fi - wait ${term_child_pid} 2>/dev/null - term_child_status=$? - trap - TERM - if [ "${term_child_status}" -gt 128 ]; then - wait ${term_child_pid} 2>/dev/null - term_child_status=$? - fi - set -e - return ${term_child_status} - } - - prepare_signal_handlers - /stackable/git-sync --depth=1 --git-config='safe.directory:/tmp/git' --link=current --one-time=false --period=20s --ref=main --repo=https://github.com/stackabletech/repo1 --root=/tmp/git & - wait_for_termination $! -command: -- /bin/bash -- -x -- -euo -- pipefail -- -c -env: -- name: GITSYNC_USERNAME - value: overridden-username -- name: VAR1 - value: value1 -image: oci.stackable.tech/sdp/product:latest -imagePullPolicy: Always -name: git-sync-0 -resources: - limits: - cpu: 200m - memory: 64Mi - requests: - cpu: 100m - memory: 64Mi -volumeMounts: -- mountPath: /tmp/git - name: content-from-git-0 -- mountPath: /stackable/log - name: log-volume -- mountPath: /mnt/extra-volume - name: extra-volume -"#, - yaml_serde::to_string(&git_sync_resources.git_sync_containers.first()).unwrap() - ); - - assert_eq!( - r#"args: -- |- - mkdir --parents /stackable/log/git-sync-1 && exec > >(tee /stackable/log/git-sync-1/container.stdout.log) 2> >(tee /stackable/log/git-sync-1/container.stderr.log >&2) - - prepare_signal_handlers() - { - unset term_child_pid - unset term_kill_needed - trap 'handle_term_signal' TERM - } - - handle_term_signal() - { - if [ -n "${term_child_pid:-}" ]; then - kill -TERM "${term_child_pid}" 2>/dev/null - else - term_kill_needed="yes" - fi - } - - wait_for_termination() - { - set +e - term_child_pid=$1 - if [[ -v term_kill_needed ]]; then - kill -TERM "${term_child_pid}" 2>/dev/null - fi - wait ${term_child_pid} 2>/dev/null - term_child_status=$? - trap - TERM - if [ "${term_child_status}" -gt 128 ]; then - wait ${term_child_pid} 2>/dev/null - term_child_status=$? - fi - set -e - return ${term_child_status} - } - - prepare_signal_handlers - /stackable/git-sync --depth=3 --git-config='safe.directory:/tmp/git,http.sslCAInfo:/tmp/ca-cert/ca.crt' --link=current --one-time=false --period=60s --ref=trunk --repo=https://github.com/stackabletech/repo2 --rev=HEAD --root=/tmp/git & - wait_for_termination $! -command: -- /bin/bash -- -x -- -euo -- pipefail -- -c -env: -- name: GITSYNC_PASSWORD - valueFrom: - secretKeyRef: - key: password - name: git-credentials -- name: GITSYNC_USERNAME - value: overridden-username -- name: VAR1 - value: value1 -image: oci.stackable.tech/sdp/product:latest -imagePullPolicy: Always -name: git-sync-1 -resources: - limits: - cpu: 200m - memory: 64Mi - requests: - cpu: 100m - memory: 64Mi -volumeMounts: -- mountPath: /tmp/git - name: content-from-git-1 -- mountPath: /stackable/log - name: log-volume -- mountPath: /mnt/extra-volume - name: extra-volume -"#, - yaml_serde::to_string(&git_sync_resources.git_sync_containers.get(1)).unwrap() - ); - - assert_eq!( - r#"args: -- |- - mkdir --parents /stackable/log/git-sync-2 && exec > >(tee /stackable/log/git-sync-2/container.stdout.log) 2> >(tee /stackable/log/git-sync-2/container.stderr.log >&2) - - prepare_signal_handlers() - { - unset term_child_pid - unset term_kill_needed - trap 'handle_term_signal' TERM - } - - handle_term_signal() - { - if [ -n "${term_child_pid:-}" ]; then - kill -TERM "${term_child_pid}" 2>/dev/null - else - term_kill_needed="yes" - fi - } - - wait_for_termination() - { - set +e - term_child_pid=$1 - if [[ -v term_kill_needed ]]; then - kill -TERM "${term_child_pid}" 2>/dev/null - fi - wait ${term_child_pid} 2>/dev/null - term_child_status=$? - trap - TERM - if [ "${term_child_status}" -gt 128 ]; then - wait ${term_child_pid} 2>/dev/null - term_child_status=$? - fi - set -e - return ${term_child_status} - } - - prepare_signal_handlers - /stackable/git-sync --depth=1 --git-config='safe.directory:/tmp/git,key:value,safe.directory:/safe-dir' --link=current --one-time=false --period=20s --ref=feat/git-sync --repo=https://github.com/stackabletech/repo3 --root=/tmp/git & - wait_for_termination $! -command: -- /bin/bash -- -x -- -euo -- pipefail -- -c -env: -- name: GITSYNC_USERNAME - value: overridden-username -- name: VAR1 - value: value1 -image: oci.stackable.tech/sdp/product:latest -imagePullPolicy: Always -name: git-sync-2 -resources: - limits: - cpu: 200m - memory: 64Mi - requests: - cpu: 100m - memory: 64Mi -volumeMounts: -- mountPath: /tmp/git - name: content-from-git-2 -- mountPath: /stackable/log - name: log-volume -- mountPath: /mnt/extra-volume - name: extra-volume -"#, - yaml_serde::to_string(&git_sync_resources.git_sync_containers.get(2)).unwrap() + insta::assert_snapshot!( + "multiple_git_syncs_containers", + yaml_serde::to_string(&git_sync_resources.git_sync_containers).unwrap() ); assert_eq!(3, git_sync_resources.git_sync_init_containers.len()); - assert_eq!( - r"args: -- |- - mkdir --parents /stackable/log/git-sync-0-init && exec > >(tee /stackable/log/git-sync-0-init/container.stdout.log) 2> >(tee /stackable/log/git-sync-0-init/container.stderr.log >&2) - /stackable/git-sync --depth=1 --git-config='safe.directory:/tmp/git' --link=current --one-time=true --period=20s --ref=main --repo=https://github.com/stackabletech/repo1 --root=/tmp/git -command: -- /bin/bash -- -x -- -euo -- pipefail -- -c -env: -- name: GITSYNC_USERNAME - value: overridden-username -- name: VAR1 - value: value1 -image: oci.stackable.tech/sdp/product:latest -imagePullPolicy: Always -name: git-sync-0-init -resources: - limits: - cpu: 200m - memory: 64Mi - requests: - cpu: 100m - memory: 64Mi -volumeMounts: -- mountPath: /tmp/git - name: content-from-git-0 -- mountPath: /stackable/log - name: log-volume -- mountPath: /mnt/extra-volume - name: extra-volume -", - yaml_serde::to_string(&git_sync_resources.git_sync_init_containers.first()).unwrap() - ); - - assert_eq!( - r"args: -- |- - mkdir --parents /stackable/log/git-sync-1-init && exec > >(tee /stackable/log/git-sync-1-init/container.stdout.log) 2> >(tee /stackable/log/git-sync-1-init/container.stderr.log >&2) - /stackable/git-sync --depth=3 --git-config='safe.directory:/tmp/git,http.sslCAInfo:/tmp/ca-cert/ca.crt' --link=current --one-time=true --period=60s --ref=trunk --repo=https://github.com/stackabletech/repo2 --rev=HEAD --root=/tmp/git -command: -- /bin/bash -- -x -- -euo -- pipefail -- -c -env: -- name: GITSYNC_PASSWORD - valueFrom: - secretKeyRef: - key: password - name: git-credentials -- name: GITSYNC_USERNAME - value: overridden-username -- name: VAR1 - value: value1 -image: oci.stackable.tech/sdp/product:latest -imagePullPolicy: Always -name: git-sync-1-init -resources: - limits: - cpu: 200m - memory: 64Mi - requests: - cpu: 100m - memory: 64Mi -volumeMounts: -- mountPath: /tmp/git - name: content-from-git-1 -- mountPath: /stackable/log - name: log-volume -- mountPath: /mnt/extra-volume - name: extra-volume -", - yaml_serde::to_string(&git_sync_resources.git_sync_init_containers.get(1)).unwrap() - ); - - assert_eq!( - r"args: -- |- - mkdir --parents /stackable/log/git-sync-2-init && exec > >(tee /stackable/log/git-sync-2-init/container.stdout.log) 2> >(tee /stackable/log/git-sync-2-init/container.stderr.log >&2) - /stackable/git-sync --depth=1 --git-config='safe.directory:/tmp/git,key:value,safe.directory:/safe-dir' --link=current --one-time=true --period=20s --ref=feat/git-sync --repo=https://github.com/stackabletech/repo3 --root=/tmp/git -command: -- /bin/bash -- -x -- -euo -- pipefail -- -c -env: -- name: GITSYNC_USERNAME - value: overridden-username -- name: VAR1 - value: value1 -image: oci.stackable.tech/sdp/product:latest -imagePullPolicy: Always -name: git-sync-2-init -resources: - limits: - cpu: 200m - memory: 64Mi - requests: - cpu: 100m - memory: 64Mi -volumeMounts: -- mountPath: /tmp/git - name: content-from-git-2 -- mountPath: /stackable/log - name: log-volume -- mountPath: /mnt/extra-volume - name: extra-volume -", - yaml_serde::to_string(&git_sync_resources.git_sync_init_containers.get(2)).unwrap() + insta::assert_snapshot!( + "multiple_git_syncs_init_containers", + yaml_serde::to_string(&git_sync_resources.git_sync_init_containers).unwrap() ); assert_eq!(3, git_sync_resources.git_content_volumes.len()); diff --git a/crates/stackable-operator/src/crd/git_sync/v1alpha2_impl.rs b/crates/stackable-operator/src/crd/git_sync/v1alpha2_impl.rs index 3adf0d8c4..ea461ecb6 100644 --- a/crates/stackable-operator/src/crd/git_sync/v1alpha2_impl.rs +++ b/crates/stackable-operator/src/crd/git_sync/v1alpha2_impl.rs @@ -615,349 +615,16 @@ mod tests { assert_eq!(3, git_sync_resources.git_sync_containers.len()); - assert_eq!( - r#"args: -- |- - mkdir --parents /stackable/log/git-sync-0 && exec > >(tee /stackable/log/git-sync-0/container.stdout.log) 2> >(tee /stackable/log/git-sync-0/container.stderr.log >&2) - - prepare_signal_handlers() - { - unset term_child_pid - unset term_kill_needed - trap 'handle_term_signal' TERM - } - - handle_term_signal() - { - if [ -n "${term_child_pid:-}" ]; then - kill -TERM "${term_child_pid}" 2>/dev/null - else - term_kill_needed="yes" - fi - } - - wait_for_termination() - { - set +e - term_child_pid=$1 - if [[ -v term_kill_needed ]]; then - kill -TERM "${term_child_pid}" 2>/dev/null - fi - wait ${term_child_pid} 2>/dev/null - term_child_status=$? - trap - TERM - if [ "${term_child_status}" -gt 128 ]; then - wait ${term_child_pid} 2>/dev/null - term_child_status=$? - fi - set -e - return ${term_child_status} - } - - prepare_signal_handlers - /stackable/git-sync --depth=1 --git-config='safe.directory:/tmp/git' --link=current --one-time=false --period=20s --ref=main --repo=https://github.com/stackabletech/repo1 --root=/tmp/git & - wait_for_termination $! -command: -- /bin/bash -- -x -- -euo -- pipefail -- -c -env: -- name: GITSYNC_USERNAME - value: overridden-username -- name: VAR1 - value: value1 -image: oci.stackable.tech/sdp/product:latest -imagePullPolicy: Always -name: git-sync-0 -resources: - limits: - cpu: 200m - memory: 64Mi - requests: - cpu: 100m - memory: 64Mi -volumeMounts: -- mountPath: /tmp/git - name: content-from-git-0 -- mountPath: /stackable/log - name: log-volume -- mountPath: /mnt/extra-volume - name: extra-volume -"#, - yaml_serde::to_string(&git_sync_resources.git_sync_containers.first()).unwrap() - ); - - assert_eq!( - r#"args: -- |- - mkdir --parents /stackable/log/git-sync-1 && exec > >(tee /stackable/log/git-sync-1/container.stdout.log) 2> >(tee /stackable/log/git-sync-1/container.stderr.log >&2) - - prepare_signal_handlers() - { - unset term_child_pid - unset term_kill_needed - trap 'handle_term_signal' TERM - } - - handle_term_signal() - { - if [ -n "${term_child_pid:-}" ]; then - kill -TERM "${term_child_pid}" 2>/dev/null - else - term_kill_needed="yes" - fi - } - - wait_for_termination() - { - set +e - term_child_pid=$1 - if [[ -v term_kill_needed ]]; then - kill -TERM "${term_child_pid}" 2>/dev/null - fi - wait ${term_child_pid} 2>/dev/null - term_child_status=$? - trap - TERM - if [ "${term_child_status}" -gt 128 ]; then - wait ${term_child_pid} 2>/dev/null - term_child_status=$? - fi - set -e - return ${term_child_status} - } - - prepare_signal_handlers - /stackable/git-sync --depth=3 --git-config='safe.directory:/tmp/git,http.sslCAInfo:/tmp/ca-cert/ca.crt' --link=current --one-time=false --period=60s --ref=trunk --repo=https://github.com/stackabletech/repo2 --rev=HEAD --root=/tmp/git & - wait_for_termination $! -command: -- /bin/bash -- -x -- -euo -- pipefail -- -c -env: -- name: GITSYNC_PASSWORD - valueFrom: - secretKeyRef: - key: password - name: git-credentials -- name: GITSYNC_USERNAME - value: overridden-username -- name: VAR1 - value: value1 -image: oci.stackable.tech/sdp/product:latest -imagePullPolicy: Always -name: git-sync-1 -resources: - limits: - cpu: 200m - memory: 64Mi - requests: - cpu: 100m - memory: 64Mi -volumeMounts: -- mountPath: /tmp/git - name: content-from-git-1 -- mountPath: /stackable/log - name: log-volume -- mountPath: /mnt/extra-volume - name: extra-volume -"#, - yaml_serde::to_string(&git_sync_resources.git_sync_containers.get(1)).unwrap() - ); - - assert_eq!( - r#"args: -- |- - mkdir --parents /stackable/log/git-sync-2 && exec > >(tee /stackable/log/git-sync-2/container.stdout.log) 2> >(tee /stackable/log/git-sync-2/container.stderr.log >&2) - - prepare_signal_handlers() - { - unset term_child_pid - unset term_kill_needed - trap 'handle_term_signal' TERM - } - - handle_term_signal() - { - if [ -n "${term_child_pid:-}" ]; then - kill -TERM "${term_child_pid}" 2>/dev/null - else - term_kill_needed="yes" - fi - } - - wait_for_termination() - { - set +e - term_child_pid=$1 - if [[ -v term_kill_needed ]]; then - kill -TERM "${term_child_pid}" 2>/dev/null - fi - wait ${term_child_pid} 2>/dev/null - term_child_status=$? - trap - TERM - if [ "${term_child_status}" -gt 128 ]; then - wait ${term_child_pid} 2>/dev/null - term_child_status=$? - fi - set -e - return ${term_child_status} - } - - prepare_signal_handlers - /stackable/git-sync --depth=1 --git-config='safe.directory:/tmp/git,key:value,safe.directory:/safe-dir' --link=current --one-time=false --period=20s --ref=feat/git-sync --repo=https://github.com/stackabletech/repo3 --root=/tmp/git & - wait_for_termination $! -command: -- /bin/bash -- -x -- -euo -- pipefail -- -c -env: -- name: GITSYNC_USERNAME - value: overridden-username -- name: VAR1 - value: value1 -image: oci.stackable.tech/sdp/product:latest -imagePullPolicy: Always -name: git-sync-2 -resources: - limits: - cpu: 200m - memory: 64Mi - requests: - cpu: 100m - memory: 64Mi -volumeMounts: -- mountPath: /tmp/git - name: content-from-git-2 -- mountPath: /stackable/log - name: log-volume -- mountPath: /mnt/extra-volume - name: extra-volume -"#, - yaml_serde::to_string(&git_sync_resources.git_sync_containers.get(2)).unwrap() + insta::assert_snapshot!( + "multiple_git_syncs_containers", + yaml_serde::to_string(&git_sync_resources.git_sync_containers).unwrap() ); assert_eq!(3, git_sync_resources.git_sync_init_containers.len()); - assert_eq!( - r"args: -- |- - mkdir --parents /stackable/log/git-sync-0-init && exec > >(tee /stackable/log/git-sync-0-init/container.stdout.log) 2> >(tee /stackable/log/git-sync-0-init/container.stderr.log >&2) - /stackable/git-sync --depth=1 --git-config='safe.directory:/tmp/git' --link=current --one-time=true --period=20s --ref=main --repo=https://github.com/stackabletech/repo1 --root=/tmp/git -command: -- /bin/bash -- -x -- -euo -- pipefail -- -c -env: -- name: GITSYNC_USERNAME - value: overridden-username -- name: VAR1 - value: value1 -image: oci.stackable.tech/sdp/product:latest -imagePullPolicy: Always -name: git-sync-0-init -resources: - limits: - cpu: 200m - memory: 64Mi - requests: - cpu: 100m - memory: 64Mi -volumeMounts: -- mountPath: /tmp/git - name: content-from-git-0 -- mountPath: /stackable/log - name: log-volume -- mountPath: /mnt/extra-volume - name: extra-volume -", - yaml_serde::to_string(&git_sync_resources.git_sync_init_containers.first()).unwrap() - ); - - assert_eq!( - r"args: -- |- - mkdir --parents /stackable/log/git-sync-1-init && exec > >(tee /stackable/log/git-sync-1-init/container.stdout.log) 2> >(tee /stackable/log/git-sync-1-init/container.stderr.log >&2) - /stackable/git-sync --depth=3 --git-config='safe.directory:/tmp/git,http.sslCAInfo:/tmp/ca-cert/ca.crt' --link=current --one-time=true --period=60s --ref=trunk --repo=https://github.com/stackabletech/repo2 --rev=HEAD --root=/tmp/git -command: -- /bin/bash -- -x -- -euo -- pipefail -- -c -env: -- name: GITSYNC_PASSWORD - valueFrom: - secretKeyRef: - key: password - name: git-credentials -- name: GITSYNC_USERNAME - value: overridden-username -- name: VAR1 - value: value1 -image: oci.stackable.tech/sdp/product:latest -imagePullPolicy: Always -name: git-sync-1-init -resources: - limits: - cpu: 200m - memory: 64Mi - requests: - cpu: 100m - memory: 64Mi -volumeMounts: -- mountPath: /tmp/git - name: content-from-git-1 -- mountPath: /stackable/log - name: log-volume -- mountPath: /mnt/extra-volume - name: extra-volume -", - yaml_serde::to_string(&git_sync_resources.git_sync_init_containers.get(1)).unwrap() - ); - - assert_eq!( - r"args: -- |- - mkdir --parents /stackable/log/git-sync-2-init && exec > >(tee /stackable/log/git-sync-2-init/container.stdout.log) 2> >(tee /stackable/log/git-sync-2-init/container.stderr.log >&2) - /stackable/git-sync --depth=1 --git-config='safe.directory:/tmp/git,key:value,safe.directory:/safe-dir' --link=current --one-time=true --period=20s --ref=feat/git-sync --repo=https://github.com/stackabletech/repo3 --root=/tmp/git -command: -- /bin/bash -- -x -- -euo -- pipefail -- -c -env: -- name: GITSYNC_USERNAME - value: overridden-username -- name: VAR1 - value: value1 -image: oci.stackable.tech/sdp/product:latest -imagePullPolicy: Always -name: git-sync-2-init -resources: - limits: - cpu: 200m - memory: 64Mi - requests: - cpu: 100m - memory: 64Mi -volumeMounts: -- mountPath: /tmp/git - name: content-from-git-2 -- mountPath: /stackable/log - name: log-volume -- mountPath: /mnt/extra-volume - name: extra-volume -", - yaml_serde::to_string(&git_sync_resources.git_sync_init_containers.get(2)).unwrap() + insta::assert_snapshot!( + "multiple_git_syncs_init_containers", + yaml_serde::to_string(&git_sync_resources.git_sync_init_containers).unwrap() ); assert_eq!(3, git_sync_resources.git_content_volumes.len()); @@ -1034,7 +701,6 @@ name: content-from-git-2 } #[test] - #[expect(clippy::too_many_lines)] fn test_git_sync_ssh() { let git_sync_spec = r#" # GitSync using SSH @@ -1085,125 +751,16 @@ name: content-from-git-2 assert_eq!(1, git_sync_resources.git_sync_containers.len()); - assert_eq!( - r#"args: -- |- - mkdir --parents /stackable/log/git-sync-0 && exec > >(tee /stackable/log/git-sync-0/container.stdout.log) 2> >(tee /stackable/log/git-sync-0/container.stderr.log >&2) - - prepare_signal_handlers() - { - unset term_child_pid - unset term_kill_needed - trap 'handle_term_signal' TERM - } - - handle_term_signal() - { - if [ -n "${term_child_pid:-}" ]; then - kill -TERM "${term_child_pid}" 2>/dev/null - else - term_kill_needed="yes" - fi - } - - wait_for_termination() - { - set +e - term_child_pid=$1 - if [[ -v term_kill_needed ]]; then - kill -TERM "${term_child_pid}" 2>/dev/null - fi - wait ${term_child_pid} 2>/dev/null - term_child_status=$? - trap - TERM - if [ "${term_child_status}" -gt 128 ]; then - wait ${term_child_pid} 2>/dev/null - term_child_status=$? - fi - set -e - return ${term_child_status} - } - - prepare_signal_handlers - /stackable/git-sync --depth=3 --git-config='safe.directory:/tmp/git,http.sslCAInfo:/tmp/ca-cert/ca.crt' --link=current --one-time=false --period=60s --ref=trunk --repo=ssh://git@github.com/stackabletech/repo.git --rev=HEAD --root=/tmp/git & - wait_for_termination $! -command: -- /bin/bash -- -x -- -euo -- pipefail -- -c -env: -- name: GITSYNC_SSH_KEY_FILE - value: /stackable/gitssh-0/key -- name: GITSYNC_SSH_KNOWN_HOSTS_FILE - value: /stackable/gitssh-0/knownHosts -- name: VAR1 - value: value1 -image: oci.stackable.tech/sdp/product:latest -imagePullPolicy: Always -name: git-sync-0 -resources: - limits: - cpu: 200m - memory: 64Mi - requests: - cpu: 100m - memory: 64Mi -volumeMounts: -- mountPath: /tmp/git - name: content-from-git-0 -- mountPath: /stackable/log - name: log-volume -- mountPath: /mnt/extra-volume - name: extra-volume -- mountPath: /stackable/gitssh-0 - name: ssh-keys-info-0 -"#, - yaml_serde::to_string(&git_sync_resources.git_sync_containers.first()).unwrap() + insta::assert_snapshot!( + "git_sync_ssh_containers", + yaml_serde::to_string(&git_sync_resources.git_sync_containers).unwrap() ); assert_eq!(1, git_sync_resources.git_sync_init_containers.len()); - assert_eq!( - r"args: -- |- - mkdir --parents /stackable/log/git-sync-0-init && exec > >(tee /stackable/log/git-sync-0-init/container.stdout.log) 2> >(tee /stackable/log/git-sync-0-init/container.stderr.log >&2) - /stackable/git-sync --depth=3 --git-config='safe.directory:/tmp/git,http.sslCAInfo:/tmp/ca-cert/ca.crt' --link=current --one-time=true --period=60s --ref=trunk --repo=ssh://git@github.com/stackabletech/repo.git --rev=HEAD --root=/tmp/git -command: -- /bin/bash -- -x -- -euo -- pipefail -- -c -env: -- name: GITSYNC_SSH_KEY_FILE - value: /stackable/gitssh-0/key -- name: GITSYNC_SSH_KNOWN_HOSTS_FILE - value: /stackable/gitssh-0/knownHosts -- name: VAR1 - value: value1 -image: oci.stackable.tech/sdp/product:latest -imagePullPolicy: Always -name: git-sync-0-init -resources: - limits: - cpu: 200m - memory: 64Mi - requests: - cpu: 100m - memory: 64Mi -volumeMounts: -- mountPath: /tmp/git - name: content-from-git-0 -- mountPath: /stackable/log - name: log-volume -- mountPath: /mnt/extra-volume - name: extra-volume -- mountPath: /stackable/gitssh-0 - name: ssh-keys-info-0 -", - yaml_serde::to_string(&git_sync_resources.git_sync_init_containers.first()).unwrap() + insta::assert_snapshot!( + "git_sync_ssh_init_containers", + yaml_serde::to_string(&git_sync_resources.git_sync_init_containers).unwrap() ); assert_eq!(1, git_sync_resources.git_content_volumes.len()); @@ -1247,7 +804,6 @@ secret: } #[test] - #[allow(clippy::too_many_lines)] fn test_git_sync_ca_cert() { let git_sync_spec = r#" # GitSync using SSH @@ -1300,117 +856,16 @@ secret: assert_eq!(1, git_sync_resources.git_sync_containers.len()); - assert_eq!( - r#"args: -- |- - mkdir --parents /stackable/log/git-sync-0 && exec > >(tee /stackable/log/git-sync-0/container.stdout.log) 2> >(tee /stackable/log/git-sync-0/container.stderr.log >&2) - - prepare_signal_handlers() - { - unset term_child_pid - unset term_kill_needed - trap 'handle_term_signal' TERM - } - - handle_term_signal() - { - if [ -n "${term_child_pid:-}" ]; then - kill -TERM "${term_child_pid}" 2>/dev/null - else - term_kill_needed="yes" - fi - } - - wait_for_termination() - { - set +e - term_child_pid=$1 - if [[ -v term_kill_needed ]]; then - kill -TERM "${term_child_pid}" 2>/dev/null - fi - wait ${term_child_pid} 2>/dev/null - term_child_status=$? - trap - TERM - if [ "${term_child_status}" -gt 128 ]; then - wait ${term_child_pid} 2>/dev/null - term_child_status=$? - fi - set -e - return ${term_child_status} - } - - prepare_signal_handlers - /stackable/git-sync --depth=3 --git-config='http.sslCAInfo:/stackable/gitca-0/ca.crt,safe.directory:/tmp/git' --link=current --one-time=false --period=60s --ref=trunk --repo=ssh://git@github.com/stackabletech/repo.git --rev=HEAD --root=/tmp/git & - wait_for_termination $! -command: -- /bin/bash -- -x -- -euo -- pipefail -- -c -env: -- name: VAR1 - value: value1 -image: oci.stackable.tech/sdp/product:latest -imagePullPolicy: Always -name: git-sync-0 -resources: - limits: - cpu: 200m - memory: 64Mi - requests: - cpu: 100m - memory: 64Mi -volumeMounts: -- mountPath: /tmp/git - name: content-from-git-0 -- mountPath: /stackable/log - name: log-volume -- mountPath: /mnt/extra-volume - name: extra-volume -- mountPath: /stackable/gitca-0 - name: ca-cert-0 -"#, - yaml_serde::to_string(&git_sync_resources.git_sync_containers.first()).unwrap() + insta::assert_snapshot!( + "git_sync_ca_cert_containers", + yaml_serde::to_string(&git_sync_resources.git_sync_containers).unwrap() ); assert_eq!(1, git_sync_resources.git_sync_init_containers.len()); - assert_eq!( - r"args: -- |- - mkdir --parents /stackable/log/git-sync-0-init && exec > >(tee /stackable/log/git-sync-0-init/container.stdout.log) 2> >(tee /stackable/log/git-sync-0-init/container.stderr.log >&2) - /stackable/git-sync --depth=3 --git-config='http.sslCAInfo:/stackable/gitca-0/ca.crt,safe.directory:/tmp/git' --link=current --one-time=true --period=60s --ref=trunk --repo=ssh://git@github.com/stackabletech/repo.git --rev=HEAD --root=/tmp/git -command: -- /bin/bash -- -x -- -euo -- pipefail -- -c -env: -- name: VAR1 - value: value1 -image: oci.stackable.tech/sdp/product:latest -imagePullPolicy: Always -name: git-sync-0-init -resources: - limits: - cpu: 200m - memory: 64Mi - requests: - cpu: 100m - memory: 64Mi -volumeMounts: -- mountPath: /tmp/git - name: content-from-git-0 -- mountPath: /stackable/log - name: log-volume -- mountPath: /mnt/extra-volume - name: extra-volume -- mountPath: /stackable/gitca-0 - name: ca-cert-0 -", - yaml_serde::to_string(&git_sync_resources.git_sync_init_containers.first()).unwrap() + insta::assert_snapshot!( + "git_sync_ca_cert_init_containers", + yaml_serde::to_string(&git_sync_resources.git_sync_init_containers).unwrap() ); assert_eq!(1, git_sync_resources.git_content_volumes.len()); From 1bc244a3498d53302e5e79eb3a45a4cf1de90ca9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20M=C3=BCller?= Date: Thu, 26 Nov 2026 13:10:01 +0100 Subject: [PATCH 6/7] set EXIT trap in remove_vector_shutdown_file_command to create vector shutdown file --- Cargo.lock | 1 + crates/stackable-operator/CHANGELOG.md | 4 + crates/stackable-operator/Cargo.toml | 1 + .../src/product_logging/framework.rs | 140 ++++++++++++++++-- 4 files changed, 136 insertions(+), 10 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index bc579998c..e965b6bc5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3894,6 +3894,7 @@ dependencies = [ "stackable-versioned", "stackable-webhook", "strum", + "tempfile", "tokio", "tracing", "tracing-appender", diff --git a/crates/stackable-operator/CHANGELOG.md b/crates/stackable-operator/CHANGELOG.md index 274540378..3be9897cd 100644 --- a/crates/stackable-operator/CHANGELOG.md +++ b/crates/stackable-operator/CHANGELOG.md @@ -18,6 +18,10 @@ All notable changes to this project will be documented in this file. non-ASCII characters and returns an error instead ([#1339]). - BREAKING: `wait_for_termination` in `COMMON_BASH_TRAP_FUNCTIONS` now returns the exit status of the process it waited for instead of always returning `0` ([#1265]). +- `remove_vector_shutdown_file_command` now also installs an `EXIT` trap which creates the Vector shutdown + file. The Vector container is therefore shut down even if the script is aborted by `set -e` because + `wait_for_termination` returned a non-zero exit status, instead of running until the termination grace + period expires. Operators do not need to change their scripts ([#1265]). - `handle_term_signal` in `COMMON_BASH_TRAP_FUNCTIONS` no longer aborts under `set -u` when SIGTERM arrives before the child process ID is known ([#1265]). diff --git a/crates/stackable-operator/Cargo.toml b/crates/stackable-operator/Cargo.toml index 9b6bea85c..b4fd60213 100644 --- a/crates/stackable-operator/Cargo.toml +++ b/crates/stackable-operator/Cargo.toml @@ -71,6 +71,7 @@ xml.workspace = true indoc.workspace = true insta.workspace = true rstest.workspace = true +tempfile.workspace = true [lints] workspace = true diff --git a/crates/stackable-operator/src/product_logging/framework.rs b/crates/stackable-operator/src/product_logging/framework.rs index 3750acf7a..3282f815b 100644 --- a/crates/stackable-operator/src/product_logging/framework.rs +++ b/crates/stackable-operator/src/product_logging/framework.rs @@ -1337,7 +1337,7 @@ sinks: /// meta::ObjectMetaBuilder, /// pod::{container::ContainerBuilder, resources::ResourceRequirementsBuilder, PodBuilder}, /// }, -/// product_logging::{self, framework:: {create_vector_shutdown_file_command, remove_vector_shutdown_file_command}}, +/// product_logging::{self, framework::remove_vector_shutdown_file_command}, /// utils::COMMON_BASH_TRAP_FUNCTIONS, /// }; /// use k8s_openapi::apimachinery::pkg::api::resource::Quantity; @@ -1386,15 +1386,10 @@ sinks: /// {remove_vector_shutdown_file_command} /// prepare_signal_handlers /// my-application start & -/// product_exit_code=0 -/// wait_for_termination $! || product_exit_code=$? -/// {create_vector_shutdown_file_command} -/// exit \"${{product_exit_code}}\" +/// wait_for_termination $! /// ", /// remove_vector_shutdown_file_command = /// remove_vector_shutdown_file_command(STACKABLE_LOG_DIR), -/// create_vector_shutdown_file_command = -/// create_vector_shutdown_file_command(STACKABLE_LOG_DIR), /// )]) /// .build(), /// ); @@ -1504,18 +1499,143 @@ touch {stackable_log_dir}/{VECTOR_LOG_DIR}/{SHUTDOWN_FILE}" /// Use this command to remove the shutdown file (if it exists) created by [`create_vector_shutdown_file_command`]. /// You should execute this command before starting your application. +/// +/// The command also installs an `EXIT` trap which creates the shutdown file, so the Vector +/// container is shut down however the script ends: after a regular exit, after `set -e` aborts +/// the script because `wait_for_termination` returned the non-zero exit status of the +/// application, or after an explicit `exit`. The exit status of the script is not changed by the +/// trap. A trailing [`create_vector_shutdown_file_command`] is therefore not needed anymore. +/// +/// The command must be executed in the top-level shell of the script which owns the lifetime of +/// the Vector container. In a subshell, the trap would fire when the subshell exits and shut down +/// Vector too early. The script must not install another `EXIT` trap, because it would replace +/// this one. pub fn remove_vector_shutdown_file_command(stackable_log_dir: &str) -> String { - format!("rm -f {stackable_log_dir}/{VECTOR_LOG_DIR}/{SHUTDOWN_FILE}") + format!( + "rm -f {stackable_log_dir}/{VECTOR_LOG_DIR}/{SHUTDOWN_FILE} && \ +trap '{create_shutdown_file_command}' EXIT", + create_shutdown_file_command = create_vector_shutdown_file_command(stackable_log_dir), + ) } #[cfg(test)] mod tests { - use std::collections::BTreeMap; + use std::{collections::BTreeMap, process::Command}; + use indoc::{formatdoc, indoc}; use rstest::rstest; use super::*; - use crate::product_logging::spec::{AppenderConfig, LoggerConfig}; + use crate::{ + product_logging::spec::{AppenderConfig, LoggerConfig}, + utils::COMMON_BASH_TRAP_FUNCTIONS, + }; + + /// Runs the given application commands like a product container does and returns the exit + /// status of the script and whether the Vector shutdown file exists afterwards. + fn run_application_script(application_commands: &str) -> (i32, bool) { + let stackable_log_dir = + tempfile::tempdir().expect("a temporary directory should be creatable"); + let stackable_log_dir_path = stackable_log_dir + .path() + .to_str() + .expect("the temporary directory path should be valid UTF-8"); + + let script = formatdoc! {" + {COMMON_BASH_TRAP_FUNCTIONS} + {remove_vector_shutdown_file_command} + prepare_signal_handlers + {application_commands}", + remove_vector_shutdown_file_command = + remove_vector_shutdown_file_command(stackable_log_dir_path), + application_commands = application_commands.replace( + "{create_vector_shutdown_file_command}", + &create_vector_shutdown_file_command(stackable_log_dir_path), + ), + }; + + let output = Command::new("/bin/bash") + .args(["-euo", "pipefail", "-c", &script]) + .output() + .expect("bash should be executable in the test environment"); + let exit_code = output + .status + .code() + .expect("the script should terminate regularly and not by a signal"); + let shutdown_file_exists = stackable_log_dir + .path() + .join(VECTOR_LOG_DIR) + .join(SHUTDOWN_FILE) + .exists(); + + (exit_code, shutdown_file_exists) + } + + #[rstest] + #[case::application_crashes( + indoc! {" + bash -c 'exit 42' & + wait_for_termination $! + "}, + 42 + )] + #[case::application_exits_successfully( + indoc! {" + bash -c 'exit 0' & + wait_for_termination $! + "}, + 0 + )] + #[case::application_is_killed( + indoc! {" + bash -c 'kill -KILL $$' & + wait_for_termination $! + "}, + 137 + )] + #[case::application_shuts_down_with_failure_on_sigterm( + indoc! {" + bash -c 'trap \"exit 143\" TERM; sleep 10 >/dev/null 2>&1 & wait $!' & + application_pid=$! + (sleep 0.2; kill -TERM $$) & + wait_for_termination $application_pid + "}, + 143 + )] + #[case::application_shuts_down_successfully_on_sigterm( + indoc! {" + bash -c 'trap \"exit 0\" TERM; sleep 10 >/dev/null 2>&1 & wait $!' & + application_pid=$! + (sleep 0.2; kill -TERM $$) & + wait_for_termination $application_pid + "}, + 0 + )] + #[case::application_crashes_with_trailing_create_command( + indoc! {" + bash -c 'exit 42' & + wait_for_termination $! + {create_vector_shutdown_file_command} + "}, + 42 + )] + #[case::application_exits_successfully_with_trailing_create_command( + indoc! {" + bash -c 'exit 0' & + wait_for_termination $! + {create_vector_shutdown_file_command} + "}, + 0 + )] + fn vector_shutdown_file_is_created_on_every_exit( + #[case] application_commands: &str, + #[case] expected_exit_code: i32, + ) { + let (exit_code, shutdown_file_exists) = run_application_script(application_commands); + + assert_eq!(expected_exit_code, exit_code); + assert!(shutdown_file_exists); + } #[rstest] #[case("0Mi", &[])] From 5fee3df87072200c4599c229881931ed9cec3895 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20M=C3=BCller?= Date: Thu, 26 Nov 2026 14:08:59 +0100 Subject: [PATCH 7/7] rework for bash 5.1 and add new function so that name fits capability --- crates/stackable-operator/CHANGELOG.md | 20 ++-- ..._tests__multiple_git_syncs_containers.snap | 20 +--- ...s__multiple_git_syncs_init_containers.snap | 2 +- ...l__tests__git_sync_ca_cert_containers.snap | 8 +- ...sts__git_sync_ca_cert_init_containers.snap | 2 +- ..._impl__tests__git_sync_ssh_containers.snap | 8 +- ...__tests__git_sync_ssh_init_containers.snap | 2 +- ..._tests__multiple_git_syncs_containers.snap | 20 +--- ...s__multiple_git_syncs_init_containers.snap | 2 +- .../src/product_logging/framework.rs | 100 ++++++++-------- crates/stackable-operator/src/utils/bash.rs | 111 ++++++++---------- 11 files changed, 127 insertions(+), 168 deletions(-) diff --git a/crates/stackable-operator/CHANGELOG.md b/crates/stackable-operator/CHANGELOG.md index 3be9897cd..d94d01e40 100644 --- a/crates/stackable-operator/CHANGELOG.md +++ b/crates/stackable-operator/CHANGELOG.md @@ -7,23 +7,29 @@ All notable changes to this project will be documented in this file. ### Added - Add `utils::crds::raw_any_nullable_value_schema`, which accepts any JSON value (not only objects) ([#1326]). +- Add `product_logging::framework::manage_vector_shutdown_file_command`. It removes the Vector shutdown + file and installs an `EXIT` trap which creates it again, so Vector also shuts down when `set -e` aborts + the script. A trailing `create_vector_shutdown_file_command` is not needed ([#1265]). ### Changed - Bump `kube` to `5.2.0`, which fixes RUSTSEC-2026-0600 ([#1340]). +- `remove_vector_shutdown_file_command` now also installs the `EXIT` trap of + `manage_vector_shutdown_file_command`, replacing any `EXIT` trap the script set before ([#1265]). ### Fixed - `ProductImage::resolve` no longer panics on long product versions or image tags containing non-ASCII characters and returns an error instead ([#1339]). - BREAKING: `wait_for_termination` in `COMMON_BASH_TRAP_FUNCTIONS` now returns the exit status of the process - it waited for instead of always returning `0` ([#1265]). -- `remove_vector_shutdown_file_command` now also installs an `EXIT` trap which creates the Vector shutdown - file. The Vector container is therefore shut down even if the script is aborted by `set -e` because - `wait_for_termination` returned a non-zero exit status, instead of running until the termination grace - period expires. Operators do not need to change their scripts ([#1265]). -- `handle_term_signal` in `COMMON_BASH_TRAP_FUNCTIONS` no longer aborts under `set -u` when SIGTERM arrives - before the child process ID is known ([#1265]). + it waited for instead of always returning `0`. Containers whose product exits non-zero on SIGTERM (e.g. + `143` for JVM products) now report that status on Pod deletion instead of `0` ([#1265]). +- `handle_term_signal` in `COMMON_BASH_TRAP_FUNCTIONS` exits the script with status `143` when SIGTERM arrives + before the child process ID is known, instead of aborting under `set -u` with status `1` ([#1265]). + +### Deprecated + +- Deprecate `remove_vector_shutdown_file_command` in favour of `manage_vector_shutdown_file_command` ([#1265]). ### Removed diff --git a/crates/stackable-operator/src/crd/git_sync/snapshots/stackable_operator__crd__git_sync__v1alpha1_impl__tests__multiple_git_syncs_containers.snap b/crates/stackable-operator/src/crd/git_sync/snapshots/stackable_operator__crd__git_sync__v1alpha1_impl__tests__multiple_git_syncs_containers.snap index 686f34002..5a0842605 100644 --- a/crates/stackable-operator/src/crd/git_sync/snapshots/stackable_operator__crd__git_sync__v1alpha1_impl__tests__multiple_git_syncs_containers.snap +++ b/crates/stackable-operator/src/crd/git_sync/snapshots/stackable_operator__crd__git_sync__v1alpha1_impl__tests__multiple_git_syncs_containers.snap @@ -1,6 +1,6 @@ --- source: crates/stackable-operator/src/crd/git_sync/v1alpha1_impl.rs -expression: "serde_yaml::to_string(&git_sync_resources.git_sync_containers).unwrap()" +expression: "yaml_serde::to_string(&git_sync_resources.git_sync_containers).unwrap()" --- - args: - |- @@ -9,7 +9,6 @@ expression: "serde_yaml::to_string(&git_sync_resources.git_sync_containers).unwr prepare_signal_handlers() { unset term_child_pid - unset term_kill_needed trap 'handle_term_signal' TERM } @@ -18,7 +17,7 @@ expression: "serde_yaml::to_string(&git_sync_resources.git_sync_containers).unwr if [ -n "${term_child_pid:-}" ]; then kill -TERM "${term_child_pid}" 2>/dev/null else - term_kill_needed="yes" + exit 143 fi } @@ -26,9 +25,6 @@ expression: "serde_yaml::to_string(&git_sync_resources.git_sync_containers).unwr { set +e term_child_pid=$1 - if [[ -v term_kill_needed ]]; then - kill -TERM "${term_child_pid}" 2>/dev/null - fi wait ${term_child_pid} 2>/dev/null term_child_status=$? trap - TERM @@ -78,7 +74,6 @@ expression: "serde_yaml::to_string(&git_sync_resources.git_sync_containers).unwr prepare_signal_handlers() { unset term_child_pid - unset term_kill_needed trap 'handle_term_signal' TERM } @@ -87,7 +82,7 @@ expression: "serde_yaml::to_string(&git_sync_resources.git_sync_containers).unwr if [ -n "${term_child_pid:-}" ]; then kill -TERM "${term_child_pid}" 2>/dev/null else - term_kill_needed="yes" + exit 143 fi } @@ -95,9 +90,6 @@ expression: "serde_yaml::to_string(&git_sync_resources.git_sync_containers).unwr { set +e term_child_pid=$1 - if [[ -v term_kill_needed ]]; then - kill -TERM "${term_child_pid}" 2>/dev/null - fi wait ${term_child_pid} 2>/dev/null term_child_status=$? trap - TERM @@ -152,7 +144,6 @@ expression: "serde_yaml::to_string(&git_sync_resources.git_sync_containers).unwr prepare_signal_handlers() { unset term_child_pid - unset term_kill_needed trap 'handle_term_signal' TERM } @@ -161,7 +152,7 @@ expression: "serde_yaml::to_string(&git_sync_resources.git_sync_containers).unwr if [ -n "${term_child_pid:-}" ]; then kill -TERM "${term_child_pid}" 2>/dev/null else - term_kill_needed="yes" + exit 143 fi } @@ -169,9 +160,6 @@ expression: "serde_yaml::to_string(&git_sync_resources.git_sync_containers).unwr { set +e term_child_pid=$1 - if [[ -v term_kill_needed ]]; then - kill -TERM "${term_child_pid}" 2>/dev/null - fi wait ${term_child_pid} 2>/dev/null term_child_status=$? trap - TERM diff --git a/crates/stackable-operator/src/crd/git_sync/snapshots/stackable_operator__crd__git_sync__v1alpha1_impl__tests__multiple_git_syncs_init_containers.snap b/crates/stackable-operator/src/crd/git_sync/snapshots/stackable_operator__crd__git_sync__v1alpha1_impl__tests__multiple_git_syncs_init_containers.snap index 91530caf5..986630eaf 100644 --- a/crates/stackable-operator/src/crd/git_sync/snapshots/stackable_operator__crd__git_sync__v1alpha1_impl__tests__multiple_git_syncs_init_containers.snap +++ b/crates/stackable-operator/src/crd/git_sync/snapshots/stackable_operator__crd__git_sync__v1alpha1_impl__tests__multiple_git_syncs_init_containers.snap @@ -1,6 +1,6 @@ --- source: crates/stackable-operator/src/crd/git_sync/v1alpha1_impl.rs -expression: "serde_yaml::to_string(&git_sync_resources.git_sync_init_containers).unwrap()" +expression: "yaml_serde::to_string(&git_sync_resources.git_sync_init_containers).unwrap()" --- - args: - |- diff --git a/crates/stackable-operator/src/crd/git_sync/snapshots/stackable_operator__crd__git_sync__v1alpha2_impl__tests__git_sync_ca_cert_containers.snap b/crates/stackable-operator/src/crd/git_sync/snapshots/stackable_operator__crd__git_sync__v1alpha2_impl__tests__git_sync_ca_cert_containers.snap index 5530066b6..4253fb080 100644 --- a/crates/stackable-operator/src/crd/git_sync/snapshots/stackable_operator__crd__git_sync__v1alpha2_impl__tests__git_sync_ca_cert_containers.snap +++ b/crates/stackable-operator/src/crd/git_sync/snapshots/stackable_operator__crd__git_sync__v1alpha2_impl__tests__git_sync_ca_cert_containers.snap @@ -1,6 +1,6 @@ --- source: crates/stackable-operator/src/crd/git_sync/v1alpha2_impl.rs -expression: "serde_yaml::to_string(&git_sync_resources.git_sync_containers).unwrap()" +expression: "yaml_serde::to_string(&git_sync_resources.git_sync_containers).unwrap()" --- - args: - |- @@ -9,7 +9,6 @@ expression: "serde_yaml::to_string(&git_sync_resources.git_sync_containers).unwr prepare_signal_handlers() { unset term_child_pid - unset term_kill_needed trap 'handle_term_signal' TERM } @@ -18,7 +17,7 @@ expression: "serde_yaml::to_string(&git_sync_resources.git_sync_containers).unwr if [ -n "${term_child_pid:-}" ]; then kill -TERM "${term_child_pid}" 2>/dev/null else - term_kill_needed="yes" + exit 143 fi } @@ -26,9 +25,6 @@ expression: "serde_yaml::to_string(&git_sync_resources.git_sync_containers).unwr { set +e term_child_pid=$1 - if [[ -v term_kill_needed ]]; then - kill -TERM "${term_child_pid}" 2>/dev/null - fi wait ${term_child_pid} 2>/dev/null term_child_status=$? trap - TERM diff --git a/crates/stackable-operator/src/crd/git_sync/snapshots/stackable_operator__crd__git_sync__v1alpha2_impl__tests__git_sync_ca_cert_init_containers.snap b/crates/stackable-operator/src/crd/git_sync/snapshots/stackable_operator__crd__git_sync__v1alpha2_impl__tests__git_sync_ca_cert_init_containers.snap index e0f787ed1..8dbd6e8f6 100644 --- a/crates/stackable-operator/src/crd/git_sync/snapshots/stackable_operator__crd__git_sync__v1alpha2_impl__tests__git_sync_ca_cert_init_containers.snap +++ b/crates/stackable-operator/src/crd/git_sync/snapshots/stackable_operator__crd__git_sync__v1alpha2_impl__tests__git_sync_ca_cert_init_containers.snap @@ -1,6 +1,6 @@ --- source: crates/stackable-operator/src/crd/git_sync/v1alpha2_impl.rs -expression: "serde_yaml::to_string(&git_sync_resources.git_sync_init_containers).unwrap()" +expression: "yaml_serde::to_string(&git_sync_resources.git_sync_init_containers).unwrap()" --- - args: - |- diff --git a/crates/stackable-operator/src/crd/git_sync/snapshots/stackable_operator__crd__git_sync__v1alpha2_impl__tests__git_sync_ssh_containers.snap b/crates/stackable-operator/src/crd/git_sync/snapshots/stackable_operator__crd__git_sync__v1alpha2_impl__tests__git_sync_ssh_containers.snap index 2a19a5be4..a3101000b 100644 --- a/crates/stackable-operator/src/crd/git_sync/snapshots/stackable_operator__crd__git_sync__v1alpha2_impl__tests__git_sync_ssh_containers.snap +++ b/crates/stackable-operator/src/crd/git_sync/snapshots/stackable_operator__crd__git_sync__v1alpha2_impl__tests__git_sync_ssh_containers.snap @@ -1,6 +1,6 @@ --- source: crates/stackable-operator/src/crd/git_sync/v1alpha2_impl.rs -expression: "serde_yaml::to_string(&git_sync_resources.git_sync_containers).unwrap()" +expression: "yaml_serde::to_string(&git_sync_resources.git_sync_containers).unwrap()" --- - args: - |- @@ -9,7 +9,6 @@ expression: "serde_yaml::to_string(&git_sync_resources.git_sync_containers).unwr prepare_signal_handlers() { unset term_child_pid - unset term_kill_needed trap 'handle_term_signal' TERM } @@ -18,7 +17,7 @@ expression: "serde_yaml::to_string(&git_sync_resources.git_sync_containers).unwr if [ -n "${term_child_pid:-}" ]; then kill -TERM "${term_child_pid}" 2>/dev/null else - term_kill_needed="yes" + exit 143 fi } @@ -26,9 +25,6 @@ expression: "serde_yaml::to_string(&git_sync_resources.git_sync_containers).unwr { set +e term_child_pid=$1 - if [[ -v term_kill_needed ]]; then - kill -TERM "${term_child_pid}" 2>/dev/null - fi wait ${term_child_pid} 2>/dev/null term_child_status=$? trap - TERM diff --git a/crates/stackable-operator/src/crd/git_sync/snapshots/stackable_operator__crd__git_sync__v1alpha2_impl__tests__git_sync_ssh_init_containers.snap b/crates/stackable-operator/src/crd/git_sync/snapshots/stackable_operator__crd__git_sync__v1alpha2_impl__tests__git_sync_ssh_init_containers.snap index 07698da0e..a099a9f81 100644 --- a/crates/stackable-operator/src/crd/git_sync/snapshots/stackable_operator__crd__git_sync__v1alpha2_impl__tests__git_sync_ssh_init_containers.snap +++ b/crates/stackable-operator/src/crd/git_sync/snapshots/stackable_operator__crd__git_sync__v1alpha2_impl__tests__git_sync_ssh_init_containers.snap @@ -1,6 +1,6 @@ --- source: crates/stackable-operator/src/crd/git_sync/v1alpha2_impl.rs -expression: "serde_yaml::to_string(&git_sync_resources.git_sync_init_containers).unwrap()" +expression: "yaml_serde::to_string(&git_sync_resources.git_sync_init_containers).unwrap()" --- - args: - |- diff --git a/crates/stackable-operator/src/crd/git_sync/snapshots/stackable_operator__crd__git_sync__v1alpha2_impl__tests__multiple_git_syncs_containers.snap b/crates/stackable-operator/src/crd/git_sync/snapshots/stackable_operator__crd__git_sync__v1alpha2_impl__tests__multiple_git_syncs_containers.snap index 3f174326b..a95c5e7e0 100644 --- a/crates/stackable-operator/src/crd/git_sync/snapshots/stackable_operator__crd__git_sync__v1alpha2_impl__tests__multiple_git_syncs_containers.snap +++ b/crates/stackable-operator/src/crd/git_sync/snapshots/stackable_operator__crd__git_sync__v1alpha2_impl__tests__multiple_git_syncs_containers.snap @@ -1,6 +1,6 @@ --- source: crates/stackable-operator/src/crd/git_sync/v1alpha2_impl.rs -expression: "serde_yaml::to_string(&git_sync_resources.git_sync_containers).unwrap()" +expression: "yaml_serde::to_string(&git_sync_resources.git_sync_containers).unwrap()" --- - args: - |- @@ -9,7 +9,6 @@ expression: "serde_yaml::to_string(&git_sync_resources.git_sync_containers).unwr prepare_signal_handlers() { unset term_child_pid - unset term_kill_needed trap 'handle_term_signal' TERM } @@ -18,7 +17,7 @@ expression: "serde_yaml::to_string(&git_sync_resources.git_sync_containers).unwr if [ -n "${term_child_pid:-}" ]; then kill -TERM "${term_child_pid}" 2>/dev/null else - term_kill_needed="yes" + exit 143 fi } @@ -26,9 +25,6 @@ expression: "serde_yaml::to_string(&git_sync_resources.git_sync_containers).unwr { set +e term_child_pid=$1 - if [[ -v term_kill_needed ]]; then - kill -TERM "${term_child_pid}" 2>/dev/null - fi wait ${term_child_pid} 2>/dev/null term_child_status=$? trap - TERM @@ -78,7 +74,6 @@ expression: "serde_yaml::to_string(&git_sync_resources.git_sync_containers).unwr prepare_signal_handlers() { unset term_child_pid - unset term_kill_needed trap 'handle_term_signal' TERM } @@ -87,7 +82,7 @@ expression: "serde_yaml::to_string(&git_sync_resources.git_sync_containers).unwr if [ -n "${term_child_pid:-}" ]; then kill -TERM "${term_child_pid}" 2>/dev/null else - term_kill_needed="yes" + exit 143 fi } @@ -95,9 +90,6 @@ expression: "serde_yaml::to_string(&git_sync_resources.git_sync_containers).unwr { set +e term_child_pid=$1 - if [[ -v term_kill_needed ]]; then - kill -TERM "${term_child_pid}" 2>/dev/null - fi wait ${term_child_pid} 2>/dev/null term_child_status=$? trap - TERM @@ -152,7 +144,6 @@ expression: "serde_yaml::to_string(&git_sync_resources.git_sync_containers).unwr prepare_signal_handlers() { unset term_child_pid - unset term_kill_needed trap 'handle_term_signal' TERM } @@ -161,7 +152,7 @@ expression: "serde_yaml::to_string(&git_sync_resources.git_sync_containers).unwr if [ -n "${term_child_pid:-}" ]; then kill -TERM "${term_child_pid}" 2>/dev/null else - term_kill_needed="yes" + exit 143 fi } @@ -169,9 +160,6 @@ expression: "serde_yaml::to_string(&git_sync_resources.git_sync_containers).unwr { set +e term_child_pid=$1 - if [[ -v term_kill_needed ]]; then - kill -TERM "${term_child_pid}" 2>/dev/null - fi wait ${term_child_pid} 2>/dev/null term_child_status=$? trap - TERM diff --git a/crates/stackable-operator/src/crd/git_sync/snapshots/stackable_operator__crd__git_sync__v1alpha2_impl__tests__multiple_git_syncs_init_containers.snap b/crates/stackable-operator/src/crd/git_sync/snapshots/stackable_operator__crd__git_sync__v1alpha2_impl__tests__multiple_git_syncs_init_containers.snap index bb2d6c5ee..8f99b18c5 100644 --- a/crates/stackable-operator/src/crd/git_sync/snapshots/stackable_operator__crd__git_sync__v1alpha2_impl__tests__multiple_git_syncs_init_containers.snap +++ b/crates/stackable-operator/src/crd/git_sync/snapshots/stackable_operator__crd__git_sync__v1alpha2_impl__tests__multiple_git_syncs_init_containers.snap @@ -1,6 +1,6 @@ --- source: crates/stackable-operator/src/crd/git_sync/v1alpha2_impl.rs -expression: "serde_yaml::to_string(&git_sync_resources.git_sync_init_containers).unwrap()" +expression: "yaml_serde::to_string(&git_sync_resources.git_sync_init_containers).unwrap()" --- - args: - |- diff --git a/crates/stackable-operator/src/product_logging/framework.rs b/crates/stackable-operator/src/product_logging/framework.rs index 3282f815b..ecf268af9 100644 --- a/crates/stackable-operator/src/product_logging/framework.rs +++ b/crates/stackable-operator/src/product_logging/framework.rs @@ -1337,7 +1337,7 @@ sinks: /// meta::ObjectMetaBuilder, /// pod::{container::ContainerBuilder, resources::ResourceRequirementsBuilder, PodBuilder}, /// }, -/// product_logging::{self, framework::remove_vector_shutdown_file_command}, +/// product_logging::{self, framework::manage_vector_shutdown_file_command}, /// utils::COMMON_BASH_TRAP_FUNCTIONS, /// }; /// use k8s_openapi::apimachinery::pkg::api::resource::Quantity; @@ -1383,13 +1383,13 @@ sinks: /// .args(vec![format!( /// "\ /// {COMMON_BASH_TRAP_FUNCTIONS} -/// {remove_vector_shutdown_file_command} +/// {manage_vector_shutdown_file_command} /// prepare_signal_handlers /// my-application start & /// wait_for_termination $! /// ", -/// remove_vector_shutdown_file_command = -/// remove_vector_shutdown_file_command(STACKABLE_LOG_DIR), +/// manage_vector_shutdown_file_command = +/// manage_vector_shutdown_file_command(STACKABLE_LOG_DIR), /// )]) /// .build(), /// ); @@ -1466,7 +1466,8 @@ kill $vector_pid } /// Command to create a shutdown file for the vector container. -/// Please delete it before starting your application using [`remove_vector_shutdown_file_command`]. +/// Please delete it before starting your application using [`manage_vector_shutdown_file_command`], +/// which also creates it again when the script exits. /// /// # Example /// @@ -1476,7 +1477,7 @@ kill $vector_pid /// const STACKABLE_LOG_DIR: &str = "/stackable/log"; /// /// let args = vec![ -/// product_logging::framework::remove_vector_shutdown_file_command(STACKABLE_LOG_DIR), +/// product_logging::framework::manage_vector_shutdown_file_command(STACKABLE_LOG_DIR), /// "echo Perform some tasks ...".into(), /// product_logging::framework::create_vector_shutdown_file_command(STACKABLE_LOG_DIR), /// ]; @@ -1497,20 +1498,22 @@ touch {stackable_log_dir}/{VECTOR_LOG_DIR}/{SHUTDOWN_FILE}" ) } -/// Use this command to remove the shutdown file (if it exists) created by [`create_vector_shutdown_file_command`]. -/// You should execute this command before starting your application. +/// Use this command to bind the lifetime of the Vector container to the script that runs your +/// application. Execute it before starting your application. /// -/// The command also installs an `EXIT` trap which creates the shutdown file, so the Vector -/// container is shut down however the script ends: after a regular exit, after `set -e` aborts -/// the script because `wait_for_termination` returned the non-zero exit status of the -/// application, or after an explicit `exit`. The exit status of the script is not changed by the -/// trap. A trailing [`create_vector_shutdown_file_command`] is therefore not needed anymore. +/// The command removes the shutdown file (if it exists) created by +/// [`create_vector_shutdown_file_command`] and installs an `EXIT` trap which creates the shutdown +/// file again, so the Vector container is shut down however the script ends: after a regular +/// exit, after `set -e` aborts the script because `wait_for_termination` returned the non-zero +/// exit status of the application, or after an explicit `exit`. The exit status of the script is +/// not changed by the trap. A trailing [`create_vector_shutdown_file_command`] is therefore not +/// needed. /// /// The command must be executed in the top-level shell of the script which owns the lifetime of /// the Vector container. In a subshell, the trap would fire when the subshell exits and shut down /// Vector too early. The script must not install another `EXIT` trap, because it would replace /// this one. -pub fn remove_vector_shutdown_file_command(stackable_log_dir: &str) -> String { +pub fn manage_vector_shutdown_file_command(stackable_log_dir: &str) -> String { format!( "rm -f {stackable_log_dir}/{VECTOR_LOG_DIR}/{SHUTDOWN_FILE} && \ trap '{create_shutdown_file_command}' EXIT", @@ -1518,9 +1521,18 @@ trap '{create_shutdown_file_command}' EXIT", ) } +/// Alias of [`manage_vector_shutdown_file_command`], including its `EXIT` trap. +#[deprecated( + note = "renamed to stackable_operator::product_logging::framework::manage_vector_shutdown_file_command", + since = "0.123.0" +)] +pub fn remove_vector_shutdown_file_command(stackable_log_dir: &str) -> String { + manage_vector_shutdown_file_command(stackable_log_dir) +} + #[cfg(test)] mod tests { - use std::{collections::BTreeMap, process::Command}; + use std::collections::BTreeMap; use indoc::{formatdoc, indoc}; use rstest::rstest; @@ -1528,12 +1540,19 @@ mod tests { use super::*; use crate::{ product_logging::spec::{AppenderConfig, LoggerConfig}, - utils::COMMON_BASH_TRAP_FUNCTIONS, + utils::{COMMON_BASH_TRAP_FUNCTIONS, bash::run_container_script}, }; /// Runs the given application commands like a product container does and returns the exit /// status of the script and whether the Vector shutdown file exists afterwards. - fn run_application_script(application_commands: &str) -> (i32, bool) { + /// + /// With `trailing_create_command`, the script ends with an explicit + /// [`create_vector_shutdown_file_command`] like operator scripts written before the `EXIT` + /// trap existed. + fn run_application_script( + application_commands: &str, + trailing_create_command: bool, + ) -> (i32, bool) { let stackable_log_dir = tempfile::tempdir().expect("a temporary directory should be creatable"); let stackable_log_dir_path = stackable_log_dir @@ -1541,27 +1560,22 @@ mod tests { .to_str() .expect("the temporary directory path should be valid UTF-8"); + let trailing_commands = if trailing_create_command { + create_vector_shutdown_file_command(stackable_log_dir_path) + } else { + String::new() + }; let script = formatdoc! {" {COMMON_BASH_TRAP_FUNCTIONS} - {remove_vector_shutdown_file_command} + {manage_vector_shutdown_file_command} prepare_signal_handlers - {application_commands}", - remove_vector_shutdown_file_command = - remove_vector_shutdown_file_command(stackable_log_dir_path), - application_commands = application_commands.replace( - "{create_vector_shutdown_file_command}", - &create_vector_shutdown_file_command(stackable_log_dir_path), - ), + {application_commands} + {trailing_commands}", + manage_vector_shutdown_file_command = + manage_vector_shutdown_file_command(stackable_log_dir_path), }; - let output = Command::new("/bin/bash") - .args(["-euo", "pipefail", "-c", &script]) - .output() - .expect("bash should be executable in the test environment"); - let exit_code = output - .status - .code() - .expect("the script should terminate regularly and not by a signal"); + let (exit_code, _) = run_container_script(&script); let shutdown_file_exists = stackable_log_dir .path() .join(VECTOR_LOG_DIR) @@ -1611,27 +1625,13 @@ mod tests { "}, 0 )] - #[case::application_crashes_with_trailing_create_command( - indoc! {" - bash -c 'exit 42' & - wait_for_termination $! - {create_vector_shutdown_file_command} - "}, - 42 - )] - #[case::application_exits_successfully_with_trailing_create_command( - indoc! {" - bash -c 'exit 0' & - wait_for_termination $! - {create_vector_shutdown_file_command} - "}, - 0 - )] fn vector_shutdown_file_is_created_on_every_exit( #[case] application_commands: &str, #[case] expected_exit_code: i32, + #[values(false, true)] trailing_create_command: bool, ) { - let (exit_code, shutdown_file_exists) = run_application_script(application_commands); + let (exit_code, shutdown_file_exists) = + run_application_script(application_commands, trailing_create_command); assert_eq!(expected_exit_code, exit_code); assert!(shutdown_file_exists); diff --git a/crates/stackable-operator/src/utils/bash.rs b/crates/stackable-operator/src/utils/bash.rs index 6163256fa..02dbd57eb 100644 --- a/crates/stackable-operator/src/utils/bash.rs +++ b/crates/stackable-operator/src/utils/bash.rs @@ -4,6 +4,10 @@ /// 2. `wait_for_termination` waits for the PID you passed as the first argument to terminate and /// returns its exit status /// +/// A SIGTERM which arrives after `prepare_signal_handlers` but before `wait_for_termination` is +/// called exits the script with status `143`. A product already started in that window is killed +/// with the container instead of shut down gracefully. +/// /// An example use could be /// ```text /// {COMMON_BASH_TRAP_FUNCTIONS} @@ -17,17 +21,20 @@ /// ``` // A `wait` status above 128 can mean two things: // 1. bash reports a signal death as `128 + signal` -// 2. an in-progress `wait` abort with such a status when a trapped signal arrives +// 2. an in-progress `wait` aborts with such a status when a trapped signal arrives // // We wait a second time to get the actual child status, which immediately returns the // status again in case 1. In case 2 the child is still running and we do need to wait. // // See https://www.gnu.org/software/bash/manual/html_node/Signals.html +// +// A SIGTERM before the child PID is known exits the script instead of being forwarded once the +// child is started: bash 5.1 (UBI 9) regularly loses a SIGTERM sent to a child right after it +// was forked, and the child then runs until the termination grace period expires. pub const COMMON_BASH_TRAP_FUNCTIONS: &str = r#" prepare_signal_handlers() { unset term_child_pid - unset term_kill_needed trap 'handle_term_signal' TERM } @@ -36,7 +43,7 @@ handle_term_signal() if [ -n "${term_child_pid:-}" ]; then kill -TERM "${term_child_pid}" 2>/dev/null else - term_kill_needed="yes" + exit 143 fi } @@ -44,9 +51,6 @@ wait_for_termination() { set +e term_child_pid=$1 - if [[ -v term_kill_needed ]]; then - kill -TERM "${term_child_pid}" 2>/dev/null - fi wait ${term_child_pid} 2>/dev/null term_child_status=$? trap - TERM @@ -59,76 +63,57 @@ wait_for_termination() } "#; +/// Runs the given script with the shell options of a product container and returns its exit +/// status and stdout. #[cfg(test)] -mod tests { - use std::process::Command; - - use super::*; - - fn run_container_command(script: &str) -> (i32, String) { - let output = Command::new("/bin/bash") - .args(["-euo", "pipefail", "-c", script]) - .output() - .expect("bash can be executed in the test environment"); - let exit_code = output - .status - .code() - .expect("the shell terminated regularly and not by a signal"); - let stdout = String::from_utf8(output.stdout).expect("the script only prints UTF-8"); - (exit_code, stdout) - } - - #[test] - fn crash_of_child_process() { - let (exit_code, _) = run_container_command(&format!( - "{COMMON_BASH_TRAP_FUNCTIONS} -prepare_signal_handlers -bash -c 'exit 42' & -wait_for_termination $!" - )); +pub(crate) fn run_container_script(script: &str) -> (i32, String) { + let output = std::process::Command::new("/bin/bash") + .args(["-euo", "pipefail", "-c", script]) + .output() + .expect("bash should be executable in the test environment"); + let exit_code = output + .status + .code() + .expect("the script should terminate regularly and not by a signal"); + let stdout = String::from_utf8(output.stdout).expect("the script should only print UTF-8"); - assert_eq!(42, exit_code); - } + (exit_code, stdout) +} - #[test] - fn graceful_shutdown_of_child_process() { - let (exit_code, _) = run_container_command(&format!( - "{COMMON_BASH_TRAP_FUNCTIONS} -prepare_signal_handlers -bash -c 'trap \"exit 7\" TERM; sleep 10 >/dev/null 2>&1 & wait $!' & -child_pid=$! -(sleep 0.2; kill -TERM $$) & -wait_for_termination $child_pid" - )); +#[cfg(test)] +mod tests { + use indoc::formatdoc; - assert_eq!(7, exit_code); - } + use super::*; #[test] fn crash_with_command_after_the_call() { - let (exit_code, stdout) = run_container_command(&format!( - "{COMMON_BASH_TRAP_FUNCTIONS} -prepare_signal_handlers -bash -c 'exit 42' & -product_exit_code=0 -wait_for_termination $! || product_exit_code=$? -echo tail-ran -exit \"${{product_exit_code}}\"" - )); + let (exit_code, stdout) = run_container_script(&formatdoc! {" + {COMMON_BASH_TRAP_FUNCTIONS} + prepare_signal_handlers + bash -c 'exit 42' & + product_exit_code=0 + wait_for_termination $! || product_exit_code=$? + echo tail-ran + exit \"${{product_exit_code}}\"" + }); + assert_eq!(42, exit_code); assert!(stdout.contains("tail-ran\n")); } #[test] fn sigterm_before_child_pid_is_known() { - let (exit_code, _) = run_container_command(&format!( - "{COMMON_BASH_TRAP_FUNCTIONS} -prepare_signal_handlers -kill -TERM $$ -sleep 10 & -wait_for_termination $! -" - )); + let (exit_code, stdout) = run_container_script(&formatdoc! {" + {COMMON_BASH_TRAP_FUNCTIONS} + prepare_signal_handlers + kill -TERM $$ + echo child-started + sleep 10 & + wait_for_termination $!" + }); + assert_eq!(143, exit_code); + assert!(!stdout.contains("child-started")); } }