Skip to content

Commit

Permalink
Fix delete job
Browse files Browse the repository at this point in the history
  • Loading branch information
ausias-armesto committed Jan 15, 2025
1 parent 273accc commit 594466b
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 39 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "hoprd_operator"
version = "0.2.22"
version = "0.2.23"
authors = ["HOPR Association <[email protected]>"]
edition = "2021"

Expand Down
39 changes: 2 additions & 37 deletions src/hoprd/hoprd_deployment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -263,42 +263,7 @@ pub async fn job_delete_database(context_data: Arc<ContextData>, deployment_name
let api: Api<Job> = Api::namespaced(context_data.client.clone(), namespace);
let rng = rand::thread_rng();
let suffix: String = rng.sample_iter(&Alphanumeric).take(10).map(char::from).collect();
let bucket_name = context_data
.config
.bucket_name
.as_ref()
.expect("No bucket name has been specified in hoprd operator configuration")
.clone();
let commands = format!(
r#"
set -e # Exit on any error
if ! apt-get -qq update && apt-get -qq -y install curl tar; then
echo "Failed to install required packages" >&2
exit 1
fi
# Cleanup old database files
rm -rf /app/hoprd-db/db/hopr_index.db* /app/hoprd-db/db/hopr_logs.db*
# Download and verify tarball
TARBALL="/tmp/hopr_logs.tar.gz"
if ! curl -sf --retry 3 "https://storage.googleapis.com/{}/hopr_logs.tar.gz" -o "$TARBALL"; then
echo "Failed to download database snapshot" >&2
exit 1
fi
# Extract tarball
if ! tar xf "$TARBALL" -C /; then
echo "Failed to extract database snapshot" >&2
rm -f "$TARBALL"
exit 1
fi
# Cleanup
rm -f "$TARBALL"
"#,
bucket_name
);
let command = "rm -rf /app/hoprd-db/db/hopr_index.db* /app/hoprd-db/db/hopr_logs.db*".to_string();

let job_name = format!("{}-delete-db-{}", deployment_name, suffix.to_lowercase());
let job = Job {
Expand All @@ -320,7 +285,7 @@ pub async fn job_delete_database(context_data: Arc<ContextData>, deployment_name
containers: vec![Container {
name: "delete-hoprd-db".to_string(),
image: Some("debian:stable".to_string()),
command: Some(vec!["/bin/sh".to_string(), "-c".to_string(), commands]),
command: Some(vec!["/bin/sh".to_string(), "-c".to_string(), command]),
volume_mounts: Some(vec![VolumeMount {
name: "hoprd-db".to_string(),
mount_path: "/app/hoprd-db".to_string(),
Expand Down

0 comments on commit 594466b

Please sign in to comment.