From 5b714d0fdd052bc79206ea3bdd89a61e9352c474 Mon Sep 17 00:00:00 2001 From: Frank Lin Date: Thu, 28 May 2026 11:39:20 +1000 Subject: [PATCH 1/6] add qualified app names --- .../ArgoCD/ArgoCDFilesUpdatedReporterTests.cs | 52 +++++++++---------- .../ArgoCDOutputVariablesWriterTests.cs | 31 ++++++----- .../Conventions/ArgoCDApplicationBuilder.cs | 8 +++ ...goCDAppImagesInstallConventionHelmTests.cs | 25 ++++----- ...ateArgoCDAppImagesInstallConventionTest.cs | 14 ++--- ...licationManifestsInstallConventionTests.cs | 16 +++--- .../ArgoCD/ArgoCDOutputVariablesWriter.cs | 16 +++--- .../ApplicationSourceUpdater.cs | 2 +- .../ManifestTemplating/ApplicationUpdater.cs | 2 +- .../ApplicationSourceUpdater.cs | 2 +- .../UpdateImageTag/ApplicationUpdater.cs | 2 +- .../ArgoCD/Models/QualifiedApplicationName.cs | 14 +++++ .../ArgoCD/ProcessApplicationResult.cs | 4 +- 13 files changed, 107 insertions(+), 81 deletions(-) create mode 100644 source/Calamari/ArgoCD/Models/QualifiedApplicationName.cs diff --git a/source/Calamari.Tests/ArgoCD/ArgoCDFilesUpdatedReporterTests.cs b/source/Calamari.Tests/ArgoCD/ArgoCDFilesUpdatedReporterTests.cs index 5805e1bab3..7b997c35d6 100644 --- a/source/Calamari.Tests/ArgoCD/ArgoCDFilesUpdatedReporterTests.cs +++ b/source/Calamari.Tests/ArgoCD/ArgoCDFilesUpdatedReporterTests.cs @@ -27,7 +27,7 @@ public void ReportDeployments_WhenGitParamsRequirePullRequest_WritesNoServiceMes var applicationResults = new List { new("gateway1", - new ApplicationName("app1"), + QualifiedApplicationName.Create("app1", "argocd"), 2, 2, [ @@ -56,7 +56,7 @@ public void ReportDeployments_WithNoUpdatedApplications_WritesNoServiceMessages( var applicationResults = new List { new("gateway1", - new ApplicationName("app1"), + QualifiedApplicationName.Create("app1", "argocd"), 2, 2, [], @@ -81,7 +81,7 @@ public void ReportDeployments_WithSingleUpdatedApplication_WritesOneServiceMessa var applicationResults = new List { new("gateway1", - new ApplicationName("app1"), + QualifiedApplicationName.Create("app1", "argocd"), 2, 2, [ @@ -106,7 +106,7 @@ public void ReportDeployments_WithSingleUpdatedApplication_WritesOneServiceMessa Properties = new Dictionary { ["gatewayId"] = "gateway1", - ["applicationName"] = "app1", + ["applicationName"] = "argocd/app1", ["sources"] = $"[{{\"CommitSha\":\"abc123\",\"CommitTimestamp\":\"{tsJson}\",\"SourceIndex\":0,\"ReplacedFiles\":[],\"PatchedFiles\":[]}}]" } }); @@ -123,7 +123,7 @@ public void ReportDeployments_WithMultipleUpdatedApplications_WritesMultipleServ var applicationResults = new List { new("gateway1", - new ApplicationName("app1"), + QualifiedApplicationName.Create("app1", "argocd"), 2, 2, [ @@ -136,7 +136,7 @@ public void ReportDeployments_WithMultipleUpdatedApplications_WritesMultipleServ [], []), new("gateway2", - new ApplicationName("app2"), + QualifiedApplicationName.Create("app2", "argocd"), 1, 1, [ @@ -160,7 +160,7 @@ public void ReportDeployments_WithMultipleUpdatedApplications_WritesMultipleServ Properties = new Dictionary { ["gatewayId"] = "gateway1", - ["applicationName"] = "app1", + ["applicationName"] = "argocd/app1", ["sources"] = $"[{{\"CommitSha\":\"abc123\",\"CommitTimestamp\":\"{tsJson}\",\"SourceIndex\":0,\"ReplacedFiles\":[],\"PatchedFiles\":[]}}]" } }, @@ -170,7 +170,7 @@ public void ReportDeployments_WithMultipleUpdatedApplications_WritesMultipleServ Properties = new Dictionary { ["gatewayId"] = "gateway2", - ["applicationName"] = "app2", + ["applicationName"] = "argocd/app2", ["sources"] = $"[{{\"CommitSha\":\"def456\",\"CommitTimestamp\":\"{tsJson}\",\"SourceIndex\":0,\"ReplacedFiles\":[],\"PatchedFiles\":[]}}]" } } @@ -188,7 +188,7 @@ public void ReportDeployments_WithReplacedFiles_IncludesReplacedFilesInSources() var applicationResults = new List { new("gateway1", - new ApplicationName("app1"), + QualifiedApplicationName.Create("app1", "argocd"), 2, 2, [ @@ -213,7 +213,7 @@ [new FileHash("values.yaml", "22c0df2cceca5273e4dc569dda52805d27df3360")], Properties = new Dictionary { ["gatewayId"] = "gateway1", - ["applicationName"] = "app1", + ["applicationName"] = "argocd/app1", ["sources"] = $"[{{\"CommitSha\":\"abc123\",\"CommitTimestamp\":\"{tsJson}\",\"SourceIndex\":0,\"ReplacedFiles\":[{{\"FilePath\":\"values.yaml\",\"Hash\":\"22c0df2cceca5273e4dc569dda52805d27df3360\"}}],\"PatchedFiles\":[]}}]" } }); @@ -230,7 +230,7 @@ public void ReportDeployments_WithPatchedFiles_IncludesPatchedFilesInSources() var applicationResults = new List { new("gateway1", - new ApplicationName("app1"), + QualifiedApplicationName.Create("app1", "argocd"), 1, 1, [ @@ -255,7 +255,7 @@ [new FileJsonPatch("kustomization.yaml", """[{"op":"replace","path":"/images/0/n Properties = new Dictionary { ["gatewayId"] = "gateway1", - ["applicationName"] = "app1", + ["applicationName"] = "argocd/app1", ["sources"] = $"[{{\"CommitSha\":\"def456\",\"CommitTimestamp\":\"{tsJson}\",\"SourceIndex\":0,\"ReplacedFiles\":[],\"PatchedFiles\":[{{\"FilePath\":\"kustomization.yaml\",\"JsonPatch\":\"[{{\\u0022op\\u0022:\\u0022replace\\u0022,\\u0022path\\u0022:\\u0022/images/0/name\\u0022,\\u0022value\\u0022:\\u0022nginx:latest\\u0022}}]\"}}]}}]" } }); @@ -272,7 +272,7 @@ public void ReportDeployments_WithBothReplacedAndPatchedFiles_IncludesBothInSour var applicationResults = new List { new("gateway1", - new ApplicationName("app1"), + QualifiedApplicationName.Create("app1", "argocd"), 2, 2, [ @@ -297,7 +297,7 @@ [new FileJsonPatch("kustomization.yaml", """[{"op":"replace","path":"/images/0/n Properties = new Dictionary { ["gatewayId"] = "gateway1", - ["applicationName"] = "app1", + ["applicationName"] = "argocd/app1", ["sources"] = $"[{{\"CommitSha\":\"abc123\",\"CommitTimestamp\":\"{tsJson}\",\"SourceIndex\":0,\"ReplacedFiles\":[{{\"FilePath\":\"values.yaml\",\"Hash\":\"22c0df2cceca5273e4dc569dda52805d27df3360\"}}],\"PatchedFiles\":[{{\"FilePath\":\"kustomization.yaml\",\"JsonPatch\":\"[{{\\u0022op\\u0022:\\u0022replace\\u0022,\\u0022path\\u0022:\\u0022/images/0/name\\u0022,\\u0022value\\u0022:\\u0022nginx:latest\\u0022}}]\"}}]}}]" } }); @@ -314,7 +314,7 @@ public void ReportDeployments_WithMultipleReplacedAndPatchedFiles_IncludesAllFil var applicationResults = new List { new("gateway1", - new ApplicationName("app1"), + QualifiedApplicationName.Create("app1", "argocd"), 2, 2, [ @@ -345,7 +345,7 @@ public void ReportDeployments_WithMultipleReplacedAndPatchedFiles_IncludesAllFil Properties = new Dictionary { ["gatewayId"] = "gateway1", - ["applicationName"] = "app1", + ["applicationName"] = "argocd/app1", ["sources"] = $"[{{\"CommitSha\":\"abc123\",\"CommitTimestamp\":\"{tsJson}\",\"SourceIndex\":0,\"ReplacedFiles\":[{{\"FilePath\":\"values.yaml\",\"Hash\":\"22c0df2cceca5273e4dc569dda52805d27df3360\"}},{{\"FilePath\":\"values-prod.yaml\",\"Hash\":\"a3b4c5d6e7f8a3b4c5d6e7f8a3b4c5d6e7f8a3b4\"}}],\"PatchedFiles\":[{{\"FilePath\":\"kustomization.yaml\",\"JsonPatch\":\"[{{\\u0022op\\u0022:\\u0022replace\\u0022,\\u0022path\\u0022:\\u0022/images/0/name\\u0022,\\u0022value\\u0022:\\u0022nginx:latest\\u0022}}]\"}},{{\"FilePath\":\"patch.yaml\",\"JsonPatch\":\"[{{\\u0022op\\u0022:\\u0022replace\\u0022,\\u0022path\\u0022:\\u0022/spec/replicas\\u0022,\\u0022value\\u0022:3}}]\"}}]}}]" } }); @@ -362,7 +362,7 @@ public void ReportDeployments_WithMultipleSourcesWithFiles_IncludesAllSourcesInS var applicationResults = new List { new("gateway1", - new ApplicationName("app1"), + QualifiedApplicationName.Create("app1", "argocd"), 2, 2, [ @@ -392,7 +392,7 @@ [new FileJsonPatch("kustomization.yaml", """[{"op":"replace","path":"/images/0/n Properties = new Dictionary { ["gatewayId"] = "gateway1", - ["applicationName"] = "app1", + ["applicationName"] = "argocd/app1", ["sources"] = $"[{{\"CommitSha\":\"abc123\",\"CommitTimestamp\":\"{tsJson}\",\"SourceIndex\":0,\"ReplacedFiles\":[{{\"FilePath\":\"values.yaml\",\"Hash\":\"22c0df2cceca5273e4dc569dda52805d27df3360\"}}],\"PatchedFiles\":[]}},{{\"CommitSha\":\"abc123\",\"CommitTimestamp\":\"{tsJson}\",\"SourceIndex\":1,\"ReplacedFiles\":[],\"PatchedFiles\":[{{\"FilePath\":\"kustomization.yaml\",\"JsonPatch\":\"[{{\\u0022op\\u0022:\\u0022replace\\u0022,\\u0022path\\u0022:\\u0022/images/0/name\\u0022,\\u0022value\\u0022:\\u0022redis:latest\\u0022}}]\"}}]}}]" } }); @@ -409,7 +409,7 @@ public void ReportDeployments_WithOsSpecificReplacedFilePaths_ReportsPosixPaths( var applicationResults = new List { new("gateway1", - new ApplicationName("app1"), + QualifiedApplicationName.Create("app1", "argocd"), 1, 1, [ @@ -434,7 +434,7 @@ [new FileHash(Path.Combine("some", "nested", "values.yaml"), "22c0df2cceca5273e4 Properties = new Dictionary { ["gatewayId"] = "gateway1", - ["applicationName"] = "app1", + ["applicationName"] = "argocd/app1", ["sources"] = $"[{{\"CommitSha\":\"abc123\",\"CommitTimestamp\":\"{tsJson}\",\"SourceIndex\":0,\"ReplacedFiles\":[{{\"FilePath\":\"some/nested/values.yaml\",\"Hash\":\"22c0df2cceca5273e4dc569dda52805d27df3360\"}}],\"PatchedFiles\":[]}}]" } }); @@ -449,7 +449,7 @@ public void ReportDeployments_WithNoOpSource_EmitsServiceMessageWithNullCommitSh var applicationResults = new List { new("gateway1", - new ApplicationName("app1"), + QualifiedApplicationName.Create("app1", "argocd"), 1, 1, [ @@ -474,7 +474,7 @@ [new FileJsonPatch("values.yaml", """[{"op":"replace","path":"/image","value":"n Properties = new Dictionary { ["gatewayId"] = "gateway1", - ["applicationName"] = "app1", + ["applicationName"] = "argocd/app1", ["sources"] = """[{"CommitSha":null,"CommitTimestamp":null,"SourceIndex":0,"ReplacedFiles":[],"PatchedFiles":[{"FilePath":"values.yaml","JsonPatch":"[{\u0022op\u0022:\u0022replace\u0022,\u0022path\u0022:\u0022/image\u0022,\u0022value\u0022:\u0022nginx:1.27\u0022}]"}]}]""" } }); @@ -491,14 +491,14 @@ public void ReportDeployments_WithMixedUpdatedAndNonUpdatedApplications_WritesOn var applicationResults = new List { new("gateway1", - new ApplicationName("app1"), + QualifiedApplicationName.Create("app1", "argocd"), 2, 2, [], [], []), new("gateway2", - new ApplicationName("app2"), + QualifiedApplicationName.Create("app2", "argocd"), 1, 1, [ @@ -511,7 +511,7 @@ public void ReportDeployments_WithMixedUpdatedAndNonUpdatedApplications_WritesOn [], []), new("gateway3", - new ApplicationName("app3"), + QualifiedApplicationName.Create("app3", "argocd"), 1, 1, [], @@ -530,7 +530,7 @@ public void ReportDeployments_WithMixedUpdatedAndNonUpdatedApplications_WritesOn Properties = new Dictionary { ["gatewayId"] = "gateway2", - ["applicationName"] = "app2", + ["applicationName"] = "argocd/app2", ["sources"] = $"[{{\"CommitSha\":\"abc123\",\"CommitTimestamp\":\"{tsJson}\",\"SourceIndex\":0,\"ReplacedFiles\":[],\"PatchedFiles\":[]}}]" } }); diff --git a/source/Calamari.Tests/ArgoCD/ArgoCDOutputVariablesWriterTests.cs b/source/Calamari.Tests/ArgoCD/ArgoCDOutputVariablesWriterTests.cs index ee213eaa33..80e038cd01 100644 --- a/source/Calamari.Tests/ArgoCD/ArgoCDOutputVariablesWriterTests.cs +++ b/source/Calamari.Tests/ArgoCD/ArgoCDOutputVariablesWriterTests.cs @@ -2,6 +2,7 @@ using Calamari.ArgoCD; using Calamari.ArgoCD.Conventions; using Calamari.ArgoCD.Git; +using Calamari.ArgoCD.Models; using Calamari.Common.Plumbing.ServiceMessages; using Calamari.Common.Plumbing.Variables; using Calamari.Testing.Helpers; @@ -19,6 +20,8 @@ public class ArgoCDOutputVariablesWriterTests const string GatewayName = "TestGateway"; const string ApplicationName = "TestApp"; + const string ApplicationNamespace = "argocd"; + static readonly QualifiedApplicationName QualifiedApplicationName = QualifiedApplicationName.Create(ApplicationName, ApplicationNamespace); const string CommitSha = "1234567890abcdef1234567890abcdef12345678"; const string ShortSha = "1234567"; static readonly DateTimeOffset Timestamp = DateTimeOffset.UtcNow; @@ -43,7 +46,7 @@ public void WriteSourceUpdateResultOutputWhenPushResultExists_NoPushResult_NoOut var sourceUpdateResult = new SourceUpdateResult([], null, [], []); // Act - writer.WriteSourceUpdateResultOutputWhenPushResultExists(GatewayName, ApplicationName, sourceIndex, sourceUpdateResult); + writer.WriteSourceUpdateResultOutputWhenPushResultExists(GatewayName, QualifiedApplicationName, sourceIndex, sourceUpdateResult); // Assert using var _ = new AssertionScope(); @@ -65,7 +68,7 @@ public void WriteSourceUpdateResultOutputWhenPushResultExists_WithoutPullRequest var sourceUpdateResult = new SourceUpdateResult([], pullResult, [], []); // Act - writer.WriteSourceUpdateResultOutputWhenPushResultExists(GatewayName, ApplicationName, sourceIndex, sourceUpdateResult); + writer.WriteSourceUpdateResultOutputWhenPushResultExists(GatewayName, QualifiedApplicationName, sourceIndex, sourceUpdateResult); // Assert using var _ = new AssertionScope(); @@ -94,7 +97,7 @@ public void WritePushResultOutput_WithPullRequest_WritesCommitAndPullRequestOutp var sourceUpdateResult = new SourceUpdateResult([], pullRequestPushResult, [], []); // Act - writer.WriteSourceUpdateResultOutputWhenPushResultExists(GatewayName, ApplicationName, sourceIndex, sourceUpdateResult); + writer.WriteSourceUpdateResultOutputWhenPushResultExists(GatewayName, QualifiedApplicationName, sourceIndex, sourceUpdateResult); // Assert using var _ = new AssertionScope(); @@ -128,8 +131,8 @@ public void WritePushResultOutput_WithMultipleSources_WritesVariablesWithCorrect var sourceUpdateResult2 = new SourceUpdateResult([], pushResult2, [], []); // Act - writer.WriteSourceUpdateResultOutputWhenPushResultExists(GatewayName, ApplicationName, 0, sourceUpdateResult1); - writer.WriteSourceUpdateResultOutputWhenPushResultExists(GatewayName, ApplicationName, 1, sourceUpdateResult2); + writer.WriteSourceUpdateResultOutputWhenPushResultExists(GatewayName, QualifiedApplicationName, 0, sourceUpdateResult1); + writer.WriteSourceUpdateResultOutputWhenPushResultExists(GatewayName, QualifiedApplicationName, 1, sourceUpdateResult2); // Assert using var _ = new AssertionScope(); @@ -150,16 +153,16 @@ public void WritePushResultOutput_WithMultipleSources_WritesVariablesWithCorrect //Zero = No (but NO COMMIT is part of the forbidden words list) static void AssertZeroCommitVariables(ServiceMessage[] serviceMessages, int sourceIndex) { - serviceMessages.GetPropertyValue($"ArgoCD.Gateway[{GatewayName}].Application[{ApplicationName}].Source[{sourceIndex}].CommitSha").Should().BeNull(); - serviceMessages.GetPropertyValue($"ArgoCD.Gateway[{GatewayName}].Application[{ApplicationName}].Source[{sourceIndex}].ShortSha").Should().BeNull(); - serviceMessages.GetPropertyValue($"ArgoCD.Gateway[{GatewayName}].Application[{ApplicationName}].Source[{sourceIndex}].CommitTimestamp").Should().BeNull(); + serviceMessages.GetPropertyValue($"ArgoCD.Gateway[{GatewayName}].Application[{QualifiedApplicationName}].Source[{sourceIndex}].CommitSha").Should().BeNull(); + serviceMessages.GetPropertyValue($"ArgoCD.Gateway[{GatewayName}].Application[{QualifiedApplicationName}].Source[{sourceIndex}].ShortSha").Should().BeNull(); + serviceMessages.GetPropertyValue($"ArgoCD.Gateway[{GatewayName}].Application[{QualifiedApplicationName}].Source[{sourceIndex}].CommitTimestamp").Should().BeNull(); } static void AssertCommitVariables(ServiceMessage[] serviceMessages, int sourceIndex, string commitSha = CommitSha, string shortSha = ShortSha) { - serviceMessages.GetPropertyValue($"ArgoCD.Gateway[{GatewayName}].Application[{ApplicationName}].Source[{sourceIndex}].CommitSha").Should().Be(commitSha); - serviceMessages.GetPropertyValue($"ArgoCD.Gateway[{GatewayName}].Application[{ApplicationName}].Source[{sourceIndex}].ShortSha").Should().Be(shortSha); - serviceMessages.GetPropertyValue($"ArgoCD.Gateway[{GatewayName}].Application[{ApplicationName}].Source[{sourceIndex}].CommitTimestamp").Should().Be(Timestamp.ToString("o")); + serviceMessages.GetPropertyValue($"ArgoCD.Gateway[{GatewayName}].Application[{QualifiedApplicationName}].Source[{sourceIndex}].CommitSha").Should().Be(commitSha); + serviceMessages.GetPropertyValue($"ArgoCD.Gateway[{GatewayName}].Application[{QualifiedApplicationName}].Source[{sourceIndex}].ShortSha").Should().Be(shortSha); + serviceMessages.GetPropertyValue($"ArgoCD.Gateway[{GatewayName}].Application[{QualifiedApplicationName}].Source[{sourceIndex}].CommitTimestamp").Should().Be(Timestamp.ToString("o")); } static void AssertNoPullRequestVariables(ServiceMessage[] serviceMessages, int sourceIndex) @@ -171,9 +174,9 @@ static void AssertNoPullRequestVariables(ServiceMessage[] serviceMessages, int s static void AssertPullRequestVariables(ServiceMessage[] serviceMessages, int sourceIndex) { - serviceMessages.GetPropertyValue($"ArgoCD.Gateway[{GatewayName}].Application[{ApplicationName}].Source[{sourceIndex}].PullRequest.Title").Should().Be(PrTitle); - serviceMessages.GetPropertyValue($"ArgoCD.Gateway[{GatewayName}].Application[{ApplicationName}].Source[{sourceIndex}].PullRequest.Number").Should().Be(PrNumber.ToString()); - serviceMessages.GetPropertyValue($"ArgoCD.Gateway[{GatewayName}].Application[{ApplicationName}].Source[{sourceIndex}].PullRequest.Url").Should().Be(PrUrl); + serviceMessages.GetPropertyValue($"ArgoCD.Gateway[{GatewayName}].Application[{QualifiedApplicationName}].Source[{sourceIndex}].PullRequest.Title").Should().Be(PrTitle); + serviceMessages.GetPropertyValue($"ArgoCD.Gateway[{GatewayName}].Application[{QualifiedApplicationName}].Source[{sourceIndex}].PullRequest.Number").Should().Be(PrNumber.ToString()); + serviceMessages.GetPropertyValue($"ArgoCD.Gateway[{GatewayName}].Application[{QualifiedApplicationName}].Source[{sourceIndex}].PullRequest.Url").Should().Be(PrUrl); } static void AssertPullRequestCreatedServiceMessage(ServiceMessage[] serviceMessages, PullRequestPushResult pushResult) diff --git a/source/Calamari.Tests/ArgoCD/Commands/Conventions/ArgoCDApplicationBuilder.cs b/source/Calamari.Tests/ArgoCD/Commands/Conventions/ArgoCDApplicationBuilder.cs index 3cbe0b4708..506cc1f350 100644 --- a/source/Calamari.Tests/ArgoCD/Commands/Conventions/ArgoCDApplicationBuilder.cs +++ b/source/Calamari.Tests/ArgoCD/Commands/Conventions/ArgoCDApplicationBuilder.cs @@ -7,6 +7,7 @@ namespace Calamari.Tests.ArgoCD.Commands.Conventions class ArgoCDApplicationBuilder { string name = "My App"; + string @namespace = "argocd"; Dictionary annotations = new Dictionary(); readonly List applicationSources = new List(); readonly List applicationSourceTypes = new List(); @@ -17,6 +18,12 @@ public ArgoCDApplicationBuilder WithName(string value) return this; } + public ArgoCDApplicationBuilder WithNamespace(string value) + { + @namespace = value; + return this; + } + public ArgoCDApplicationBuilder WithAnnotations(Dictionary value) { annotations = value; @@ -47,6 +54,7 @@ public Application Build() Metadata = new Metadata() { Name = name, + Namespace = @namespace, Annotations = annotations }, Spec = new ApplicationSpec() diff --git a/source/Calamari.Tests/ArgoCD/Commands/Conventions/UpdateArgoCDAppImagesInstallConventionHelmTests.cs b/source/Calamari.Tests/ArgoCD/Commands/Conventions/UpdateArgoCDAppImagesInstallConventionHelmTests.cs index 615cdc2245..e96484a9bc 100644 --- a/source/Calamari.Tests/ArgoCD/Commands/Conventions/UpdateArgoCDAppImagesInstallConventionHelmTests.cs +++ b/source/Calamari.Tests/ArgoCD/Commands/Conventions/UpdateArgoCDAppImagesInstallConventionHelmTests.cs @@ -107,6 +107,7 @@ public void Init() Metadata = new Metadata() { Name = "App1", + Namespace = "argocd", Annotations = new Dictionary() { [ArgoCDConstants.Annotations.OctopusProjectAnnotationKey(null)] = ProjectSlug, @@ -174,7 +175,7 @@ public void HelmSource_NoPath_DontUpdate() originRepo.AddFilesToBranch(argoCDBranchName, filesInRepo); var argoCDAppWithHelmSource = new ArgoCDApplicationBuilder() - .WithName("App1") + .WithName("App1").WithNamespace("argocd") .WithAnnotations(new Dictionary() { [ArgoCDConstants.Annotations.OctopusProjectAnnotationKey(null)] = ProjectSlug, @@ -828,7 +829,7 @@ public void HelmSourceWithHelmConfigurationAndImplicitValuesFile_IncludeValuesFi originRepo.AddFilesToBranch(argoCDBranchName, filesInRepo); var argoCDAppWithHelmSource = new ArgoCDApplicationBuilder() - .WithName("App1") + .WithName("App1").WithNamespace("argocd") .WithAnnotations(new Dictionary() { [ArgoCDConstants.Annotations.OctopusProjectAnnotationKey(null)] = ProjectSlug, @@ -911,7 +912,7 @@ public void HelmSourceWithHelmConfigurationAndNoImplicitValuesFile_ExcludeValues originRepo.AddFilesToBranch(argoCDBranchName, filesInRepo); var argoCDAppWithHelmSource = new ArgoCDApplicationBuilder() - .WithName("App1") + .WithName("App1").WithNamespace("argocd") .WithAnnotations(new Dictionary() { [ArgoCDConstants.Annotations.OctopusProjectAnnotationKey(null)] = ProjectSlug, @@ -995,7 +996,7 @@ public void HelmSourceWithHelmConfigurationIncludesImplicitValuesFile_IncludeVal originRepo.AddFilesToBranch(argoCDBranchName, filesInRepo); var argoCDAppWithHelmSource = new ArgoCDApplicationBuilder() - .WithName("App1") + .WithName("App1").WithNamespace("argocd") .WithAnnotations(new Dictionary() { [ArgoCDConstants.Annotations.OctopusProjectAnnotationKey(null)] = ProjectSlug, @@ -1081,7 +1082,7 @@ public void HelmSourceWithImplicitValuesFile_Update() originRepo.AddFilesToBranch(argoCDBranchName, filesInRepo); var argoCDAppWithHelmSource = new ArgoCDApplicationBuilder() - .WithName("App1") + .WithName("App1").WithNamespace("argocd") .WithAnnotations(new Dictionary() { [ArgoCDConstants.Annotations.OctopusProjectAnnotationKey(null)] = ProjectSlug, @@ -1162,7 +1163,7 @@ public void RefSourceWithHelmImageMatches_Update() originRepo.AddFilesToBranch(argoCDBranchName, filesInRepo); var argoCDAppWithHelmSource = new ArgoCDApplicationBuilder() - .WithName("App1") + .WithName("App1").WithNamespace("argocd") .WithAnnotations(new Dictionary() { [ArgoCDConstants.Annotations.OctopusProjectAnnotationKey(new ApplicationSourceName("ref-source"))] = ProjectSlug, @@ -1293,7 +1294,7 @@ public void RefSourceWithHelmImageMatchesAndPath_IgnoresFilesUnderPath() originRepo.AddFilesToBranch(argoCDBranchName, filesInRepo); var argoCDAppWithHelmSource = new ArgoCDApplicationBuilder() - .WithName("App1") + .WithName("App1").WithNamespace("argocd") .WithAnnotations(new Dictionary() { [ArgoCDConstants.Annotations.OctopusProjectAnnotationKey(new ApplicationSourceName("ref-source"))] = ProjectSlug, @@ -1448,7 +1449,7 @@ public void CanUpdateRefSourceUsingStepBasedVariables() originRepo.AddFilesToBranch(argoCDBranchName, filesInRepo); var argoCDAppWithHelmSource = new ArgoCDApplicationBuilder() - .WithName("App1") + .WithName("App1").WithNamespace("argocd") .WithAnnotations(new Dictionary() { [ArgoCDConstants.Annotations.OctopusProjectAnnotationKey(new ApplicationSourceName("ref-source"))] = ProjectSlug, @@ -1598,7 +1599,7 @@ public void CanUpdateHelmSourceUsingStepBasedVariables() originRepo.AddFilesToBranch(argoCDBranchName, filesInRepo); var argoCDAppWithHelmSource = new ArgoCDApplicationBuilder() - .WithName("App1") + .WithName("App1").WithNamespace("argocd") .WithAnnotations(new Dictionary() { [ArgoCDConstants.Annotations.OctopusProjectAnnotationKey(new ApplicationSourceName("helm-source"))] = ProjectSlug, @@ -1817,7 +1818,7 @@ void SetupRefSourceAppManifest( } var app = new ArgoCDApplicationBuilder() - .WithName("App1") + .WithName("App1").WithNamespace("argocd") .WithAnnotations(annotations) .WithSource(new ApplicationSource { @@ -1900,10 +1901,10 @@ void AssertOutputVariables(bool updated = true, string matchingApplicationTotalS serviceMessages.GetPropertyValue("ArgoCD.GatewayIds").Should().Be(GatewayId); serviceMessages.GetPropertyValue("ArgoCD.GitUris").Should().Be(updated ? OriginUrl : string.Empty); serviceMessages.GetPropertyValue("ArgoCD.UpdatedImages").Should().Be(updated ? updatedImages.ToString() : "0"); - serviceMessages.GetPropertyValue("ArgoCD.MatchingApplications").Should().Be("App1"); + serviceMessages.GetPropertyValue("ArgoCD.MatchingApplications").Should().Be("argocd/App1"); serviceMessages.GetPropertyValue("ArgoCD.MatchingApplicationTotalSourceCounts").Should().Be(matchingApplicationTotalSourceCounts); serviceMessages.GetPropertyValue("ArgoCD.MatchingApplicationMatchingSourceCounts").Should().Be(matchingApplicationMatchingSourceCounts); - serviceMessages.GetPropertyValue("ArgoCD.UpdatedApplications").Should().Be(updated ? "App1" : string.Empty); + serviceMessages.GetPropertyValue("ArgoCD.UpdatedApplications").Should().Be(updated ? "argocd/App1" : string.Empty); serviceMessages.GetPropertyValue("ArgoCD.UpdatedApplicationSourceCounts").Should().Be(updated ? "1" : string.Empty); if (updated) diff --git a/source/Calamari.Tests/ArgoCD/Commands/Conventions/UpdateArgoCDAppImagesInstallConventionTest.cs b/source/Calamari.Tests/ArgoCD/Commands/Conventions/UpdateArgoCDAppImagesInstallConventionTest.cs index 40bcc3480e..8dd0b2bdb1 100644 --- a/source/Calamari.Tests/ArgoCD/Commands/Conventions/UpdateArgoCDAppImagesInstallConventionTest.cs +++ b/source/Calamari.Tests/ArgoCD/Commands/Conventions/UpdateArgoCDAppImagesInstallConventionTest.cs @@ -98,7 +98,7 @@ public void Init() customPropertiesLoader.Load().Returns(argoCdCustomPropertiesDto); var argoCdApplicationFromYaml = new ArgoCDApplicationBuilder() - .WithName("App1") + .WithName("App1").WithNamespace("argocd") .WithAnnotations(new Dictionary() { [ArgoCDConstants.Annotations.OctopusProjectAnnotationKey(null)] = ProjectSlug, @@ -1052,7 +1052,7 @@ void OverrideApplicationSourceType(string sourceType, string path = "") { argoCdApplicationManifestParser.ParseManifest(Arg.Any()) .Returns(new ArgoCDApplicationBuilder() - .WithName("App1") + .WithName("App1").WithNamespace("argocd") .WithAnnotations(new Dictionary { [ArgoCDConstants.Annotations.OctopusProjectAnnotationKey(null)] = ProjectSlug, @@ -1123,7 +1123,7 @@ public void MultiSource_OneSourceUpdated_OtherAlreadyAtTarget_BothTracked() argoCdApplicationManifestParser.ParseManifest(Arg.Any()) .Returns(new ArgoCDApplicationBuilder() - .WithName("App1") + .WithName("App1").WithNamespace("argocd") .WithAnnotations(new Dictionary { [ArgoCDConstants.Annotations.OctopusProjectAnnotationKey(new ApplicationSourceName("source0"))] = ProjectSlug, @@ -1182,7 +1182,7 @@ public void MultiSource_BothSourcesAlreadyAtTarget_BothTrackedWithNullCommitSha( argoCdApplicationManifestParser.ParseManifest(Arg.Any()) .Returns(new ArgoCDApplicationBuilder() - .WithName("App1") + .WithName("App1").WithNamespace("argocd") .WithAnnotations(new Dictionary { [ArgoCDConstants.Annotations.OctopusProjectAnnotationKey(new ApplicationSourceName("source0"))] = ProjectSlug, @@ -1243,7 +1243,7 @@ public void MultiSource_OutOfScopeSource_IsNotTracked() argoCdApplicationManifestParser.ParseManifest(Arg.Any()) .Returns(new ArgoCDApplicationBuilder() - .WithName("App1") + .WithName("App1").WithNamespace("argocd") .WithAnnotations(new Dictionary { // source0 is annotated for a different project — out of scope for this deployment @@ -1302,10 +1302,10 @@ void AssertOutputVariables(bool updated = true, string matchingApplicationTotalS serviceMessages.GetPropertyValue("ArgoCD.GatewayIds").Should().Be(GatewayId); serviceMessages.GetPropertyValue("ArgoCD.GitUris").Should().Be(updated ? OriginUrl : string.Empty); serviceMessages.GetPropertyValue("ArgoCD.UpdatedImages").Should().Be(updated ? "1" : "0"); - serviceMessages.GetPropertyValue("ArgoCD.MatchingApplications").Should().Be("App1"); + serviceMessages.GetPropertyValue("ArgoCD.MatchingApplications").Should().Be("argocd/App1"); serviceMessages.GetPropertyValue("ArgoCD.MatchingApplicationTotalSourceCounts").Should().Be(matchingApplicationTotalSourceCounts); serviceMessages.GetPropertyValue("ArgoCD.MatchingApplicationMatchingSourceCounts").Should().Be("1"); - serviceMessages.GetPropertyValue("ArgoCD.UpdatedApplications").Should().Be(updated ? "App1" : string.Empty); + serviceMessages.GetPropertyValue("ArgoCD.UpdatedApplications").Should().Be(updated ? "argocd/App1" : string.Empty); serviceMessages.GetPropertyValue("ArgoCD.UpdatedApplicationSourceCounts").Should().Be(updated ? "1" : string.Empty); if (updated) diff --git a/source/Calamari.Tests/ArgoCD/Commands/Conventions/UpdateArgoCDApplicationManifestsInstallConventionTests.cs b/source/Calamari.Tests/ArgoCD/Commands/Conventions/UpdateArgoCDApplicationManifestsInstallConventionTests.cs index 702956e6ee..3ae4386c24 100644 --- a/source/Calamari.Tests/ArgoCD/Commands/Conventions/UpdateArgoCDApplicationManifestsInstallConventionTests.cs +++ b/source/Calamari.Tests/ArgoCD/Commands/Conventions/UpdateArgoCDApplicationManifestsInstallConventionTests.cs @@ -80,7 +80,7 @@ public void Init() customPropertiesLoader.Load().Returns(argoCdCustomPropertiesDto); var argoCdApplicationFromYaml = new ArgoCDApplicationBuilder() - .WithName("App1") + .WithName("App1").WithNamespace("argocd") .WithAnnotations(new Dictionary() { [ArgoCDConstants.Annotations.OctopusProjectAnnotationKey(null)] = ProjectSlug, @@ -232,7 +232,7 @@ public void CanTemplateFilesIntoAHelmSource() runningDeployment.StagingDirectory = WorkingDirectory; var argoCDAppWithHelmSource = new ArgoCDApplicationBuilder() - .WithName("App1") + .WithName("App1").WithNamespace("argocd") .WithAnnotations(new Dictionary() { [ArgoCDConstants.Annotations.OctopusProjectAnnotationKey(null)] = ProjectSlug, @@ -293,7 +293,7 @@ public void CanUpdateReferenceSource() runningDeployment.StagingDirectory = WorkingDirectory; var argoCDAppWithHelmSource = new ArgoCDApplicationBuilder() - .WithName("App1") + .WithName("App1").WithNamespace("argocd") .WithAnnotations(new Dictionary() { [ArgoCDConstants.Annotations.OctopusProjectAnnotationKey(new ApplicationSourceName("refSourceName"))] = ProjectSlug, @@ -362,7 +362,7 @@ public void WillNotUpdateAReferenceSourceWhichHasAPath() runningDeployment.StagingDirectory = WorkingDirectory; var argoCDAppWithHelmSource = new ArgoCDApplicationBuilder() - .WithName("App1") + .WithName("App1").WithNamespace("argocd") .WithAnnotations(new Dictionary() { [ArgoCDConstants.Annotations.OctopusProjectAnnotationKey(new ApplicationSourceName("refSourceName"))] = ProjectSlug, @@ -518,7 +518,7 @@ public void CanTemplateFilesIntoAnUnknownSource() runningDeployment.StagingDirectory = WorkingDirectory; var argoCDAppWithUnknownSource = new ArgoCDApplicationBuilder() - .WithName("App1") + .WithName("App1").WithNamespace("argocd") .WithAnnotations(new Dictionary() { [ArgoCDConstants.Annotations.OctopusProjectAnnotationKey(null)] = ProjectSlug, @@ -560,7 +560,7 @@ public void PathAnnotationOverridesTheOutputPath() // Arrange - create app with a path-override in the annotation var overriddenSubPath = Path.Combine("sub1", "sub2"); var argoCdApplicationFromYaml = new ArgoCDApplicationBuilder() - .WithName("App1") + .WithName("App1").WithNamespace("argocd") .WithAnnotations(new Dictionary() { [ArgoCDConstants.Annotations.OctopusProjectAnnotationKey(null)] = ProjectSlug, @@ -652,10 +652,10 @@ void AssertOutputVariables(bool updated = true, string matchingApplicationTotalS var serviceMessages = log.Messages.GetServiceMessagesOfType("setVariable"); serviceMessages.GetPropertyValue("ArgoCD.GatewayIds").Should().Be(GatewayId); serviceMessages.GetPropertyValue("ArgoCD.GitUris").Should().Be(updated ? OriginUrl : string.Empty); - serviceMessages.GetPropertyValue("ArgoCD.MatchingApplications").Should().Be("App1"); + serviceMessages.GetPropertyValue("ArgoCD.MatchingApplications").Should().Be("argocd/App1"); serviceMessages.GetPropertyValue("ArgoCD.MatchingApplicationTotalSourceCounts").Should().Be(matchingApplicationTotalSourceCounts); serviceMessages.GetPropertyValue("ArgoCD.MatchingApplicationMatchingSourceCounts").Should().Be("1"); - serviceMessages.GetPropertyValue("ArgoCD.UpdatedApplications").Should().Be(updated ? "App1" : string.Empty); + serviceMessages.GetPropertyValue("ArgoCD.UpdatedApplications").Should().Be(updated ? "argocd/App1" : string.Empty); serviceMessages.GetPropertyValue("ArgoCD.UpdatedApplicationSourceCounts").Should().Be(updated ? "1" : string.Empty); if (updated) diff --git a/source/Calamari/ArgoCD/ArgoCDOutputVariablesWriter.cs b/source/Calamari/ArgoCD/ArgoCDOutputVariablesWriter.cs index a07ebf665f..7590bad717 100644 --- a/source/Calamari/ArgoCD/ArgoCDOutputVariablesWriter.cs +++ b/source/Calamari/ArgoCD/ArgoCDOutputVariablesWriter.cs @@ -26,7 +26,7 @@ public ArgoCDOutputVariablesWriter(ILog log) public void WriteSourceUpdateResultOutputWhenPushResultExists( string gatewayName, - string applicationName, + QualifiedApplicationName applicationName, int sourceIndex, SourceUpdateResult sourceUpdateResult) { @@ -39,7 +39,7 @@ public void WriteSourceUpdateResultOutputWhenPushResultExists( var appSourceVariables = SpecialVariables.ArgoCD.Output .Actions() .ArgoCDGateways(gatewayName) - .Applications(applicationName) + .Applications(applicationName.Value) .Sources(sourceIndex); log.SetOutputVariableButDoNotAddToVariables(appSourceVariables.CommitSha, pushResult.CommitSha); @@ -91,8 +91,8 @@ static ServiceMessage CreatePullRequestCreatedServiceMessage(PullRequestPushResu public void WriteImageUpdateOutput(IEnumerable gateways, IEnumerable gitRepos, - IReadOnlyCollection<(ApplicationName ApplicationName, int TotalSourceCount, int MatchingSourceCount)> totalApplicationsWithSourceCounts, - IReadOnlyCollection<(ApplicationName ApplicationName, int SourceCount)> updatedApplicationsWithSourceCounts, + IReadOnlyCollection<(QualifiedApplicationName ApplicationName, int TotalSourceCount, int MatchingSourceCount)> totalApplicationsWithSourceCounts, + IReadOnlyCollection<(QualifiedApplicationName ApplicationName, int SourceCount)> updatedApplicationsWithSourceCounts, int imagesUpdatedCount) { WriteGatewayIds(gateways); @@ -105,8 +105,8 @@ public void WriteImageUpdateOutput(IEnumerable gateways, public void WriteManifestUpdateOutput(IEnumerable gateways, IEnumerable gitRepos, - IReadOnlyCollection<(ApplicationName ApplicationName, int TotalSourceCount, int MatchingSourceCount)> totalApplicationsWithSourceCounts, - IReadOnlyCollection<(ApplicationName ApplicationName, int SourceCount)> updatedApplicationsWithSourceCounts) + IReadOnlyCollection<(QualifiedApplicationName ApplicationName, int TotalSourceCount, int MatchingSourceCount)> totalApplicationsWithSourceCounts, + IReadOnlyCollection<(QualifiedApplicationName ApplicationName, int SourceCount)> updatedApplicationsWithSourceCounts) { WriteGatewayIds(gateways); WriteGitUris(gitRepos); @@ -114,7 +114,7 @@ public void WriteManifestUpdateOutput(IEnumerable gateways, WriteUpdatedApplicationsWithSourceCounts(updatedApplicationsWithSourceCounts); } - void WriteTotalApplicationsWithSourceCounts(IReadOnlyCollection<(ApplicationName ApplicationName, int TotalSourceCount, int MatchingSourceCount)> matchingApplicationsWithSourceCounts) + void WriteTotalApplicationsWithSourceCounts(IReadOnlyCollection<(QualifiedApplicationName ApplicationName, int TotalSourceCount, int MatchingSourceCount)> matchingApplicationsWithSourceCounts) { var totalApps = ToCommaSeparatedString(matchingApplicationsWithSourceCounts.Select(c => c.ApplicationName)); log.SetOutputVariableButDoNotAddToVariables(SpecialVariables.Git.Output.MatchingApplications, totalApps); @@ -126,7 +126,7 @@ void WriteTotalApplicationsWithSourceCounts(IReadOnlyCollection<(ApplicationName log.SetOutputVariableButDoNotAddToVariables(SpecialVariables.Git.Output.MatchingApplicationMatchingSourceCounts, matchingSourceCounts); } - void WriteUpdatedApplicationsWithSourceCounts(IReadOnlyCollection<(ApplicationName ApplicationName, int SourceCount)> updatedApplicationsWithSourceCount) + void WriteUpdatedApplicationsWithSourceCounts(IReadOnlyCollection<(QualifiedApplicationName ApplicationName, int SourceCount)> updatedApplicationsWithSourceCount) { var updatedApps = ToCommaSeparatedString(updatedApplicationsWithSourceCount.Select(c => c.ApplicationName)); log.SetOutputVariableButDoNotAddToVariables(SpecialVariables.Git.Output.UpdatedApplications, updatedApps); diff --git a/source/Calamari/ArgoCD/Conventions/ManifestTemplating/ApplicationSourceUpdater.cs b/source/Calamari/ArgoCD/Conventions/ManifestTemplating/ApplicationSourceUpdater.cs index ef8a5cc735..1a9ee4203f 100644 --- a/source/Calamari/ArgoCD/Conventions/ManifestTemplating/ApplicationSourceUpdater.cs +++ b/source/Calamari/ArgoCD/Conventions/ManifestTemplating/ApplicationSourceUpdater.cs @@ -62,7 +62,7 @@ public ManifestUpdateResult ProcessSource(ApplicationSourceWithMetadata sourceWi var sourceUpdateResult = repositoryAdapter.Process(sourceWithMetadata, sourceUpdater); outputVariablesWriter.WriteSourceUpdateResultOutputWhenPushResultExists(gateway.Name, - applicationFromYaml.Metadata.Name, + QualifiedApplicationName.Create(applicationFromYaml.Metadata.Name, applicationFromYaml.Metadata.Namespace), sourceWithMetadata.Index, sourceUpdateResult); diff --git a/source/Calamari/ArgoCD/Conventions/ManifestTemplating/ApplicationUpdater.cs b/source/Calamari/ArgoCD/Conventions/ManifestTemplating/ApplicationUpdater.cs index 77c54154da..0ab401b585 100644 --- a/source/Calamari/ArgoCD/Conventions/ManifestTemplating/ApplicationUpdater.cs +++ b/source/Calamari/ArgoCD/Conventions/ManifestTemplating/ApplicationUpdater.cs @@ -90,7 +90,7 @@ public ProcessApplicationResult ProcessApplication( return new ProcessApplicationResult( application.GatewayId, - applicationName.ToApplicationName(), + QualifiedApplicationName.Create(applicationName, applicationFromYaml.Metadata.Namespace), applicationFromYaml.Spec.Sources.Count, applicationFromYaml.Spec.Sources.Count(s => deploymentScope.Matches(ScopingAnnotationReader.GetScopeForApplicationSource(s.Name.ToApplicationSourceName(), applicationFromYaml.Metadata.Annotations, containsMultipleSources))), trackedSourceUpdateResults.Select(r => new TrackedSourceDetail(r.UpdateResult.CommitSha, r.UpdateResult.CommitTimestamp, r.applicationSource.Index, r.UpdateResult.ReplacedFiles, [])).ToList(), diff --git a/source/Calamari/ArgoCD/Conventions/UpdateImageTag/ApplicationSourceUpdater.cs b/source/Calamari/ArgoCD/Conventions/UpdateImageTag/ApplicationSourceUpdater.cs index ba7cf381a0..283261efd9 100644 --- a/source/Calamari/ArgoCD/Conventions/UpdateImageTag/ApplicationSourceUpdater.cs +++ b/source/Calamari/ArgoCD/Conventions/UpdateImageTag/ApplicationSourceUpdater.cs @@ -59,7 +59,7 @@ public SourceUpdateResult ProcessSource(ApplicationSourceWithMetadata sourceWith var sourceUpdateResult = repositoryAdapter.Process(sourceWithMetadata, sourceUpdater); outputVariablesWriter.WriteSourceUpdateResultOutputWhenPushResultExists(gateway.Name, - applicationFromYaml.Metadata.Name, + QualifiedApplicationName.Create(applicationFromYaml.Metadata.Name, applicationFromYaml.Metadata.Namespace), sourceWithMetadata.Index, sourceUpdateResult); diff --git a/source/Calamari/ArgoCD/Conventions/UpdateImageTag/ApplicationUpdater.cs b/source/Calamari/ArgoCD/Conventions/UpdateImageTag/ApplicationUpdater.cs index 9ca76773e8..dc0c35241f 100644 --- a/source/Calamari/ArgoCD/Conventions/UpdateImageTag/ApplicationUpdater.cs +++ b/source/Calamari/ArgoCD/Conventions/UpdateImageTag/ApplicationUpdater.cs @@ -78,7 +78,7 @@ public ProcessApplicationResult ProcessApplication( return new ProcessApplicationResult( application.GatewayId, - applicationName.ToApplicationName(), + QualifiedApplicationName.Create(applicationName, applicationFromYaml.Metadata.Namespace), applicationFromYaml.Spec.Sources.Count, applicationFromYaml.Spec.Sources.Count(s => deploymentScope.Matches(ScopingAnnotationReader.GetScopeForApplicationSource(s.Name.ToApplicationSourceName(), applicationFromYaml.Metadata.Annotations, containsMultipleSources))), appliedSourcesResults.Select(r => new TrackedSourceDetail(r.UpdateResult.PushResult?.CommitSha, r.UpdateResult.PushResult?.CommitTimestamp, r.applicationSource.Index, [], r.UpdateResult.PatchedFiles)).ToList(), diff --git a/source/Calamari/ArgoCD/Models/QualifiedApplicationName.cs b/source/Calamari/ArgoCD/Models/QualifiedApplicationName.cs new file mode 100644 index 0000000000..58b5993036 --- /dev/null +++ b/source/Calamari/ArgoCD/Models/QualifiedApplicationName.cs @@ -0,0 +1,14 @@ +using Octopus.TinyTypes; + +namespace Calamari.ArgoCD.Models +{ + public class QualifiedApplicationName : CaseSensitiveStringTinyType + { + QualifiedApplicationName(string value) : base(value) + { + } + + public static QualifiedApplicationName Create(string name, string @namespace) + => new QualifiedApplicationName($"{@namespace}/{name}"); + } +} diff --git a/source/Calamari/ArgoCD/ProcessApplicationResult.cs b/source/Calamari/ArgoCD/ProcessApplicationResult.cs index abad5c14ed..7d71fef811 100644 --- a/source/Calamari/ArgoCD/ProcessApplicationResult.cs +++ b/source/Calamari/ArgoCD/ProcessApplicationResult.cs @@ -19,7 +19,7 @@ public record TrackedSourceDetail( public class ProcessApplicationResult( string gatewayId, - ApplicationName applicationName, + QualifiedApplicationName applicationName, int totalSourceCount, int matchingSourceCount, List trackedSourceDetails, @@ -27,7 +27,7 @@ public class ProcessApplicationResult( HashSet gitReposUpdated) { public string GatewayId { get; } = gatewayId; - public ApplicationName ApplicationName { get; } = applicationName; + public QualifiedApplicationName ApplicationName { get; } = applicationName; public int TotalSourceCount { get; } = totalSourceCount; public int MatchingSourceCount { get; } = matchingSourceCount; public List TrackedSourceDetails { get; } = trackedSourceDetails; From 999b64aefa705d4437da380dc849500ddee01122 Mon Sep 17 00:00:00 2001 From: Frank Lin Date: Fri, 29 May 2026 09:55:29 +1000 Subject: [PATCH 2/6] WIP --- .../ArgoCDOutputVariablesWriterTests.cs | 153 ++++++++++++++++++ 1 file changed, 153 insertions(+) diff --git a/source/Calamari.Tests/ArgoCD/ArgoCDOutputVariablesWriterTests.cs b/source/Calamari.Tests/ArgoCD/ArgoCDOutputVariablesWriterTests.cs index 80e038cd01..9778b6aa4e 100644 --- a/source/Calamari.Tests/ArgoCD/ArgoCDOutputVariablesWriterTests.cs +++ b/source/Calamari.Tests/ArgoCD/ArgoCDOutputVariablesWriterTests.cs @@ -150,6 +150,159 @@ public void WritePushResultOutput_WithMultipleSources_WritesVariablesWithCorrect AssertPullRequestCreatedServiceMessage(pullRequestCreatedServiceMessages, pushResult2); } + [Test] + public void WriteManifestUpdateOutput_SingleItems_WritesAllOutputVariables() + { + // Arrange + var gateways = new[] { "gateway-1" }; + var gitRepos = new[] { "https://github.com/org/repo" }; + var totalApps = new[] { (QualifiedApplicationName, 3, 2) }; + var updatedApps = new[] { (QualifiedApplicationName, 2) }; + + // Act + writer.WriteManifestUpdateOutput(gateways, gitRepos, totalApps, updatedApps); + + // Assert + using var _ = new AssertionScope(); + var serviceMessages = log.Messages.GetServiceMessagesOfType("setVariable"); + + serviceMessages.GetPropertyValue("ArgoCD.GatewayIds").Should().Be("gateway-1"); + serviceMessages.GetPropertyValue("ArgoCD.GitUris").Should().Be("https://github.com/org/repo"); + serviceMessages.GetPropertyValue("ArgoCD.MatchingApplications").Should().Be(QualifiedApplicationName.ToString()); + serviceMessages.GetPropertyValue("ArgoCD.MatchingApplicationTotalSourceCounts").Should().Be("3"); + serviceMessages.GetPropertyValue("ArgoCD.MatchingApplicationMatchingSourceCounts").Should().Be("2"); + serviceMessages.GetPropertyValue("ArgoCD.UpdatedApplications").Should().Be(QualifiedApplicationName.ToString()); + serviceMessages.GetPropertyValue("ArgoCD.UpdatedApplicationSourceCounts").Should().Be("2"); + serviceMessages.GetPropertyValue("ArgoCD.UpdatedImages").Should().BeNull(); + } + + [Test] + public void WriteManifestUpdateOutput_MultipleItems_WritesCommaSeparatedValues() + { + // Arrange + var gateways = new[] { "gateway-1", "gateway-2" }; + var gitRepos = new[] { "https://github.com/org/repo-a", "https://github.com/org/repo-b" }; + var app2 = QualifiedApplicationName.Create("OtherApp", "argocd"); + var totalApps = new[] + { + (QualifiedApplicationName, 3, 2), + (app2, 1, 1), + }; + var updatedApps = new[] + { + (QualifiedApplicationName, 2), + (app2, 1), + }; + + // Act + writer.WriteManifestUpdateOutput(gateways, gitRepos, totalApps, updatedApps); + + // Assert + using var _ = new AssertionScope(); + var serviceMessages = log.Messages.GetServiceMessagesOfType("setVariable"); + + serviceMessages.GetPropertyValue("ArgoCD.GatewayIds").Should().Be("gateway-1, gateway-2"); + serviceMessages.GetPropertyValue("ArgoCD.GitUris").Should().Be("https://github.com/org/repo-a, https://github.com/org/repo-b"); + serviceMessages.GetPropertyValue("ArgoCD.MatchingApplications").Should().Be($"{QualifiedApplicationName}, {app2}"); + serviceMessages.GetPropertyValue("ArgoCD.MatchingApplicationTotalSourceCounts").Should().Be("3, 1"); + serviceMessages.GetPropertyValue("ArgoCD.MatchingApplicationMatchingSourceCounts").Should().Be("2, 1"); + serviceMessages.GetPropertyValue("ArgoCD.UpdatedApplications").Should().Be($"{QualifiedApplicationName}, {app2}"); + serviceMessages.GetPropertyValue("ArgoCD.UpdatedApplicationSourceCounts").Should().Be("2, 1"); + } + + [Test] + public void WriteManifestUpdateOutput_EmptyCollections_WritesEmptyValues() + { + // Act + writer.WriteManifestUpdateOutput([], [], [], []); + + // Assert + using var _ = new AssertionScope(); + var serviceMessages = log.Messages.GetServiceMessagesOfType("setVariable"); + + serviceMessages.GetPropertyValue("ArgoCD.GatewayIds").Should().BeEmpty(); + serviceMessages.GetPropertyValue("ArgoCD.GitUris").Should().BeEmpty(); + serviceMessages.GetPropertyValue("ArgoCD.MatchingApplications").Should().BeEmpty(); + serviceMessages.GetPropertyValue("ArgoCD.MatchingApplicationTotalSourceCounts").Should().BeEmpty(); + serviceMessages.GetPropertyValue("ArgoCD.MatchingApplicationMatchingSourceCounts").Should().BeEmpty(); + serviceMessages.GetPropertyValue("ArgoCD.UpdatedApplications").Should().BeEmpty(); + serviceMessages.GetPropertyValue("ArgoCD.UpdatedApplicationSourceCounts").Should().BeEmpty(); + } + + [Test] + public void WriteImageUpdateOutput_SingleItems_WritesAllOutputVariablesIncludingUpdatedImages() + { + // Arrange + var gateways = new[] { "gateway-1" }; + var gitRepos = new[] { "https://github.com/org/repo" }; + var totalApps = new[] { (QualifiedApplicationName, 3, 2) }; + var updatedApps = new[] { (QualifiedApplicationName, 2) }; + const int imagesUpdatedCount = 5; + + // Act + writer.WriteImageUpdateOutput(gateways, gitRepos, totalApps, updatedApps, imagesUpdatedCount); + + // Assert + using var _ = new AssertionScope(); + var serviceMessages = log.Messages.GetServiceMessagesOfType("setVariable"); + + serviceMessages.GetPropertyValue("ArgoCD.GatewayIds").Should().Be("gateway-1"); + serviceMessages.GetPropertyValue("ArgoCD.GitUris").Should().Be("https://github.com/org/repo"); + serviceMessages.GetPropertyValue("ArgoCD.MatchingApplications").Should().Be(QualifiedApplicationName.ToString()); + serviceMessages.GetPropertyValue("ArgoCD.MatchingApplicationTotalSourceCounts").Should().Be("3"); + serviceMessages.GetPropertyValue("ArgoCD.MatchingApplicationMatchingSourceCounts").Should().Be("2"); + serviceMessages.GetPropertyValue("ArgoCD.UpdatedApplications").Should().Be(QualifiedApplicationName.ToString()); + serviceMessages.GetPropertyValue("ArgoCD.UpdatedApplicationSourceCounts").Should().Be("2"); + serviceMessages.GetPropertyValue("ArgoCD.UpdatedImages").Should().Be("5"); + } + + [Test] + public void WriteImageUpdateOutput_MultipleItems_WritesCommaSeparatedValues() + { + // Arrange + var gateways = new[] { "gateway-1", "gateway-2" }; + var gitRepos = new[] { "https://github.com/org/repo-a", "https://github.com/org/repo-b" }; + var app2 = QualifiedApplicationName.Create("OtherApp", "argocd"); + var totalApps = new[] + { + (QualifiedApplicationName, 4, 3), + (app2, 2, 1), + }; + var updatedApps = new[] + { + (QualifiedApplicationName, 3), + (app2, 1), + }; + const int imagesUpdatedCount = 4; + + // Act + writer.WriteImageUpdateOutput(gateways, gitRepos, totalApps, updatedApps, imagesUpdatedCount); + + // Assert + using var _ = new AssertionScope(); + var serviceMessages = log.Messages.GetServiceMessagesOfType("setVariable"); + + serviceMessages.GetPropertyValue("ArgoCD.GatewayIds").Should().Be("gateway-1, gateway-2"); + serviceMessages.GetPropertyValue("ArgoCD.GitUris").Should().Be("https://github.com/org/repo-a, https://github.com/org/repo-b"); + serviceMessages.GetPropertyValue("ArgoCD.MatchingApplications").Should().Be($"{QualifiedApplicationName}, {app2}"); + serviceMessages.GetPropertyValue("ArgoCD.MatchingApplicationTotalSourceCounts").Should().Be("4, 2"); + serviceMessages.GetPropertyValue("ArgoCD.MatchingApplicationMatchingSourceCounts").Should().Be("3, 1"); + serviceMessages.GetPropertyValue("ArgoCD.UpdatedApplications").Should().Be($"{QualifiedApplicationName}, {app2}"); + serviceMessages.GetPropertyValue("ArgoCD.UpdatedApplicationSourceCounts").Should().Be("3, 1"); + serviceMessages.GetPropertyValue("ArgoCD.UpdatedImages").Should().Be("4"); + } + + [Test] + public void WriteImageUpdateOutput_ZeroImagesUpdated_WritesZeroForUpdatedImages() + { + // Act + writer.WriteImageUpdateOutput([], [], [], [], 0); + + // Assert + var serviceMessages = log.Messages.GetServiceMessagesOfType("setVariable"); + serviceMessages.GetPropertyValue("ArgoCD.UpdatedImages").Should().Be("0"); + } + //Zero = No (but NO COMMIT is part of the forbidden words list) static void AssertZeroCommitVariables(ServiceMessage[] serviceMessages, int sourceIndex) { From de98fadda2e8837efb5e3071464cfe8d5e49eb11 Mon Sep 17 00:00:00 2001 From: Frank Lin Date: Tue, 2 Jun 2026 13:14:39 +1000 Subject: [PATCH 3/6] changes --- .../ArgoCD/ArgoCDOutputVariablesWriter.cs | 42 +++++++++++++++++-- .../ManifestTemplating/ApplicationUpdater.cs | 3 +- .../UpdateArgoCDAppImagesInstallConvention.cs | 3 +- ...CDApplicationManifestsInstallConvention.cs | 3 +- .../UpdateImageTag/ApplicationUpdater.cs | 3 +- .../ArgoCD/ProcessApplicationResult.cs | 3 ++ .../Calamari/Kubernetes/SpecialVariables.cs | 12 ++++-- 7 files changed, 58 insertions(+), 11 deletions(-) diff --git a/source/Calamari/ArgoCD/ArgoCDOutputVariablesWriter.cs b/source/Calamari/ArgoCD/ArgoCDOutputVariablesWriter.cs index 7590bad717..81baa64f6c 100644 --- a/source/Calamari/ArgoCD/ArgoCDOutputVariablesWriter.cs +++ b/source/Calamari/ArgoCD/ArgoCDOutputVariablesWriter.cs @@ -11,6 +11,7 @@ using Calamari.Common.Plumbing.ServiceMessages; using Calamari.Kubernetes; using Octopus.Calamari.Contracts.Git; +using Octopus.CoreUtilities.Extensions; using PullRequestCreatedServiceMessage = Octopus.Calamari.Contracts.Git.ServiceMessages.PullRequestCreated; namespace Calamari.ArgoCD @@ -39,7 +40,7 @@ public void WriteSourceUpdateResultOutputWhenPushResultExists( var appSourceVariables = SpecialVariables.ArgoCD.Output .Actions() .ArgoCDGateways(gatewayName) - .Applications(applicationName.Value) + .Applications(applicationName) .Sources(sourceIndex); log.SetOutputVariableButDoNotAddToVariables(appSourceVariables.CommitSha, pushResult.CommitSha); @@ -48,7 +49,7 @@ public void WriteSourceUpdateResultOutputWhenPushResultExists( if (pushResult is PullRequestPushResult prResult) { - log.SetOutputVariableButDoNotAddToVariables(appSourceVariables.RepositoryUrl, prResult.RepositoryUri); +// log.SetOutputVariableButDoNotAddToVariables(appSourceVariables.RepositoryUrl, prResult.RepositoryUri); log.SetOutputVariableButDoNotAddToVariables(appSourceVariables.PullRequestTitle, prResult.PullRequestTitle); log.SetOutputVariableButDoNotAddToVariables(appSourceVariables.PullRequestUrl, prResult.PullRequestUri); log.SetOutputVariableButDoNotAddToVariables(appSourceVariables.PullRequestNumber, prResult.PullRequestNumber.ToString(CultureInfo.InvariantCulture)); @@ -93,8 +94,25 @@ public void WriteImageUpdateOutput(IEnumerable gateways, IEnumerable gitRepos, IReadOnlyCollection<(QualifiedApplicationName ApplicationName, int TotalSourceCount, int MatchingSourceCount)> totalApplicationsWithSourceCounts, IReadOnlyCollection<(QualifiedApplicationName ApplicationName, int SourceCount)> updatedApplicationsWithSourceCounts, - int imagesUpdatedCount) + int imagesUpdatedCount, + List applicationResults) { + + foreach (var applicationResult in applicationResults) + { + foreach (var sourceDetail in applicationResult.TrackedSourceDetails) + { + var appSourceVariables = SpecialVariables.ArgoCD.Output + .Actions() + .ArgoCDGateways(applicationResult.GatewayName) + .Applications(applicationResult.ApplicationName) + .Sources(sourceDetail.SourceIndex); + + log.SetOutputVariableButDoNotAddToVariables(appSourceVariables.Updated, sourceDetail.CommitSha.IsNullOrEmpty().ToString()); + log.SetOutputVariableButDoNotAddToVariables(appSourceVariables.RepositoryUrl, sourceDetail.RepositoryUri); + } + } + WriteGatewayIds(gateways); WriteGitUris(gitRepos); WriteTotalApplicationsWithSourceCounts(totalApplicationsWithSourceCounts); @@ -106,8 +124,24 @@ public void WriteImageUpdateOutput(IEnumerable gateways, public void WriteManifestUpdateOutput(IEnumerable gateways, IEnumerable gitRepos, IReadOnlyCollection<(QualifiedApplicationName ApplicationName, int TotalSourceCount, int MatchingSourceCount)> totalApplicationsWithSourceCounts, - IReadOnlyCollection<(QualifiedApplicationName ApplicationName, int SourceCount)> updatedApplicationsWithSourceCounts) + IReadOnlyCollection<(QualifiedApplicationName ApplicationName, int SourceCount)> updatedApplicationsWithSourceCounts, + List applicationResults) { + foreach (var applicationResult in applicationResults) + { + foreach (var sourceDetail in applicationResult.TrackedSourceDetails) + { + var appSourceVariables = SpecialVariables.ArgoCD.Output + .Actions() + .ArgoCDGateways(applicationResult.GatewayName) + .Applications(applicationResult.ApplicationName) + .Sources(sourceDetail.SourceIndex); + + log.SetOutputVariableButDoNotAddToVariables(appSourceVariables.Updated, sourceDetail.CommitSha.IsNullOrEmpty().ToString()); + log.SetOutputVariableButDoNotAddToVariables(appSourceVariables.RepositoryUrl, sourceDetail.RepositoryUri); + } + } + WriteGatewayIds(gateways); WriteGitUris(gitRepos); WriteTotalApplicationsWithSourceCounts(totalApplicationsWithSourceCounts); diff --git a/source/Calamari/ArgoCD/Conventions/ManifestTemplating/ApplicationUpdater.cs b/source/Calamari/ArgoCD/Conventions/ManifestTemplating/ApplicationUpdater.cs index 0ab401b585..28be4f1ebf 100644 --- a/source/Calamari/ArgoCD/Conventions/ManifestTemplating/ApplicationUpdater.cs +++ b/source/Calamari/ArgoCD/Conventions/ManifestTemplating/ApplicationUpdater.cs @@ -90,10 +90,11 @@ public ProcessApplicationResult ProcessApplication( return new ProcessApplicationResult( application.GatewayId, + gateway.Name, QualifiedApplicationName.Create(applicationName, applicationFromYaml.Metadata.Namespace), applicationFromYaml.Spec.Sources.Count, applicationFromYaml.Spec.Sources.Count(s => deploymentScope.Matches(ScopingAnnotationReader.GetScopeForApplicationSource(s.Name.ToApplicationSourceName(), applicationFromYaml.Metadata.Annotations, containsMultipleSources))), - trackedSourceUpdateResults.Select(r => new TrackedSourceDetail(r.UpdateResult.CommitSha, r.UpdateResult.CommitTimestamp, r.applicationSource.Index, r.UpdateResult.ReplacedFiles, [])).ToList(), + trackedSourceUpdateResults.Select(r => new TrackedSourceDetail(r.applicationSource.Source.OriginalRepoUrl, r.UpdateResult.CommitSha, r.UpdateResult.CommitTimestamp, r.applicationSource.Index, r.UpdateResult.ReplacedFiles, [])).ToList(), [], trackedSourceUpdateResults.Where(r => r.UpdateResult.Updated).Select(r => r.applicationSource.Source.OriginalRepoUrl).ToHashSet()); } diff --git a/source/Calamari/ArgoCD/Conventions/UpdateArgoCDAppImagesInstallConvention.cs b/source/Calamari/ArgoCD/Conventions/UpdateArgoCDAppImagesInstallConvention.cs index 04fcc55a49..d5e7275e3a 100644 --- a/source/Calamari/ArgoCD/Conventions/UpdateArgoCDAppImagesInstallConvention.cs +++ b/source/Calamari/ArgoCD/Conventions/UpdateArgoCDAppImagesInstallConvention.cs @@ -99,7 +99,8 @@ public void Install(RunningDeployment deployment) gitReposUpdated, totalApplicationsWithSourceCounts, updatedApplicationsWithSources, - newImagesWritten.Count + newImagesWritten.Count, + applicationResults ); } } diff --git a/source/Calamari/ArgoCD/Conventions/UpdateArgoCDApplicationManifestsInstallConvention.cs b/source/Calamari/ArgoCD/Conventions/UpdateArgoCDApplicationManifestsInstallConvention.cs index 00de914204..edb3f3e5ba 100644 --- a/source/Calamari/ArgoCD/Conventions/UpdateArgoCDApplicationManifestsInstallConvention.cs +++ b/source/Calamari/ArgoCD/Conventions/UpdateArgoCDApplicationManifestsInstallConvention.cs @@ -102,7 +102,8 @@ public void Install(RunningDeployment deployment) outputVariablesWriter.WriteManifestUpdateOutput(gatewayIds, gitReposUpdated, totalApplicationsWithSourceCounts, - updatedApplicationsWithSources + updatedApplicationsWithSources, + applicationResults ); } diff --git a/source/Calamari/ArgoCD/Conventions/UpdateImageTag/ApplicationUpdater.cs b/source/Calamari/ArgoCD/Conventions/UpdateImageTag/ApplicationUpdater.cs index dc0c35241f..2dc83e3d5e 100644 --- a/source/Calamari/ArgoCD/Conventions/UpdateImageTag/ApplicationUpdater.cs +++ b/source/Calamari/ArgoCD/Conventions/UpdateImageTag/ApplicationUpdater.cs @@ -78,10 +78,11 @@ public ProcessApplicationResult ProcessApplication( return new ProcessApplicationResult( application.GatewayId, + gateway.Name, QualifiedApplicationName.Create(applicationName, applicationFromYaml.Metadata.Namespace), applicationFromYaml.Spec.Sources.Count, applicationFromYaml.Spec.Sources.Count(s => deploymentScope.Matches(ScopingAnnotationReader.GetScopeForApplicationSource(s.Name.ToApplicationSourceName(), applicationFromYaml.Metadata.Annotations, containsMultipleSources))), - appliedSourcesResults.Select(r => new TrackedSourceDetail(r.UpdateResult.PushResult?.CommitSha, r.UpdateResult.PushResult?.CommitTimestamp, r.applicationSource.Index, [], r.UpdateResult.PatchedFiles)).ToList(), + appliedSourcesResults.Select(r => new TrackedSourceDetail(r.applicationSource.Source.OriginalRepoUrl, r.UpdateResult.PushResult?.CommitSha, r.UpdateResult.PushResult?.CommitTimestamp, r.applicationSource.Index, [], r.UpdateResult.PatchedFiles)).ToList(), appliedSourcesResults.SelectMany(r => r.UpdateResult.ImagesUpdated).ToHashSet(), appliedSourcesResults.Where(r => r.UpdateResult.Updated).Select(r => r.applicationSource.Source.OriginalRepoUrl).ToHashSet()); } diff --git a/source/Calamari/ArgoCD/ProcessApplicationResult.cs b/source/Calamari/ArgoCD/ProcessApplicationResult.cs index 7d71fef811..559ad37369 100644 --- a/source/Calamari/ArgoCD/ProcessApplicationResult.cs +++ b/source/Calamari/ArgoCD/ProcessApplicationResult.cs @@ -11,6 +11,7 @@ public record FileHash(string FilePath, string Hash); public record FileJsonPatch(string FilePath, string JsonPatch); public record TrackedSourceDetail( + string RepositoryUri, string? CommitSha, DateTimeOffset? CommitTimestamp, int SourceIndex, @@ -19,6 +20,7 @@ public record TrackedSourceDetail( public class ProcessApplicationResult( string gatewayId, + string gatewayName, QualifiedApplicationName applicationName, int totalSourceCount, int matchingSourceCount, @@ -27,6 +29,7 @@ public class ProcessApplicationResult( HashSet gitReposUpdated) { public string GatewayId { get; } = gatewayId; + public string GatewayName { get; } = gatewayName; public QualifiedApplicationName ApplicationName { get; } = applicationName; public int TotalSourceCount { get; } = totalSourceCount; public int MatchingSourceCount { get; } = matchingSourceCount; diff --git a/source/Calamari/Kubernetes/SpecialVariables.cs b/source/Calamari/Kubernetes/SpecialVariables.cs index 86cddcf04b..909e18f30b 100644 --- a/source/Calamari/Kubernetes/SpecialVariables.cs +++ b/source/Calamari/Kubernetes/SpecialVariables.cs @@ -112,9 +112,11 @@ public record ArgoCDGatewayOutputVariables(string GatewayName) { readonly string qualifiedPrefix = $"ArgoCD.Gateway[{GatewayName}]"; - public ApplicationOutputVariables Applications(string name) => new(name, this); + //public string ApplicationCount => $"{qualifiedPrefix}.ApplicationCount"; - public record ApplicationOutputVariables(string Name, ArgoCDGatewayOutputVariables ArgoCDGatewayOutputVariables) + public ApplicationOutputVariables Applications(QualifiedApplicationName name) => new(name, this); + + public record ApplicationOutputVariables(QualifiedApplicationName Name, ArgoCDGatewayOutputVariables ArgoCDGatewayOutputVariables) { readonly string qualifiedPrefix = $"{ArgoCDGatewayOutputVariables.qualifiedPrefix}.Application[{Name}]"; @@ -124,15 +126,19 @@ public record ApplicationSourceOutputVariables(int Index, ApplicationOutputVaria { readonly string qualifiedPrefix = $"{ApplicationVariables.qualifiedPrefix}.Source[{Index}]"; + //These are only sent if there was an update public string CommitSha => $"{qualifiedPrefix}.CommitSha"; public string ShortSha => $"{qualifiedPrefix}.ShortSha"; - public string RepositoryUrl => $"{qualifiedPrefix}.RepositoryUrl"; public string CommitTimestamp => $"{qualifiedPrefix}.CommitTimestamp"; public string PullRequestTitle => $"{qualifiedPrefix}.PullRequest.Title"; public string PullRequestNumber => $"{qualifiedPrefix}.PullRequest.Number"; public string PullRequestUrl => $"{qualifiedPrefix}.PullRequest.Url"; public string PullRequestReplacedFiles => $"{qualifiedPrefix}.PullRequest.ReplacedFiles"; public string PullRequestPatchedFiles => $"{qualifiedPrefix}.PullRequest.PatchedFiles"; + + //These are always sent + public string Updated => $"{qualifiedPrefix}.Updated"; + public string RepositoryUrl => $"{qualifiedPrefix}.RepositoryUrl"; } } } From 026ebe73db68a295b94439d99787e564c9a5aa3a Mon Sep 17 00:00:00 2001 From: Frank Lin Date: Tue, 2 Jun 2026 13:14:48 +1000 Subject: [PATCH 4/6] fix some --- .../ArgoCD/ArgoCDFilesUpdatedReporterTests.cs | 176 +++++++++++------- 1 file changed, 108 insertions(+), 68 deletions(-) diff --git a/source/Calamari.Tests/ArgoCD/ArgoCDFilesUpdatedReporterTests.cs b/source/Calamari.Tests/ArgoCD/ArgoCDFilesUpdatedReporterTests.cs index 7b997c35d6..325b1f097a 100644 --- a/source/Calamari.Tests/ArgoCD/ArgoCDFilesUpdatedReporterTests.cs +++ b/source/Calamari.Tests/ArgoCD/ArgoCDFilesUpdatedReporterTests.cs @@ -23,19 +23,22 @@ public void ReportDeployments_WhenGitParamsRequirePullRequest_WritesNoServiceMes var prGitParams = new GitCommitParameters(string.Empty, string.Empty, true); var timestamp = DateTimeOffset.UtcNow; var reporter = new ArgoCDFilesUpdatedReporter(log); - + var applicationResults = new List { new("gateway1", + "gateway1Name", QualifiedApplicationName.Create("app1", "argocd"), 2, 2, [ - new TrackedSourceDetail("abc123", - timestamp, - 0, - [], - []) + new TrackedSourceDetail( + "https://github.com", + "abc123", + timestamp, + 0, + [], + []) ], [], []) @@ -56,6 +59,7 @@ public void ReportDeployments_WithNoUpdatedApplications_WritesNoServiceMessages( var applicationResults = new List { new("gateway1", + "gateway1Name", QualifiedApplicationName.Create("app1", "argocd"), 2, 2, @@ -81,15 +85,18 @@ public void ReportDeployments_WithSingleUpdatedApplication_WritesOneServiceMessa var applicationResults = new List { new("gateway1", + "gateway1Name", QualifiedApplicationName.Create("app1", "argocd"), 2, 2, [ - new TrackedSourceDetail("abc123", - timestamp, - 0, - [], - []) + new TrackedSourceDetail( + "https://github.com", + "abc123", + timestamp, + 0, + [], + []) ], [], []) @@ -123,28 +130,34 @@ public void ReportDeployments_WithMultipleUpdatedApplications_WritesMultipleServ var applicationResults = new List { new("gateway1", + "gateway1Name", QualifiedApplicationName.Create("app1", "argocd"), 2, 2, [ - new TrackedSourceDetail("abc123", - timestamp, - 0, - [], - []) + new TrackedSourceDetail( + "https://github.com", + "abc123", + timestamp, + 0, + [], + []) ], [], []), new("gateway2", + "gateway2Name", QualifiedApplicationName.Create("app2", "argocd"), 1, 1, [ - new TrackedSourceDetail("def456", - timestamp, - 0, - [], - []) + new TrackedSourceDetail( + "https://github.com", + "def456", + timestamp, + 0, + [], + []) ], [], []) @@ -188,11 +201,13 @@ public void ReportDeployments_WithReplacedFiles_IncludesReplacedFilesInSources() var applicationResults = new List { new("gateway1", + "gateway1Name", QualifiedApplicationName.Create("app1", "argocd"), 2, 2, [ - new TrackedSourceDetail("abc123", + new TrackedSourceDetail("https://github.com", + "abc123", timestamp, 0, [new FileHash("values.yaml", "22c0df2cceca5273e4dc569dda52805d27df3360")], @@ -230,15 +245,18 @@ public void ReportDeployments_WithPatchedFiles_IncludesPatchedFilesInSources() var applicationResults = new List { new("gateway1", + "gateway1Name", QualifiedApplicationName.Create("app1", "argocd"), 1, 1, [ - new TrackedSourceDetail("def456", - timestamp, - 0, - [], - [new FileJsonPatch("kustomization.yaml", """[{"op":"replace","path":"/images/0/name","value":"nginx:latest"}]""")]) + new TrackedSourceDetail( + "https://github.com", + "def456", + timestamp, + 0, + [], + [new FileJsonPatch("kustomization.yaml", """[{"op":"replace","path":"/images/0/name","value":"nginx:latest"}]""")]) ], [], []) @@ -272,15 +290,18 @@ public void ReportDeployments_WithBothReplacedAndPatchedFiles_IncludesBothInSour var applicationResults = new List { new("gateway1", + "gateway1Name", QualifiedApplicationName.Create("app1", "argocd"), 2, 2, [ - new TrackedSourceDetail("abc123", - timestamp, - 0, - [new FileHash("values.yaml", "22c0df2cceca5273e4dc569dda52805d27df3360")], - [new FileJsonPatch("kustomization.yaml", """[{"op":"replace","path":"/images/0/name","value":"nginx:latest"}]""")]) + new TrackedSourceDetail( + "https://github.com", + "abc123", + timestamp, + 0, + [new FileHash("values.yaml", "22c0df2cceca5273e4dc569dda52805d27df3360")], + [new FileJsonPatch("kustomization.yaml", """[{"op":"replace","path":"/images/0/name","value":"nginx:latest"}]""")]) ], [], []) @@ -314,21 +335,24 @@ public void ReportDeployments_WithMultipleReplacedAndPatchedFiles_IncludesAllFil var applicationResults = new List { new("gateway1", + "gateway1Name", QualifiedApplicationName.Create("app1", "argocd"), 2, 2, [ - new TrackedSourceDetail("abc123", - timestamp, - 0, - [ - new FileHash("values.yaml", "22c0df2cceca5273e4dc569dda52805d27df3360"), - new FileHash("values-prod.yaml", "a3b4c5d6e7f8a3b4c5d6e7f8a3b4c5d6e7f8a3b4") - ], - [ - new FileJsonPatch("kustomization.yaml", """[{"op":"replace","path":"/images/0/name","value":"nginx:latest"}]"""), - new FileJsonPatch("patch.yaml", """[{"op":"replace","path":"/spec/replicas","value":3}]""") - ]) + new TrackedSourceDetail( + "https://github.com", + "abc123", + timestamp, + 0, + [ + new FileHash("values.yaml", "22c0df2cceca5273e4dc569dda52805d27df3360"), + new FileHash("values-prod.yaml", "a3b4c5d6e7f8a3b4c5d6e7f8a3b4c5d6e7f8a3b4") + ], + [ + new FileJsonPatch("kustomization.yaml", """[{"op":"replace","path":"/images/0/name","value":"nginx:latest"}]"""), + new FileJsonPatch("patch.yaml", """[{"op":"replace","path":"/spec/replicas","value":3}]""") + ]) ], [], []) @@ -362,20 +386,25 @@ public void ReportDeployments_WithMultipleSourcesWithFiles_IncludesAllSourcesInS var applicationResults = new List { new("gateway1", + "gateway1Name", QualifiedApplicationName.Create("app1", "argocd"), 2, 2, [ - new TrackedSourceDetail("abc123", - timestamp, - 0, - [new FileHash("values.yaml", "22c0df2cceca5273e4dc569dda52805d27df3360")], - []), - new TrackedSourceDetail("abc123", - timestamp, - 1, - [], - [new FileJsonPatch("kustomization.yaml", """[{"op":"replace","path":"/images/0/name","value":"redis:latest"}]""")]) + new TrackedSourceDetail( + "https://github.com", + "abc123", + timestamp, + 0, + [new FileHash("values.yaml", "22c0df2cceca5273e4dc569dda52805d27df3360")], + []), + new TrackedSourceDetail( + "https://github.com", + "abc123", + timestamp, + 1, + [], + [new FileJsonPatch("kustomization.yaml", """[{"op":"replace","path":"/images/0/name","value":"redis:latest"}]""")]) ], [], []) @@ -409,15 +438,18 @@ public void ReportDeployments_WithOsSpecificReplacedFilePaths_ReportsPosixPaths( var applicationResults = new List { new("gateway1", + "gateway1Name", QualifiedApplicationName.Create("app1", "argocd"), 1, 1, [ - new TrackedSourceDetail("abc123", - timestamp, - 0, - [new FileHash(Path.Combine("some", "nested", "values.yaml"), "22c0df2cceca5273e4dc569dda52805d27df3360")], - []) + new TrackedSourceDetail( + "https://github.com", + "abc123", + timestamp, + 0, + [new FileHash(Path.Combine("some", "nested", "values.yaml"), "22c0df2cceca5273e4dc569dda52805d27df3360")], + []) ], [], []) @@ -449,15 +481,18 @@ public void ReportDeployments_WithNoOpSource_EmitsServiceMessageWithNullCommitSh var applicationResults = new List { new("gateway1", + "gateway1Name", QualifiedApplicationName.Create("app1", "argocd"), 1, 1, [ - new TrackedSourceDetail(null, - null, - 0, - [], - [new FileJsonPatch("values.yaml", """[{"op":"replace","path":"/image","value":"nginx:1.27"}]""")]) + new TrackedSourceDetail( + "https://github.com", + null, + null, + 0, + [], + [new FileJsonPatch("values.yaml", """[{"op":"replace","path":"/image","value":"nginx:1.27"}]""")]) ], [], []) @@ -491,6 +526,7 @@ public void ReportDeployments_WithMixedUpdatedAndNonUpdatedApplications_WritesOn var applicationResults = new List { new("gateway1", + "gateway1Name", QualifiedApplicationName.Create("app1", "argocd"), 2, 2, @@ -498,19 +534,23 @@ public void ReportDeployments_WithMixedUpdatedAndNonUpdatedApplications_WritesOn [], []), new("gateway2", + "gateway2Name", QualifiedApplicationName.Create("app2", "argocd"), 1, 1, [ - new TrackedSourceDetail("abc123", - timestamp, - 0, - [], - []) + new TrackedSourceDetail( + "https://github.com", + "abc123", + timestamp, + 0, + [], + []) ], [], []), new("gateway3", + "gateway3Name", QualifiedApplicationName.Create("app3", "argocd"), 1, 1, From 0438abc8ff483bb0e5cac87d47e608cff72bb919 Mon Sep 17 00:00:00 2001 From: Frank Lin Date: Tue, 2 Jun 2026 16:22:20 +1000 Subject: [PATCH 5/6] fix --- .../ArgoCDOutputVariablesWriterTests.cs | 161 +++++++++++++----- .../ArgoCD/ArgoCDFilesUpdatedReporter.cs | 13 +- .../ArgoCD/ArgoCDOutputVariablesWriter.cs | 2 +- .../Calamari/Kubernetes/SpecialVariables.cs | 9 + 4 files changed, 137 insertions(+), 48 deletions(-) diff --git a/source/Calamari.Tests/ArgoCD/ArgoCDOutputVariablesWriterTests.cs b/source/Calamari.Tests/ArgoCD/ArgoCDOutputVariablesWriterTests.cs index 9778b6aa4e..f78d59566e 100644 --- a/source/Calamari.Tests/ArgoCD/ArgoCDOutputVariablesWriterTests.cs +++ b/source/Calamari.Tests/ArgoCD/ArgoCDOutputVariablesWriterTests.cs @@ -1,4 +1,6 @@ using System; +using System.Collections.Generic; +using System.Linq; using Calamari.ArgoCD; using Calamari.ArgoCD.Conventions; using Calamari.ArgoCD.Git; @@ -22,6 +24,7 @@ public class ArgoCDOutputVariablesWriterTests const string ApplicationName = "TestApp"; const string ApplicationNamespace = "argocd"; static readonly QualifiedApplicationName QualifiedApplicationName = QualifiedApplicationName.Create(ApplicationName, ApplicationNamespace); + static readonly QualifiedApplicationName SecondApplicationName = Calamari.ArgoCD.Models.QualifiedApplicationName.Create("OtherApp", ApplicationNamespace); const string CommitSha = "1234567890abcdef1234567890abcdef12345678"; const string ShortSha = "1234567"; static readonly DateTimeOffset Timestamp = DateTimeOffset.UtcNow; @@ -154,13 +157,25 @@ public void WritePushResultOutput_WithMultipleSources_WritesVariablesWithCorrect public void WriteManifestUpdateOutput_SingleItems_WritesAllOutputVariables() { // Arrange - var gateways = new[] { "gateway-1" }; - var gitRepos = new[] { "https://github.com/org/repo" }; - var totalApps = new[] { (QualifiedApplicationName, 3, 2) }; - var updatedApps = new[] { (QualifiedApplicationName, 2) }; + var appResult = new ProcessApplicationResult( + gatewayId: "gateway-1", + gatewayName: "gateway-1", + applicationName: QualifiedApplicationName, + totalSourceCount: 3, + matchingSourceCount: 2, + trackedSourceDetails: + [ + new TrackedSourceDetail("https://github.com/org/repo", "abc123", DateTimeOffset.UtcNow, 0, [], []), + new TrackedSourceDetail("https://github.com/org/repo", "def456", DateTimeOffset.UtcNow, 1, [], []), + ], + updatedImages: new HashSet(), + gitReposUpdated: ["https://github.com/org/repo"]); + var applicationResults = new[] { appResult }; + var totalApps = applicationResults.Select(r => (r.ApplicationName, r.TotalSourceCount, r.MatchingSourceCount)).ToList(); + var updatedApps = applicationResults.Where(r => r.Updated).Select(r => (r.ApplicationName, r.UpdatedSourceCount)).ToList(); // Act - writer.WriteManifestUpdateOutput(gateways, gitRepos, totalApps, updatedApps); + writer.WriteManifestUpdateOutput(["gateway-1"], ["https://github.com/org/repo"], totalApps, updatedApps, applicationResults); // Assert using var _ = new AssertionScope(); @@ -180,22 +195,37 @@ public void WriteManifestUpdateOutput_SingleItems_WritesAllOutputVariables() public void WriteManifestUpdateOutput_MultipleItems_WritesCommaSeparatedValues() { // Arrange - var gateways = new[] { "gateway-1", "gateway-2" }; - var gitRepos = new[] { "https://github.com/org/repo-a", "https://github.com/org/repo-b" }; - var app2 = QualifiedApplicationName.Create("OtherApp", "argocd"); - var totalApps = new[] - { - (QualifiedApplicationName, 3, 2), - (app2, 1, 1), - }; - var updatedApps = new[] - { - (QualifiedApplicationName, 2), - (app2, 1), - }; + var appResult1 = new ProcessApplicationResult( + gatewayId: "gateway-1", + gatewayName: "gateway-1", + applicationName: QualifiedApplicationName, + totalSourceCount: 3, + matchingSourceCount: 2, + trackedSourceDetails: + [ + new TrackedSourceDetail("https://github.com/org/repo-a", "abc123", DateTimeOffset.UtcNow, 0, [], []), + new TrackedSourceDetail("https://github.com/org/repo-a", "def456", DateTimeOffset.UtcNow, 1, [], []), + ], + updatedImages: new HashSet(), + gitReposUpdated: ["https://github.com/org/repo-a"]); + var appResult2 = new ProcessApplicationResult( + gatewayId: "gateway-2", + gatewayName: "gateway-2", + applicationName: SecondApplicationName, + totalSourceCount: 1, + matchingSourceCount: 1, + trackedSourceDetails: + [ + new TrackedSourceDetail("https://github.com/org/repo-b", "ghi789", DateTimeOffset.UtcNow, 0, [], []), + ], + updatedImages: new HashSet(), + gitReposUpdated: ["https://github.com/org/repo-b"]); + var applicationResults = new[] { appResult1, appResult2 }; + var totalApps = applicationResults.Select(r => (r.ApplicationName, r.TotalSourceCount, r.MatchingSourceCount)).ToList(); + var updatedApps = applicationResults.Where(r => r.Updated).Select(r => (r.ApplicationName, r.UpdatedSourceCount)).ToList(); // Act - writer.WriteManifestUpdateOutput(gateways, gitRepos, totalApps, updatedApps); + writer.WriteManifestUpdateOutput(["gateway-1", "gateway-2"], ["https://github.com/org/repo-a", "https://github.com/org/repo-b"], totalApps, updatedApps, applicationResults); // Assert using var _ = new AssertionScope(); @@ -203,18 +233,23 @@ public void WriteManifestUpdateOutput_MultipleItems_WritesCommaSeparatedValues() serviceMessages.GetPropertyValue("ArgoCD.GatewayIds").Should().Be("gateway-1, gateway-2"); serviceMessages.GetPropertyValue("ArgoCD.GitUris").Should().Be("https://github.com/org/repo-a, https://github.com/org/repo-b"); - serviceMessages.GetPropertyValue("ArgoCD.MatchingApplications").Should().Be($"{QualifiedApplicationName}, {app2}"); + serviceMessages.GetPropertyValue("ArgoCD.MatchingApplications").Should().Be($"{QualifiedApplicationName}, {SecondApplicationName}"); serviceMessages.GetPropertyValue("ArgoCD.MatchingApplicationTotalSourceCounts").Should().Be("3, 1"); serviceMessages.GetPropertyValue("ArgoCD.MatchingApplicationMatchingSourceCounts").Should().Be("2, 1"); - serviceMessages.GetPropertyValue("ArgoCD.UpdatedApplications").Should().Be($"{QualifiedApplicationName}, {app2}"); + serviceMessages.GetPropertyValue("ArgoCD.UpdatedApplications").Should().Be($"{QualifiedApplicationName}, {SecondApplicationName}"); serviceMessages.GetPropertyValue("ArgoCD.UpdatedApplicationSourceCounts").Should().Be("2, 1"); } [Test] public void WriteManifestUpdateOutput_EmptyCollections_WritesEmptyValues() { + // Arrange + var applicationResults = Array.Empty(); + var totalApps = applicationResults.Select(r => (r.ApplicationName, r.TotalSourceCount, r.MatchingSourceCount)).ToList(); + var updatedApps = applicationResults.Where(r => r.Updated).Select(r => (r.ApplicationName, r.UpdatedSourceCount)).ToList(); + // Act - writer.WriteManifestUpdateOutput([], [], [], []); + writer.WriteManifestUpdateOutput([], [], totalApps, updatedApps, applicationResults); // Assert using var _ = new AssertionScope(); @@ -233,14 +268,26 @@ public void WriteManifestUpdateOutput_EmptyCollections_WritesEmptyValues() public void WriteImageUpdateOutput_SingleItems_WritesAllOutputVariablesIncludingUpdatedImages() { // Arrange - var gateways = new[] { "gateway-1" }; - var gitRepos = new[] { "https://github.com/org/repo" }; - var totalApps = new[] { (QualifiedApplicationName, 3, 2) }; - var updatedApps = new[] { (QualifiedApplicationName, 2) }; - const int imagesUpdatedCount = 5; + var appResult = new ProcessApplicationResult( + gatewayId: "gateway-1", + gatewayName: "gateway-1", + applicationName: QualifiedApplicationName, + totalSourceCount: 3, + matchingSourceCount: 2, + trackedSourceDetails: + [ + new TrackedSourceDetail("https://github.com/org/repo", "abc123", DateTimeOffset.UtcNow, 0, [], []), + new TrackedSourceDetail("https://github.com/org/repo", "def456", DateTimeOffset.UtcNow, 1, [], []), + ], + updatedImages: ["image-a:1.0", "image-b:2.0", "image-c:3.0", "image-d:4.0", "image-e:5.0"], + gitReposUpdated: ["https://github.com/org/repo"]); + var applicationResults = new[] { appResult }; + var totalApps = applicationResults.Select(r => (r.ApplicationName, r.TotalSourceCount, r.MatchingSourceCount)).ToList(); + var updatedApps = applicationResults.Where(r => r.Updated).Select(r => (r.ApplicationName, r.UpdatedSourceCount)).ToList(); + var imagesUpdatedCount = applicationResults.SelectMany(r => r.UpdatedImages).ToHashSet().Count; // Act - writer.WriteImageUpdateOutput(gateways, gitRepos, totalApps, updatedApps, imagesUpdatedCount); + writer.WriteImageUpdateOutput(["gateway-1"], ["https://github.com/org/repo"], totalApps, updatedApps, imagesUpdatedCount, applicationResults.ToList()); // Assert using var _ = new AssertionScope(); @@ -260,23 +307,39 @@ public void WriteImageUpdateOutput_SingleItems_WritesAllOutputVariablesIncluding public void WriteImageUpdateOutput_MultipleItems_WritesCommaSeparatedValues() { // Arrange - var gateways = new[] { "gateway-1", "gateway-2" }; - var gitRepos = new[] { "https://github.com/org/repo-a", "https://github.com/org/repo-b" }; - var app2 = QualifiedApplicationName.Create("OtherApp", "argocd"); - var totalApps = new[] - { - (QualifiedApplicationName, 4, 3), - (app2, 2, 1), - }; - var updatedApps = new[] - { - (QualifiedApplicationName, 3), - (app2, 1), - }; - const int imagesUpdatedCount = 4; + var appResult1 = new ProcessApplicationResult( + gatewayId: "gateway-1", + gatewayName: "gateway-1", + applicationName: QualifiedApplicationName, + totalSourceCount: 4, + matchingSourceCount: 3, + trackedSourceDetails: + [ + new TrackedSourceDetail("https://github.com/org/repo-a", "abc123", DateTimeOffset.UtcNow, 0, [], []), + new TrackedSourceDetail("https://github.com/org/repo-a", "def456", DateTimeOffset.UtcNow, 1, [], []), + new TrackedSourceDetail("https://github.com/org/repo-a", "ghi789", DateTimeOffset.UtcNow, 2, [], []), + ], + updatedImages: ["image-a:1.0", "image-b:2.0"], + gitReposUpdated: ["https://github.com/org/repo-a"]); + var appResult2 = new ProcessApplicationResult( + gatewayId: "gateway-2", + gatewayName: "gateway-2", + applicationName: SecondApplicationName, + totalSourceCount: 2, + matchingSourceCount: 1, + trackedSourceDetails: + [ + new TrackedSourceDetail("https://github.com/org/repo-b", "jkl012", DateTimeOffset.UtcNow, 0, [], []), + ], + updatedImages: ["image-c:3.0", "image-d:4.0"], + gitReposUpdated: ["https://github.com/org/repo-b"]); + var applicationResults = new[] { appResult1, appResult2 }; + var totalApps = applicationResults.Select(r => (r.ApplicationName, r.TotalSourceCount, r.MatchingSourceCount)).ToList(); + var updatedApps = applicationResults.Where(r => r.Updated).Select(r => (r.ApplicationName, r.UpdatedSourceCount)).ToList(); + var imagesUpdatedCount = applicationResults.SelectMany(r => r.UpdatedImages).ToHashSet().Count; // Act - writer.WriteImageUpdateOutput(gateways, gitRepos, totalApps, updatedApps, imagesUpdatedCount); + writer.WriteImageUpdateOutput(["gateway-1", "gateway-2"], ["https://github.com/org/repo-a", "https://github.com/org/repo-b"], totalApps, updatedApps, imagesUpdatedCount, applicationResults.ToList()); // Assert using var _ = new AssertionScope(); @@ -284,10 +347,10 @@ public void WriteImageUpdateOutput_MultipleItems_WritesCommaSeparatedValues() serviceMessages.GetPropertyValue("ArgoCD.GatewayIds").Should().Be("gateway-1, gateway-2"); serviceMessages.GetPropertyValue("ArgoCD.GitUris").Should().Be("https://github.com/org/repo-a, https://github.com/org/repo-b"); - serviceMessages.GetPropertyValue("ArgoCD.MatchingApplications").Should().Be($"{QualifiedApplicationName}, {app2}"); + serviceMessages.GetPropertyValue("ArgoCD.MatchingApplications").Should().Be($"{QualifiedApplicationName}, {SecondApplicationName}"); serviceMessages.GetPropertyValue("ArgoCD.MatchingApplicationTotalSourceCounts").Should().Be("4, 2"); serviceMessages.GetPropertyValue("ArgoCD.MatchingApplicationMatchingSourceCounts").Should().Be("3, 1"); - serviceMessages.GetPropertyValue("ArgoCD.UpdatedApplications").Should().Be($"{QualifiedApplicationName}, {app2}"); + serviceMessages.GetPropertyValue("ArgoCD.UpdatedApplications").Should().Be($"{QualifiedApplicationName}, {SecondApplicationName}"); serviceMessages.GetPropertyValue("ArgoCD.UpdatedApplicationSourceCounts").Should().Be("3, 1"); serviceMessages.GetPropertyValue("ArgoCD.UpdatedImages").Should().Be("4"); } @@ -295,8 +358,14 @@ public void WriteImageUpdateOutput_MultipleItems_WritesCommaSeparatedValues() [Test] public void WriteImageUpdateOutput_ZeroImagesUpdated_WritesZeroForUpdatedImages() { + // Arrange + var applicationResults = Array.Empty(); + var totalApps = applicationResults.Select(r => (r.ApplicationName, r.TotalSourceCount, r.MatchingSourceCount)).ToList(); + var updatedApps = applicationResults.Where(r => r.Updated).Select(r => (r.ApplicationName, r.UpdatedSourceCount)).ToList(); + var imagesUpdatedCount = applicationResults.SelectMany(r => r.UpdatedImages).ToHashSet().Count; + // Act - writer.WriteImageUpdateOutput([], [], [], [], 0); + writer.WriteImageUpdateOutput([], [], totalApps, updatedApps, imagesUpdatedCount, applicationResults.ToList()); // Assert var serviceMessages = log.Messages.GetServiceMessagesOfType("setVariable"); diff --git a/source/Calamari/ArgoCD/ArgoCDFilesUpdatedReporter.cs b/source/Calamari/ArgoCD/ArgoCDFilesUpdatedReporter.cs index ebf06cdc9c..d2d5bc8c3d 100644 --- a/source/Calamari/ArgoCD/ArgoCDFilesUpdatedReporter.cs +++ b/source/Calamari/ArgoCD/ArgoCDFilesUpdatedReporter.cs @@ -34,7 +34,7 @@ public void ReportFilesUpdated(GitCommitParameters gitCommitParameters, IReadOnl { { ArgoCDFilesUpdatedAttributes.GatewayId, appResult.GatewayId }, { ArgoCDFilesUpdatedAttributes.ApplicationName, appResult.ApplicationName.Value }, - { ArgoCDFilesUpdatedAttributes.Sources, JsonSerializer.Serialize(ConvertPathsToPosix(appResult.TrackedSourceDetails)) } + { ArgoCDFilesUpdatedAttributes.Sources, JsonSerializer.Serialize(MapToDto(ConvertPathsToPosix(appResult.TrackedSourceDetails))) } }; var message = new ServiceMessage( @@ -45,6 +45,17 @@ public void ReportFilesUpdated(GitCommitParameters gitCommitParameters, IReadOnl } } + List MapToDto(List inputs) + { + return inputs.Select(i => new SpecialVariables.ServiceMessages.ArgoCDFilesUpdated.SourceDetails( + i.CommitSha, + i.CommitTimestamp, + i.SourceIndex, + i.ReplacedFiles, + i.PatchedFiles)) + .ToList(); + } + List ConvertPathsToPosix(List inputs) { return inputs.Select(usd => usd with diff --git a/source/Calamari/ArgoCD/ArgoCDOutputVariablesWriter.cs b/source/Calamari/ArgoCD/ArgoCDOutputVariablesWriter.cs index 81baa64f6c..9e4563cdc4 100644 --- a/source/Calamari/ArgoCD/ArgoCDOutputVariablesWriter.cs +++ b/source/Calamari/ArgoCD/ArgoCDOutputVariablesWriter.cs @@ -125,7 +125,7 @@ public void WriteManifestUpdateOutput(IEnumerable gateways, IEnumerable gitRepos, IReadOnlyCollection<(QualifiedApplicationName ApplicationName, int TotalSourceCount, int MatchingSourceCount)> totalApplicationsWithSourceCounts, IReadOnlyCollection<(QualifiedApplicationName ApplicationName, int SourceCount)> updatedApplicationsWithSourceCounts, - List applicationResults) + IReadOnlyCollection applicationResults) { foreach (var applicationResult in applicationResults) { diff --git a/source/Calamari/Kubernetes/SpecialVariables.cs b/source/Calamari/Kubernetes/SpecialVariables.cs index 909e18f30b..b540615855 100644 --- a/source/Calamari/Kubernetes/SpecialVariables.cs +++ b/source/Calamari/Kubernetes/SpecialVariables.cs @@ -1,4 +1,6 @@ using System; +using System.Collections.Generic; +using Calamari.ArgoCD; using Calamari.ArgoCD.Models; namespace Calamari.Kubernetes @@ -191,6 +193,13 @@ public static class Attributes public const string ApplicationName = "applicationName"; public const string Sources = "sources"; } + + public record SourceDetails( + string? CommitSha, + DateTimeOffset? CommitTimestamp, + int SourceIndex, + List ReplacedFiles, + List PatchedFiles); } } } From b93be5212b83fd0a822fe91f91a4a555d7c3c35b Mon Sep 17 00:00:00 2001 From: Frank Lin Date: Wed, 3 Jun 2026 13:39:39 +1000 Subject: [PATCH 6/6] fds --- .../ArgoCD/ArgoCDFilesUpdatedReporterTests.cs | 26 ++++---- .../ArgoCDOutputVariablesWriterTests.cs | 34 +++++------ .../ArgoCD/ArgoCDOutputVariablesWriter.cs | 59 +------------------ .../ManifestTemplating/ApplicationUpdater.cs | 2 +- .../UpdateArgoCDAppImagesInstallConvention.cs | 17 +----- ...CDApplicationManifestsInstallConvention.cs | 12 +--- .../UpdateImageTag/ApplicationUpdater.cs | 2 +- .../ArgoCD/ProcessApplicationResult.cs | 3 +- .../Calamari/Kubernetes/SpecialVariables.cs | 3 + 9 files changed, 43 insertions(+), 115 deletions(-) diff --git a/source/Calamari.Tests/ArgoCD/ArgoCDFilesUpdatedReporterTests.cs b/source/Calamari.Tests/ArgoCD/ArgoCDFilesUpdatedReporterTests.cs index bc5b3d0f11..1075218678 100644 --- a/source/Calamari.Tests/ArgoCD/ArgoCDFilesUpdatedReporterTests.cs +++ b/source/Calamari.Tests/ArgoCD/ArgoCDFilesUpdatedReporterTests.cs @@ -39,7 +39,7 @@ public void ReportDeployments_WhenGitParamsRequirePullRequest_WritesNoServiceMes timestamp, 0, [], - []) + [],[]) ], [], []) @@ -97,7 +97,7 @@ public void ReportDeployments_WithSingleUpdatedApplication_WritesOneServiceMessa timestamp, 0, [], - []) + [],[]) ], [], []) @@ -142,7 +142,7 @@ public void ReportDeployments_WithMultipleUpdatedApplications_WritesMultipleServ timestamp, 0, [], - []) + [],[]) ], [], []), @@ -158,7 +158,7 @@ public void ReportDeployments_WithMultipleUpdatedApplications_WritesMultipleServ timestamp, 0, [], - []) + [],[]) ], [], []) @@ -212,7 +212,7 @@ public void ReportDeployments_WithReplacedFiles_IncludesReplacedFilesInSources() timestamp, 0, [new FileHash("values.yaml", "22c0df2cceca5273e4dc569dda52805d27df3360")], - []) + [],[]) ], [], []) @@ -257,7 +257,7 @@ public void ReportDeployments_WithPatchedFiles_IncludesPatchedFilesInSources() timestamp, 0, [], - [new FileJsonPatch("kustomization.yaml", """[{"op":"replace","path":"/images/0/name","value":"nginx:latest"}]""")]) + [new FileJsonPatch("kustomization.yaml", """[{"op":"replace","path":"/images/0/name","value":"nginx:latest"}]""")],[]) ], [], []) @@ -302,7 +302,7 @@ public void ReportDeployments_WithBothReplacedAndPatchedFiles_IncludesBothInSour timestamp, 0, [new FileHash("values.yaml", "22c0df2cceca5273e4dc569dda52805d27df3360")], - [new FileJsonPatch("kustomization.yaml", """[{"op":"replace","path":"/images/0/name","value":"nginx:latest"}]""")]) + [new FileJsonPatch("kustomization.yaml", """[{"op":"replace","path":"/images/0/name","value":"nginx:latest"}]""")],[]) ], [], []) @@ -353,7 +353,7 @@ public void ReportDeployments_WithMultipleReplacedAndPatchedFiles_IncludesAllFil [ new FileJsonPatch("kustomization.yaml", """[{"op":"replace","path":"/images/0/name","value":"nginx:latest"}]"""), new FileJsonPatch("patch.yaml", """[{"op":"replace","path":"/spec/replicas","value":3}]""") - ]) + ],[]) ], [], []) @@ -398,14 +398,14 @@ public void ReportDeployments_WithMultipleSourcesWithFiles_IncludesAllSourcesInS timestamp, 0, [new FileHash("values.yaml", "22c0df2cceca5273e4dc569dda52805d27df3360")], - []), + [],[]), new TrackedSourceDetail( "https://github.com", "abc123", timestamp, 1, [], - [new FileJsonPatch("kustomization.yaml", """[{"op":"replace","path":"/images/0/name","value":"redis:latest"}]""")]) + [new FileJsonPatch("kustomization.yaml", """[{"op":"replace","path":"/images/0/name","value":"redis:latest"}]""")],[]) ], [], []) @@ -450,7 +450,7 @@ public void ReportDeployments_WithOsSpecificReplacedFilePaths_ReportsPosixPaths( timestamp, 0, [new FileHash(Path.Combine("some", "nested", "values.yaml"), "22c0df2cceca5273e4dc569dda52805d27df3360")], - []) + [],[]) ], [], []) @@ -493,7 +493,7 @@ public void ReportDeployments_WithNoOpSource_EmitsServiceMessageWithNullCommitSh null, 0, [], - [new FileJsonPatch("values.yaml", """[{"op":"replace","path":"/image","value":"nginx:1.27"}]""")]) + [new FileJsonPatch("values.yaml", """[{"op":"replace","path":"/image","value":"nginx:1.27"}]""")],[]) ], [], []) @@ -546,7 +546,7 @@ public void ReportDeployments_WithMixedUpdatedAndNonUpdatedApplications_WritesOn timestamp, 0, [], - []) + [],[]) ], [], []), diff --git a/source/Calamari.Tests/ArgoCD/ArgoCDOutputVariablesWriterTests.cs b/source/Calamari.Tests/ArgoCD/ArgoCDOutputVariablesWriterTests.cs index f78d59566e..a16d23384a 100644 --- a/source/Calamari.Tests/ArgoCD/ArgoCDOutputVariablesWriterTests.cs +++ b/source/Calamari.Tests/ArgoCD/ArgoCDOutputVariablesWriterTests.cs @@ -165,8 +165,8 @@ public void WriteManifestUpdateOutput_SingleItems_WritesAllOutputVariables() matchingSourceCount: 2, trackedSourceDetails: [ - new TrackedSourceDetail("https://github.com/org/repo", "abc123", DateTimeOffset.UtcNow, 0, [], []), - new TrackedSourceDetail("https://github.com/org/repo", "def456", DateTimeOffset.UtcNow, 1, [], []), + new TrackedSourceDetail("https://github.com/org/repo", "abc123", DateTimeOffset.UtcNow, 0, [], [],[]), + new TrackedSourceDetail("https://github.com/org/repo", "def456", DateTimeOffset.UtcNow, 1, [], [],[]), ], updatedImages: new HashSet(), gitReposUpdated: ["https://github.com/org/repo"]); @@ -175,7 +175,7 @@ public void WriteManifestUpdateOutput_SingleItems_WritesAllOutputVariables() var updatedApps = applicationResults.Where(r => r.Updated).Select(r => (r.ApplicationName, r.UpdatedSourceCount)).ToList(); // Act - writer.WriteManifestUpdateOutput(["gateway-1"], ["https://github.com/org/repo"], totalApps, updatedApps, applicationResults); + writer.WriteManifestUpdateOutput(applicationResults); // Assert using var _ = new AssertionScope(); @@ -203,8 +203,8 @@ public void WriteManifestUpdateOutput_MultipleItems_WritesCommaSeparatedValues() matchingSourceCount: 2, trackedSourceDetails: [ - new TrackedSourceDetail("https://github.com/org/repo-a", "abc123", DateTimeOffset.UtcNow, 0, [], []), - new TrackedSourceDetail("https://github.com/org/repo-a", "def456", DateTimeOffset.UtcNow, 1, [], []), + new TrackedSourceDetail("https://github.com/org/repo-a", "abc123", DateTimeOffset.UtcNow, 0, [], [],[]), + new TrackedSourceDetail("https://github.com/org/repo-a", "def456", DateTimeOffset.UtcNow, 1, [], [],[]), ], updatedImages: new HashSet(), gitReposUpdated: ["https://github.com/org/repo-a"]); @@ -216,7 +216,7 @@ public void WriteManifestUpdateOutput_MultipleItems_WritesCommaSeparatedValues() matchingSourceCount: 1, trackedSourceDetails: [ - new TrackedSourceDetail("https://github.com/org/repo-b", "ghi789", DateTimeOffset.UtcNow, 0, [], []), + new TrackedSourceDetail("https://github.com/org/repo-b", "ghi789", DateTimeOffset.UtcNow, 0, [], [],[]), ], updatedImages: new HashSet(), gitReposUpdated: ["https://github.com/org/repo-b"]); @@ -225,7 +225,7 @@ public void WriteManifestUpdateOutput_MultipleItems_WritesCommaSeparatedValues() var updatedApps = applicationResults.Where(r => r.Updated).Select(r => (r.ApplicationName, r.UpdatedSourceCount)).ToList(); // Act - writer.WriteManifestUpdateOutput(["gateway-1", "gateway-2"], ["https://github.com/org/repo-a", "https://github.com/org/repo-b"], totalApps, updatedApps, applicationResults); + writer.WriteManifestUpdateOutput(applicationResults); // Assert using var _ = new AssertionScope(); @@ -249,7 +249,7 @@ public void WriteManifestUpdateOutput_EmptyCollections_WritesEmptyValues() var updatedApps = applicationResults.Where(r => r.Updated).Select(r => (r.ApplicationName, r.UpdatedSourceCount)).ToList(); // Act - writer.WriteManifestUpdateOutput([], [], totalApps, updatedApps, applicationResults); + writer.WriteManifestUpdateOutput(applicationResults); // Assert using var _ = new AssertionScope(); @@ -276,8 +276,8 @@ public void WriteImageUpdateOutput_SingleItems_WritesAllOutputVariablesIncluding matchingSourceCount: 2, trackedSourceDetails: [ - new TrackedSourceDetail("https://github.com/org/repo", "abc123", DateTimeOffset.UtcNow, 0, [], []), - new TrackedSourceDetail("https://github.com/org/repo", "def456", DateTimeOffset.UtcNow, 1, [], []), + new TrackedSourceDetail("https://github.com/org/repo", "abc123", DateTimeOffset.UtcNow, 0, [], [],[]), + new TrackedSourceDetail("https://github.com/org/repo", "def456", DateTimeOffset.UtcNow, 1, [], [],[]), ], updatedImages: ["image-a:1.0", "image-b:2.0", "image-c:3.0", "image-d:4.0", "image-e:5.0"], gitReposUpdated: ["https://github.com/org/repo"]); @@ -287,7 +287,7 @@ public void WriteImageUpdateOutput_SingleItems_WritesAllOutputVariablesIncluding var imagesUpdatedCount = applicationResults.SelectMany(r => r.UpdatedImages).ToHashSet().Count; // Act - writer.WriteImageUpdateOutput(["gateway-1"], ["https://github.com/org/repo"], totalApps, updatedApps, imagesUpdatedCount, applicationResults.ToList()); + writer.WriteImageUpdateOutput(applicationResults.ToList()); // Assert using var _ = new AssertionScope(); @@ -315,9 +315,9 @@ public void WriteImageUpdateOutput_MultipleItems_WritesCommaSeparatedValues() matchingSourceCount: 3, trackedSourceDetails: [ - new TrackedSourceDetail("https://github.com/org/repo-a", "abc123", DateTimeOffset.UtcNow, 0, [], []), - new TrackedSourceDetail("https://github.com/org/repo-a", "def456", DateTimeOffset.UtcNow, 1, [], []), - new TrackedSourceDetail("https://github.com/org/repo-a", "ghi789", DateTimeOffset.UtcNow, 2, [], []), + new TrackedSourceDetail("https://github.com/org/repo-a", "abc123", DateTimeOffset.UtcNow, 0, [], [],[]), + new TrackedSourceDetail("https://github.com/org/repo-a", "def456", DateTimeOffset.UtcNow, 1, [], [],[]), + new TrackedSourceDetail("https://github.com/org/repo-a", "ghi789", DateTimeOffset.UtcNow, 2, [], [],[]), ], updatedImages: ["image-a:1.0", "image-b:2.0"], gitReposUpdated: ["https://github.com/org/repo-a"]); @@ -329,7 +329,7 @@ public void WriteImageUpdateOutput_MultipleItems_WritesCommaSeparatedValues() matchingSourceCount: 1, trackedSourceDetails: [ - new TrackedSourceDetail("https://github.com/org/repo-b", "jkl012", DateTimeOffset.UtcNow, 0, [], []), + new TrackedSourceDetail("https://github.com/org/repo-b", "jkl012", DateTimeOffset.UtcNow, 0, [], [],[]), ], updatedImages: ["image-c:3.0", "image-d:4.0"], gitReposUpdated: ["https://github.com/org/repo-b"]); @@ -339,7 +339,7 @@ public void WriteImageUpdateOutput_MultipleItems_WritesCommaSeparatedValues() var imagesUpdatedCount = applicationResults.SelectMany(r => r.UpdatedImages).ToHashSet().Count; // Act - writer.WriteImageUpdateOutput(["gateway-1", "gateway-2"], ["https://github.com/org/repo-a", "https://github.com/org/repo-b"], totalApps, updatedApps, imagesUpdatedCount, applicationResults.ToList()); + writer.WriteImageUpdateOutput(applicationResults.ToList()); // Assert using var _ = new AssertionScope(); @@ -365,7 +365,7 @@ public void WriteImageUpdateOutput_ZeroImagesUpdated_WritesZeroForUpdatedImages( var imagesUpdatedCount = applicationResults.SelectMany(r => r.UpdatedImages).ToHashSet().Count; // Act - writer.WriteImageUpdateOutput([], [], totalApps, updatedApps, imagesUpdatedCount, applicationResults.ToList()); + writer.WriteImageUpdateOutput(applicationResults.ToList()); // Assert var serviceMessages = log.Messages.GetServiceMessagesOfType("setVariable"); diff --git a/source/Calamari/ArgoCD/ArgoCDOutputVariablesWriter.cs b/source/Calamari/ArgoCD/ArgoCDOutputVariablesWriter.cs index 9e4563cdc4..e16d74436d 100644 --- a/source/Calamari/ArgoCD/ArgoCDOutputVariablesWriter.cs +++ b/source/Calamari/ArgoCD/ArgoCDOutputVariablesWriter.cs @@ -90,12 +90,7 @@ static ServiceMessage CreatePullRequestCreatedServiceMessage(PullRequestPushResu return message; } - public void WriteImageUpdateOutput(IEnumerable gateways, - IEnumerable gitRepos, - IReadOnlyCollection<(QualifiedApplicationName ApplicationName, int TotalSourceCount, int MatchingSourceCount)> totalApplicationsWithSourceCounts, - IReadOnlyCollection<(QualifiedApplicationName ApplicationName, int SourceCount)> updatedApplicationsWithSourceCounts, - int imagesUpdatedCount, - List applicationResults) + public void WriteImageUpdateOutput(List applicationResults) { foreach (var applicationResult in applicationResults) @@ -110,22 +105,12 @@ public void WriteImageUpdateOutput(IEnumerable gateways, log.SetOutputVariableButDoNotAddToVariables(appSourceVariables.Updated, sourceDetail.CommitSha.IsNullOrEmpty().ToString()); log.SetOutputVariableButDoNotAddToVariables(appSourceVariables.RepositoryUrl, sourceDetail.RepositoryUri); + log.SetOutputVariableButDoNotAddToVariables(appSourceVariables.UpdatedImages, ToCommaSeparatedString(sourceDetail.imagesUpdated)); } } - - WriteGatewayIds(gateways); - WriteGitUris(gitRepos); - WriteTotalApplicationsWithSourceCounts(totalApplicationsWithSourceCounts); - WriteUpdatedApplicationsWithSourceCounts(updatedApplicationsWithSourceCounts); - - log.SetOutputVariableButDoNotAddToVariables(SpecialVariables.Git.Output.UpdatedImages, imagesUpdatedCount.ToString()); } - public void WriteManifestUpdateOutput(IEnumerable gateways, - IEnumerable gitRepos, - IReadOnlyCollection<(QualifiedApplicationName ApplicationName, int TotalSourceCount, int MatchingSourceCount)> totalApplicationsWithSourceCounts, - IReadOnlyCollection<(QualifiedApplicationName ApplicationName, int SourceCount)> updatedApplicationsWithSourceCounts, - IReadOnlyCollection applicationResults) + public void WriteManifestUpdateOutput(IReadOnlyCollection applicationResults) { foreach (var applicationResult in applicationResults) { @@ -141,44 +126,6 @@ public void WriteManifestUpdateOutput(IEnumerable gateways, log.SetOutputVariableButDoNotAddToVariables(appSourceVariables.RepositoryUrl, sourceDetail.RepositoryUri); } } - - WriteGatewayIds(gateways); - WriteGitUris(gitRepos); - WriteTotalApplicationsWithSourceCounts(totalApplicationsWithSourceCounts); - WriteUpdatedApplicationsWithSourceCounts(updatedApplicationsWithSourceCounts); - } - - void WriteTotalApplicationsWithSourceCounts(IReadOnlyCollection<(QualifiedApplicationName ApplicationName, int TotalSourceCount, int MatchingSourceCount)> matchingApplicationsWithSourceCounts) - { - var totalApps = ToCommaSeparatedString(matchingApplicationsWithSourceCounts.Select(c => c.ApplicationName)); - log.SetOutputVariableButDoNotAddToVariables(SpecialVariables.Git.Output.MatchingApplications, totalApps); - - var totalSourceCounts = ToCommaSeparatedString(matchingApplicationsWithSourceCounts.Select(c => c.TotalSourceCount)); - log.SetOutputVariableButDoNotAddToVariables(SpecialVariables.Git.Output.MatchingApplicationTotalSourceCounts, totalSourceCounts); - - var matchingSourceCounts = ToCommaSeparatedString(matchingApplicationsWithSourceCounts.Select(c => c.MatchingSourceCount)); - log.SetOutputVariableButDoNotAddToVariables(SpecialVariables.Git.Output.MatchingApplicationMatchingSourceCounts, matchingSourceCounts); - } - - void WriteUpdatedApplicationsWithSourceCounts(IReadOnlyCollection<(QualifiedApplicationName ApplicationName, int SourceCount)> updatedApplicationsWithSourceCount) - { - var updatedApps = ToCommaSeparatedString(updatedApplicationsWithSourceCount.Select(c => c.ApplicationName)); - log.SetOutputVariableButDoNotAddToVariables(SpecialVariables.Git.Output.UpdatedApplications, updatedApps); - var updatedSourceCounts = ToCommaSeparatedString(updatedApplicationsWithSourceCount.Select(c => c.SourceCount)); - - log.SetOutputVariableButDoNotAddToVariables(SpecialVariables.Git.Output.UpdatedApplicationSourceCounts, updatedSourceCounts); - } - - void WriteGitUris(IEnumerable gitRepos) - { - var gitUris = ToCommaSeparatedString(gitRepos); - log.SetOutputVariableButDoNotAddToVariables(SpecialVariables.Git.Output.GitUris, gitUris); - } - - void WriteGatewayIds(IEnumerable gateways) - { - var gatewayIds = ToCommaSeparatedString(gateways); - log.SetOutputVariableButDoNotAddToVariables(SpecialVariables.Git.Output.GatewayIds, gatewayIds); } static string ToCommaSeparatedString(IEnumerable items) diff --git a/source/Calamari/ArgoCD/Conventions/ManifestTemplating/ApplicationUpdater.cs b/source/Calamari/ArgoCD/Conventions/ManifestTemplating/ApplicationUpdater.cs index 28be4f1ebf..900617113c 100644 --- a/source/Calamari/ArgoCD/Conventions/ManifestTemplating/ApplicationUpdater.cs +++ b/source/Calamari/ArgoCD/Conventions/ManifestTemplating/ApplicationUpdater.cs @@ -94,7 +94,7 @@ public ProcessApplicationResult ProcessApplication( QualifiedApplicationName.Create(applicationName, applicationFromYaml.Metadata.Namespace), applicationFromYaml.Spec.Sources.Count, applicationFromYaml.Spec.Sources.Count(s => deploymentScope.Matches(ScopingAnnotationReader.GetScopeForApplicationSource(s.Name.ToApplicationSourceName(), applicationFromYaml.Metadata.Annotations, containsMultipleSources))), - trackedSourceUpdateResults.Select(r => new TrackedSourceDetail(r.applicationSource.Source.OriginalRepoUrl, r.UpdateResult.CommitSha, r.UpdateResult.CommitTimestamp, r.applicationSource.Index, r.UpdateResult.ReplacedFiles, [])).ToList(), + trackedSourceUpdateResults.Select(r => new TrackedSourceDetail(r.applicationSource.Source.OriginalRepoUrl, r.UpdateResult.CommitSha, r.UpdateResult.CommitTimestamp, r.applicationSource.Index, r.UpdateResult.ReplacedFiles, [], [])).ToList(), [], trackedSourceUpdateResults.Where(r => r.UpdateResult.Updated).Select(r => r.applicationSource.Source.OriginalRepoUrl).ToHashSet()); } diff --git a/source/Calamari/ArgoCD/Conventions/UpdateArgoCDAppImagesInstallConvention.cs b/source/Calamari/ArgoCD/Conventions/UpdateArgoCDAppImagesInstallConvention.cs index d5e7275e3a..5147631c8a 100644 --- a/source/Calamari/ArgoCD/Conventions/UpdateArgoCDAppImagesInstallConvention.cs +++ b/source/Calamari/ArgoCD/Conventions/UpdateArgoCDAppImagesInstallConvention.cs @@ -86,22 +86,9 @@ public void Install(RunningDeployment deployment) //if we are creating a pull request, we don't want to report files updated (as this will be passed down as output variables _with_ the PR info) - reporter.ReportFilesUpdated(deploymentConfig.CommitParameters, applicationResults); + reporter.ReportFilesUpdated(deploymentConfig.CommitParameters, applicationResults); - var totalApplicationsWithSourceCounts = applicationResults.Select(r => (r.ApplicationName, r.TotalSourceCount, r.MatchingSourceCount)).ToList(); - var updatedApplications = applicationResults.Where(r => r.Updated).ToList(); - var updatedApplicationsWithSources = updatedApplications.Select(r => (r.ApplicationName, r.UpdatedSourceCount)).ToList(); - var gitReposUpdated = updatedApplications.SelectMany(r => r.GitReposUpdated).ToHashSet(); - var newImagesWritten = updatedApplications.SelectMany(r => r.UpdatedImages).ToHashSet(); - - var gatewayIds = argoProperties.Applications.Select(a => a.GatewayId).ToHashSet(); - outputVariablesWriter.WriteImageUpdateOutput(gatewayIds, - gitReposUpdated, - totalApplicationsWithSourceCounts, - updatedApplicationsWithSources, - newImagesWritten.Count, - applicationResults - ); + outputVariablesWriter.WriteImageUpdateOutput(applicationResults); } } } \ No newline at end of file diff --git a/source/Calamari/ArgoCD/Conventions/UpdateArgoCDApplicationManifestsInstallConvention.cs b/source/Calamari/ArgoCD/Conventions/UpdateArgoCDApplicationManifestsInstallConvention.cs index edb3f3e5ba..c627ce54fa 100644 --- a/source/Calamari/ArgoCD/Conventions/UpdateArgoCDApplicationManifestsInstallConvention.cs +++ b/source/Calamari/ArgoCD/Conventions/UpdateArgoCDApplicationManifestsInstallConvention.cs @@ -94,17 +94,7 @@ public void Install(RunningDeployment deployment) reporter.ReportFilesUpdated(deploymentConfig.CommitParameters, applicationResults); - var gitReposUpdated = applicationResults.SelectMany(r => r.GitReposUpdated).ToHashSet(); - var totalApplicationsWithSourceCounts = applicationResults.Select(r => (r.ApplicationName, r.TotalSourceCount, r.MatchingSourceCount)).ToList(); - var updatedApplicationsWithSources = applicationResults.Where(r => r.UpdatedSourceCount > 0).Select(r => (r.ApplicationName, r.UpdatedSourceCount)).ToList(); - - var gatewayIds = argoProperties.Applications.Select(a => a.GatewayId).ToHashSet(); - outputVariablesWriter.WriteManifestUpdateOutput(gatewayIds, - gitReposUpdated, - totalApplicationsWithSourceCounts, - updatedApplicationsWithSources, - applicationResults - ); + outputVariablesWriter.WriteManifestUpdateOutput(applicationResults); } IPackageRelativeFile[] GetReferencedPackageFiles(ArgoCommitToGitConfig config) diff --git a/source/Calamari/ArgoCD/Conventions/UpdateImageTag/ApplicationUpdater.cs b/source/Calamari/ArgoCD/Conventions/UpdateImageTag/ApplicationUpdater.cs index 2dc83e3d5e..429e21b3a7 100644 --- a/source/Calamari/ArgoCD/Conventions/UpdateImageTag/ApplicationUpdater.cs +++ b/source/Calamari/ArgoCD/Conventions/UpdateImageTag/ApplicationUpdater.cs @@ -82,7 +82,7 @@ public ProcessApplicationResult ProcessApplication( QualifiedApplicationName.Create(applicationName, applicationFromYaml.Metadata.Namespace), applicationFromYaml.Spec.Sources.Count, applicationFromYaml.Spec.Sources.Count(s => deploymentScope.Matches(ScopingAnnotationReader.GetScopeForApplicationSource(s.Name.ToApplicationSourceName(), applicationFromYaml.Metadata.Annotations, containsMultipleSources))), - appliedSourcesResults.Select(r => new TrackedSourceDetail(r.applicationSource.Source.OriginalRepoUrl, r.UpdateResult.PushResult?.CommitSha, r.UpdateResult.PushResult?.CommitTimestamp, r.applicationSource.Index, [], r.UpdateResult.PatchedFiles)).ToList(), + appliedSourcesResults.Select(r => new TrackedSourceDetail(r.applicationSource.Source.OriginalRepoUrl, r.UpdateResult.PushResult?.CommitSha, r.UpdateResult.PushResult?.CommitTimestamp, r.applicationSource.Index, [], r.UpdateResult.PatchedFiles, r.UpdateResult.ImagesUpdated)).ToList(), appliedSourcesResults.SelectMany(r => r.UpdateResult.ImagesUpdated).ToHashSet(), appliedSourcesResults.Where(r => r.UpdateResult.Updated).Select(r => r.applicationSource.Source.OriginalRepoUrl).ToHashSet()); } diff --git a/source/Calamari/ArgoCD/ProcessApplicationResult.cs b/source/Calamari/ArgoCD/ProcessApplicationResult.cs index b62efb0810..08b4136daa 100644 --- a/source/Calamari/ArgoCD/ProcessApplicationResult.cs +++ b/source/Calamari/ArgoCD/ProcessApplicationResult.cs @@ -13,7 +13,8 @@ public record TrackedSourceDetail( DateTimeOffset? CommitTimestamp, int SourceIndex, List ReplacedFiles, - List PatchedFiles); + List PatchedFiles, + HashSet imagesUpdated); public class ProcessApplicationResult( string gatewayId, diff --git a/source/Calamari/Kubernetes/SpecialVariables.cs b/source/Calamari/Kubernetes/SpecialVariables.cs index fdb129a56c..e3d7438266 100644 --- a/source/Calamari/Kubernetes/SpecialVariables.cs +++ b/source/Calamari/Kubernetes/SpecialVariables.cs @@ -141,6 +141,9 @@ public record ApplicationSourceOutputVariables(int Index, ApplicationOutputVaria //These are always sent public string Updated => $"{qualifiedPrefix}.Updated"; public string RepositoryUrl => $"{qualifiedPrefix}.RepositoryUrl"; + + //These are only sent for image tag updates + public string UpdatedImages => $"{qualifiedPrefix}.UpdatedImages"; } } }