From 937e5b6db14f98c6ac09987bf4570c9fcfa58aa1 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/5] fix: wait_for_termination returns actual exit status --- crates/stackable-operator/CHANGELOG.md | 8 +++ .../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, 121 insertions(+), 21 deletions(-) diff --git a/crates/stackable-operator/CHANGELOG.md b/crates/stackable-operator/CHANGELOG.md index ee60b2114..315b95903 100644 --- a/crates/stackable-operator/CHANGELOG.md +++ b/crates/stackable-operator/CHANGELOG.md @@ -4,6 +4,14 @@ All notable changes to this project will be documented in this file. ## [Unreleased] +### 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 + ## [0.119.0] - 2026-09-23 ### Removed 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 20cfc7e5f..5ad1bb03b 100644 --- a/crates/stackable-operator/src/crd/git_sync/v1alpha1_impl.rs +++ b/crates/stackable-operator/src/crd/git_sync/v1alpha1_impl.rs @@ -494,7 +494,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" @@ -509,9 +509,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 @@ -563,7 +568,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" @@ -578,9 +583,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 @@ -637,7 +647,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" @@ -652,9 +662,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 eba308bfb..da59054ab 100644 --- a/crates/stackable-operator/src/crd/git_sync/v1alpha2_impl.rs +++ b/crates/stackable-operator/src/crd/git_sync/v1alpha2_impl.rs @@ -625,7 +625,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" @@ -640,9 +640,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 @@ -694,7 +699,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" @@ -709,9 +714,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 @@ -768,7 +778,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" @@ -783,9 +793,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 @@ -1080,7 +1095,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" @@ -1095,9 +1110,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 @@ -1290,7 +1310,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" @@ -1305,9 +1325,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 3262bba0d05db7cf4effc838ef7d67c0b7b8d19f 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/5] 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 55f5b352523d00297627c861e7e05b2bb06c449d 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/5] 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 315b95903..96e712de3 100644 --- a/crates/stackable-operator/CHANGELOG.md +++ b/crates/stackable-operator/CHANGELOG.md @@ -6,9 +6,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 From d8849ca70b6d73fa17a80b82384722755f82217f 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/5] 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 704b60a25dc04393ab1510cd6f02573d6040639b 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/5] use insta for snapshot tests --- Cargo.lock | 1 + 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 +----------------- 12 files changed, 894 insertions(+), 902 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 02573c11a..e1cc1c5d3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3857,6 +3857,7 @@ dependencies = [ "http", "indexmap", "indoc", + "insta", "java-properties", "jiff", "json-patch", diff --git a/crates/stackable-operator/Cargo.toml b/crates/stackable-operator/Cargo.toml index 86caf2e30..7c898880c 100644 --- a/crates/stackable-operator/Cargo.toml +++ b/crates/stackable-operator/Cargo.toml @@ -66,6 +66,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 5ad1bb03b..5b1577068 100644 --- a/crates/stackable-operator/src/crd/git_sync/v1alpha1_impl.rs +++ b/crates/stackable-operator/src/crd/git_sync/v1alpha1_impl.rs @@ -480,349 +480,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 -"#, - serde_yaml::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 -"#, - serde_yaml::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 -"#, - serde_yaml::to_string(&git_sync_resources.git_sync_containers.get(2)).unwrap() + insta::assert_snapshot!( + "multiple_git_syncs_containers", + serde_yaml::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 -", - serde_yaml::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 -", - serde_yaml::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 -", - serde_yaml::to_string(&git_sync_resources.git_sync_init_containers.get(2)).unwrap() + insta::assert_snapshot!( + "multiple_git_syncs_init_containers", + serde_yaml::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 da59054ab..93311f397 100644 --- a/crates/stackable-operator/src/crd/git_sync/v1alpha2_impl.rs +++ b/crates/stackable-operator/src/crd/git_sync/v1alpha2_impl.rs @@ -611,349 +611,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 -"#, - serde_yaml::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 -"#, - serde_yaml::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 -"#, - serde_yaml::to_string(&git_sync_resources.git_sync_containers.get(2)).unwrap() + insta::assert_snapshot!( + "multiple_git_syncs_containers", + serde_yaml::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 -", - serde_yaml::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 -", - serde_yaml::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 -", - serde_yaml::to_string(&git_sync_resources.git_sync_init_containers.get(2)).unwrap() + insta::assert_snapshot!( + "multiple_git_syncs_init_containers", + serde_yaml::to_string(&git_sync_resources.git_sync_init_containers).unwrap() ); assert_eq!(3, git_sync_resources.git_content_volumes.len()); @@ -1030,7 +697,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 @@ -1081,125 +747,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 -"#, - serde_yaml::to_string(&git_sync_resources.git_sync_containers.first()).unwrap() + insta::assert_snapshot!( + "git_sync_ssh_containers", + serde_yaml::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 -", - serde_yaml::to_string(&git_sync_resources.git_sync_init_containers.first()).unwrap() + insta::assert_snapshot!( + "git_sync_ssh_init_containers", + serde_yaml::to_string(&git_sync_resources.git_sync_init_containers).unwrap() ); assert_eq!(1, git_sync_resources.git_content_volumes.len()); @@ -1243,7 +800,6 @@ secret: } #[test] - #[allow(clippy::too_many_lines)] fn test_git_sync_ca_cert() { let git_sync_spec = r#" # GitSync using SSH @@ -1296,117 +852,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 -"#, - serde_yaml::to_string(&git_sync_resources.git_sync_containers.first()).unwrap() + insta::assert_snapshot!( + "git_sync_ca_cert_containers", + serde_yaml::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 -", - serde_yaml::to_string(&git_sync_resources.git_sync_init_containers.first()).unwrap() + insta::assert_snapshot!( + "git_sync_ca_cert_init_containers", + serde_yaml::to_string(&git_sync_resources.git_sync_init_containers).unwrap() ); assert_eq!(1, git_sync_resources.git_content_volumes.len());