Skip to content

Commit

Permalink
Use argocd appset generate to generate the Applications (#87)
Browse files Browse the repository at this point in the history
* Exit program if getting manifests for an application fails

* Generate Apps from AppSets

* Fixed not being able to generate app sets

* Moved all temporary generated files into its own folder

* Update Cargo version to 0.0.29

* Keep temp folder after program exits
  • Loading branch information
dag-andersen authored Jan 5, 2025
1 parent c40ef39 commit a3f0fbe
Show file tree
Hide file tree
Showing 8 changed files with 317 additions and 114 deletions.
5 changes: 2 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ secrets/
output/
.vscode/
/values.yaml
/apps_target_branch.yaml
/apps_base_branch.yaml
venv/
base-branch/
target-branch/
target-branch/
temp/
92 changes: 85 additions & 7 deletions Cargo.lock

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

7 changes: 4 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
[package]
name = "argocd-diff-preview"
version = "0.0.28"
version = "0.0.29"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
tokio = {version="1.42.0",features = ["full"]}
base64 = "0.22.1"
serde = "1.0.216"
serde = "1.0.217"
serde_yaml = "0.9.33"
serde_json = "1.0.134"
walkdir = "2.5.0"
Expand All @@ -17,4 +17,5 @@ structopt = { version = "0.3" }
regex = "1.11.1"
log = "0.4.22"
env_logger = "0.11.6"
once_cell = "1.20.2"
once_cell = "1.20.2"
rand = "0.8.5"
6 changes: 5 additions & 1 deletion src/argocd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use serde_yaml::Value;
use std::error::Error;

pub struct ArgoCDInstallation {
namespace: String,
pub namespace: String,
version: Option<String>,
config_path: String,
}
Expand Down Expand Up @@ -222,4 +222,8 @@ impl ArgoCDInstallation {
pub fn refresh_app(&self, app_name: &str) -> Result<CommandOutput, CommandOutput> {
self.run_argocd_command(&format!("argocd app get {} --refresh", app_name))
}

pub fn appset_generate(&self, app_set_path: &str) -> Result<CommandOutput, CommandOutput> {
self.run_argocd_command(&format!("argocd appset generate {} -o yaml", app_set_path))
}
}
18 changes: 13 additions & 5 deletions src/extract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,17 @@ pub async fn get_resources(
branch: &Branch,
timeout: u64,
output_folder: &str,
input_folder: &str,
) -> Result<(), Box<dyn Error>> {
info!("🌚 Getting resources from {}-branch", branch.branch_type);

let app_file = branch.app_file();
let app_file = &format!("{}/{}", input_folder, branch.app_file());

if fs::metadata(app_file)?.len() != 0 {
if fs::metadata(app_file)
.inspect_err(|_| error!("❌ File does not exist: {}", app_file))?
.len()
!= 0
{
apply_manifest(app_file).map_err(|e| {
error!(
"❌ Failed to apply applications for branch: {}",
Expand Down Expand Up @@ -90,11 +95,14 @@ pub async fn get_resources(
match argocd.get_manifests(name) {
Ok(o) => {
write_to_file(&format!("{}/{}", destination_folder, name), &o.stdout)?;
debug!("Got manifests for application: {}", name)
debug!("Got manifests for application: {}", name);
processed_apps.insert(name.to_string().clone());
}
Err(e) => {
error!("❌ Failed to get manifests for application: {}", name);
failed_apps.insert(name.to_string().clone(), e.stderr);
}
Err(e) => error!("error: {}", e.stderr),
}
processed_apps.insert(name.to_string().clone());
continue;
}
Some("Unknown") => {
Expand Down
Loading

0 comments on commit a3f0fbe

Please sign in to comment.