Skip to content

Commit

Permalink
Merge pull request #33 from omertuc/fixes
Browse files Browse the repository at this point in the history
Various fixes
  • Loading branch information
omertuc authored Oct 17, 2023
2 parents 616f377 + 3d62982 commit 8f45ba3
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 16 deletions.
3 changes: 1 addition & 2 deletions run_seed.sh
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,7 @@ cargo run --release -- \
--cn-san-replace *.apps.test-cluster.redhat.com:*.apps.new-name.foo.com \
--cn-san-replace 192.168.127.10:192.168.127.11 \
--summary-file summary.yaml \
--extend-expiration \
--dry-run
--extend-expiration
# --regenerate-server-ssh-keys backup/etc/ssh/ \

cargo run --manifest-path etcddump/Cargo.toml --release -- --etcd-endpoint localhost:2379 --output-dir backup/etcd
Expand Down
37 changes: 23 additions & 14 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,23 @@ fn main() -> Result<()> {
}

async fn main_internal(parsed_cli: ParsedCLI) -> Result<()> {
let mut cluster_crypto = ClusterCryptoObjects::new();

let summary_file = parsed_cli.summary_file.clone();

let run_result = run(parsed_cli, &mut cluster_crypto).await;

// Serialize cluster_crypto into the summary file if requested
if let Some(summary_file) = summary_file {
let summary_file = summary_file.create().context("opening summary file for writing")?;

serde_yaml::to_writer(summary_file, &cluster_crypto).context("serializing cluster crypto into summary file")?;
}

run_result
}

async fn run(parsed_cli: ParsedCLI, cluster_crypto: &mut ClusterCryptoObjects) -> std::result::Result<(), anyhow::Error> {
let _ouger_child_process = ouger::launch_ouger_server().await?;

let in_memory_etcd_client = Arc::new(InMemoryK8sEtcd::new(match parsed_cli.etcd_endpoint {
Expand All @@ -46,7 +63,8 @@ async fn main_internal(parsed_cli: ParsedCLI) -> Result<()> {
file_utils::DRY_RUN.store(true, Relaxed);
}

let cluster_crypto = recertify(
recertify(
cluster_crypto,
Arc::clone(&in_memory_etcd_client),
parsed_cli.static_dirs.clone(),
parsed_cli.static_files.clone(),
Expand All @@ -61,7 +79,6 @@ async fn main_internal(parsed_cli: ParsedCLI) -> Result<()> {
parsed_cli.cluster_rename,
parsed_cli.static_dirs,
parsed_cli.regenerate_server_ssh_keys.as_deref(),
parsed_cli.summary_file,
parsed_cli.dry_run,
)
.await
Expand All @@ -71,11 +88,12 @@ async fn main_internal(parsed_cli: ParsedCLI) -> Result<()> {
}

async fn recertify(
cluster_crypto: &mut ClusterCryptoObjects,
in_memory_etcd_client: Arc<InMemoryK8sEtcd>,
static_dirs: Vec<ClioPath>,
static_files: Vec<ClioPath>,
customizations: Customizations,
) -> Result<ClusterCryptoObjects> {
) -> Result<()> {
if in_memory_etcd_client.etcd_client.is_some() {
scanning::discover_external_certs(Arc::clone(&in_memory_etcd_client))
.await
Expand All @@ -92,21 +110,19 @@ async fn recertify(
let rsa_pool = rsa_keys.await?.context("generating rsa keys")?;

// We discovered all crypto objects, process them
let mut cluster_crypto = ClusterCryptoObjects::new();
cluster_crypto
.process_objects(all_discovered_crypto_objects, customizations, rsa_pool)
.context("processing discovered objects")?;

Ok(cluster_crypto)
Ok(())
}

async fn finalize(
in_memory_etcd_client: Arc<InMemoryK8sEtcd>,
mut cluster_crypto: ClusterCryptoObjects,
cluster_crypto: &mut ClusterCryptoObjects,
cluster_rename: Option<ClusterRenameParameters>,
static_dirs: Vec<ClioPath>,
regenerate_server_ssh_keys: Option<&Path>,
summary_file: Option<ClioPath>,
dry_run: bool,
) -> Result<()> {
cluster_crypto
Expand Down Expand Up @@ -137,12 +153,5 @@ async fn finalize(
.context("commiting etcd cache to actual etcd")?;
}

// Serialize cluster_crypto into the summary file if requested
if let Some(summary_file) = summary_file {
let summary_file = summary_file.create().context("opening summary file for writing")?;

serde_yaml::to_writer(summary_file, &cluster_crypto).context("serializing cluster crypto into summary file")?;
}

Ok(())
}

0 comments on commit 8f45ba3

Please sign in to comment.