Skip to content

Commit

Permalink
Dependency upgrades + minor name changes (#103)
Browse files Browse the repository at this point in the history
  • Loading branch information
dag-andersen authored Jan 23, 2025
1 parent c51a2ed commit ec4e91a
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 37 deletions.
10 changes: 5 additions & 5 deletions Cargo.lock

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

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

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
Expand All @@ -10,12 +10,12 @@ tokio = {version="1.43.0",features = ["full"]}
base64 = "0.22.1"
serde = "1.0.217"
serde_yaml = "0.9.33"
serde_json = "1.0.134"
serde_json = "1.0.137"
walkdir = "2.5.0"
schemars = "0.8.21"
structopt = { version = "0.3" }
regex = "1.11.1"
log = "0.4.22"
log = "0.4.25"
env_logger = "0.11.6"
once_cell = "1.20.2"
rand = "0.8.5"
3 changes: 2 additions & 1 deletion makefile
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ run-with-cargo: pull-repository
--timeout $(timeout) \
-l "$(selector)" \
--argocd-namespace "$(argocd_namespace)" \
--files-changed="$(files_changed)"
--files-changed="$(files_changed)" \
--redirect-target-revisions="HEAD"

run-with-docker: pull-repository docker-build
docker run \
Expand Down
10 changes: 5 additions & 5 deletions src/argo_resource.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ impl ArgoResource {
mut self,
repo: &str,
branch: &str,
redirect_target_revisions: &Option<Vec<String>>,
redirect_revisions: &Option<Vec<String>>,
) -> Result<ArgoResource, Box<dyn Error>> {
let spec = match self.kind {
ApplicationKind::Application => self.yaml["spec"].as_mapping_mut(),
Expand All @@ -128,7 +128,7 @@ impl ArgoResource {
}
match spec["source"]["repoURL"].as_str() {
Some(url) if url.to_lowercase().contains(&repo.to_lowercase()) => {
let redirect = match redirect_target_revisions {
let redirect = match redirect_revisions {
Some(revisions) => revisions.iter().any(|revision| {
revision.as_str()
== spec["source"]["targetRevision"].as_str().unwrap_or("HEAD")
Expand Down Expand Up @@ -156,7 +156,7 @@ impl ArgoResource {
}
match source["repoURL"].as_str() {
Some(url) if url.to_lowercase().contains(&repo.to_lowercase()) => {
let redirect = match redirect_target_revisions {
let redirect = match redirect_revisions {
Some(revisions) => revisions.iter().any(|revision| {
revision.as_str()
== source["targetRevision"].as_str().unwrap_or("HEAD")
Expand Down Expand Up @@ -190,7 +190,7 @@ impl ArgoResource {
mut self,
repo: &str,
branch: &str,
redirect_target_revisions: &Option<Vec<String>>,
redirect_revisions: &Option<Vec<String>>,
) -> Result<ArgoResource, Box<dyn Error>> {
if self.kind != ApplicationKind::ApplicationSet {
return Ok(self);
Expand All @@ -202,7 +202,7 @@ impl ArgoResource {
None => Err(format!("No 'spec' key found in ApplicationSet: {}", self.name).into()),
Some(spec) => {
if spec.contains_key("generators")
&& redirect_git_generator(spec, repo, branch, redirect_target_revisions)
&& redirect_git_generator(spec, repo, branch, redirect_revisions)
{
debug!(
"Patched git generators in ApplicationSet: {} in file: {}",
Expand Down
10 changes: 5 additions & 5 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ async fn run() -> Result<(), Box<dyn Error>> {
return Err("Target branch folder does not exist".into());
}

let redirect_target_revisions = opt
let redirect_revisions = opt
.redirect_target_revisions
.filter(|s| !s.trim().is_empty())
.map(|s| {
Expand All @@ -304,7 +304,7 @@ async fn run() -> Result<(), Box<dyn Error>> {
revisions
});

if let Some(list) = &redirect_target_revisions {
if let Some(list) = &redirect_revisions {
info!(
"✨ - redirect-target-revisions: {}",
list.iter()
Expand All @@ -325,7 +325,7 @@ async fn run() -> Result<(), Box<dyn Error>> {
&files_changed,
repo,
opt.ignore_invalid_watch_pattern,
&redirect_target_revisions,
&redirect_revisions,
)?;

let found_base_apps = !base_apps.is_empty();
Expand Down Expand Up @@ -376,7 +376,7 @@ async fn run() -> Result<(), Box<dyn Error>> {
&base_branch,
repo,
temp_folder,
&redirect_target_revisions,
&redirect_revisions,
)?;
let base_apps = unique_names(base_apps, &base_branch);
let base_apps: Vec<ArgoResource> = base_apps
Expand All @@ -391,7 +391,7 @@ async fn run() -> Result<(), Box<dyn Error>> {
&target_branch,
repo,
temp_folder,
&redirect_target_revisions,
&redirect_revisions,
)?;
let target_apps = unique_names(target_apps, &target_branch);
let target_apps: Vec<ArgoResource> = target_apps
Expand Down
28 changes: 10 additions & 18 deletions src/parsing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ pub fn get_applications_for_branches(
files_changed: &Option<Vec<String>>,
repo: &str,
ignore_invalid_watch_pattern: bool,
redirect_target_revisions: &Option<Vec<String>>,
redirect_revisions: &Option<Vec<String>>,
) -> Result<(Vec<ArgoResource>, Vec<ArgoResource>), Box<dyn Error>> {
let base_apps = get_applications(
argo_cd_namespace,
Expand All @@ -42,7 +42,7 @@ pub fn get_applications_for_branches(
files_changed,
repo,
ignore_invalid_watch_pattern,
redirect_target_revisions,
redirect_revisions,
)?;
let target_apps = get_applications(
argo_cd_namespace,
Expand All @@ -52,7 +52,7 @@ pub fn get_applications_for_branches(
files_changed,
repo,
ignore_invalid_watch_pattern,
redirect_target_revisions,
redirect_revisions,
)?;

let duplicate_yaml = base_apps
Expand Down Expand Up @@ -125,7 +125,7 @@ fn get_applications(
files_changed: &Option<Vec<String>>,
repo: &str,
ignore_invalid_watch_pattern: bool,
redirect_target_revisions: &Option<Vec<String>>,
redirect_revisions: &Option<Vec<String>>,
) -> Result<Vec<ArgoResource>, Box<dyn Error>> {
let yaml_files = get_yaml_files(branch.folder_name(), regex);
let k8s_resources = parse_yaml(branch.folder_name(), yaml_files);
Expand All @@ -142,7 +142,7 @@ fn get_applications(
applications,
branch,
repo,
redirect_target_revisions,
redirect_revisions,
)?;
info!(
"🤖 Patching {} Argo CD Application[Sets] for branch: {}",
Expand Down Expand Up @@ -241,16 +241,16 @@ fn patch_application(
application: ArgoResource,
branch: &Branch,
repo: &str,
redirect_target_revisions: &Option<Vec<String>>,
redirect_revisions: &Option<Vec<String>>,
) -> Result<ArgoResource, Box<dyn Error>> {
let app_name = application.name.clone();
let app = application
.set_namespace(argo_cd_namespace)
.remove_sync_policy()
.set_project_to_default()
.and_then(|a| a.point_destination_to_in_cluster())
.and_then(|a| a.redirect_sources(repo, &branch.name, redirect_target_revisions))
.and_then(|a| a.redirect_generators(repo, &branch.name, redirect_target_revisions));
.and_then(|a| a.redirect_sources(repo, &branch.name, redirect_revisions))
.and_then(|a| a.redirect_generators(repo, &branch.name, redirect_revisions));

if app.is_err() {
error!("❌ Failed to patch application: {}", app_name);
Expand All @@ -264,19 +264,11 @@ fn patch_applications(
applications: Vec<ArgoResource>,
branch: &Branch,
repo: &str,
redirect_target_revisions: &Option<Vec<String>>,
redirect_revisions: &Option<Vec<String>>,
) -> Result<Vec<ArgoResource>, Box<dyn Error>> {
applications
.into_iter()
.map(|a| {
patch_application(
argo_cd_namespace,
a,
branch,
repo,
redirect_target_revisions,
)
})
.map(|a| patch_application(argo_cd_namespace, a, branch, repo, redirect_revisions))
.collect()
}

Expand Down

0 comments on commit ec4e91a

Please sign in to comment.