diff --git a/source/Calamari.Tests/ArgoCD/ArgoCDFilesUpdatedReporterTests.cs b/source/Calamari.Tests/ArgoCD/ArgoCDFilesUpdatedReporterTests.cs index 4cc5d0ba37..1075218678 100644 --- a/source/Calamari.Tests/ArgoCD/ArgoCDFilesUpdatedReporterTests.cs +++ b/source/Calamari.Tests/ArgoCD/ArgoCDFilesUpdatedReporterTests.cs @@ -24,19 +24,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", - new ApplicationName("app1"), + "gateway1Name", + QualifiedApplicationName.Create("app1", "argocd"), 2, 2, [ - new TrackedSourceDetail("abc123", - timestamp, - 0, - [], - []) + new TrackedSourceDetail( + "https://github.com", + "abc123", + timestamp, + 0, + [], + [],[]) ], [], []) @@ -57,7 +60,8 @@ public void ReportDeployments_WithNoUpdatedApplications_WritesNoServiceMessages( var applicationResults = new List { new("gateway1", - new ApplicationName("app1"), + "gateway1Name", + QualifiedApplicationName.Create("app1", "argocd"), 2, 2, [], @@ -82,15 +86,18 @@ public void ReportDeployments_WithSingleUpdatedApplication_WritesOneServiceMessa var applicationResults = new List { new("gateway1", - new ApplicationName("app1"), + "gateway1Name", + QualifiedApplicationName.Create("app1", "argocd"), 2, 2, [ - new TrackedSourceDetail("abc123", - timestamp, - 0, - [], - []) + new TrackedSourceDetail( + "https://github.com", + "abc123", + timestamp, + 0, + [], + [],[]) ], [], []) @@ -107,7 +114,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\":[]}}]" } }); @@ -124,28 +131,34 @@ public void ReportDeployments_WithMultipleUpdatedApplications_WritesMultipleServ var applicationResults = new List { new("gateway1", - new ApplicationName("app1"), + "gateway1Name", + QualifiedApplicationName.Create("app1", "argocd"), 2, 2, [ - new TrackedSourceDetail("abc123", - timestamp, - 0, - [], - []) + new TrackedSourceDetail( + "https://github.com", + "abc123", + timestamp, + 0, + [], + [],[]) ], [], []), new("gateway2", - new ApplicationName("app2"), + "gateway2Name", + QualifiedApplicationName.Create("app2", "argocd"), 1, 1, [ - new TrackedSourceDetail("def456", - timestamp, - 0, - [], - []) + new TrackedSourceDetail( + "https://github.com", + "def456", + timestamp, + 0, + [], + [],[]) ], [], []) @@ -161,7 +174,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\":[]}}]" } }, @@ -171,7 +184,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\":[]}}]" } } @@ -189,15 +202,17 @@ public void ReportDeployments_WithReplacedFiles_IncludesReplacedFilesInSources() var applicationResults = new List { new("gateway1", - new ApplicationName("app1"), + "gateway1Name", + QualifiedApplicationName.Create("app1", "argocd"), 2, 2, [ - new TrackedSourceDetail("abc123", + new TrackedSourceDetail("https://github.com", + "abc123", timestamp, 0, [new FileHash("values.yaml", "22c0df2cceca5273e4dc569dda52805d27df3360")], - []) + [],[]) ], [], []) @@ -214,7 +229,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\":[]}}]" } }); @@ -231,15 +246,18 @@ public void ReportDeployments_WithPatchedFiles_IncludesPatchedFilesInSources() var applicationResults = new List { new("gateway1", - new ApplicationName("app1"), + "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"}]""")],[]) ], [], []) @@ -256,7 +274,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}}]\"}}]}}]" } }); @@ -273,15 +291,18 @@ public void ReportDeployments_WithBothReplacedAndPatchedFiles_IncludesBothInSour var applicationResults = new List { new("gateway1", - new ApplicationName("app1"), + "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"}]""")],[]) ], [], []) @@ -298,7 +319,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}}]\"}}]}}]" } }); @@ -315,21 +336,24 @@ public void ReportDeployments_WithMultipleReplacedAndPatchedFiles_IncludesAllFil var applicationResults = new List { new("gateway1", - new ApplicationName("app1"), + "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}]""") + ],[]) ], [], []) @@ -346,7 +370,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}}]\"}}]}}]" } }); @@ -363,20 +387,25 @@ public void ReportDeployments_WithMultipleSourcesWithFiles_IncludesAllSourcesInS var applicationResults = new List { new("gateway1", - new ApplicationName("app1"), + "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"}]""")],[]) ], [], []) @@ -393,7 +422,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}}]\"}}]}}]" } }); @@ -410,15 +439,18 @@ public void ReportDeployments_WithOsSpecificReplacedFilePaths_ReportsPosixPaths( var applicationResults = new List { new("gateway1", - new ApplicationName("app1"), + "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")], + [],[]) ], [], []) @@ -435,7 +467,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\":[]}}]" } }); @@ -450,15 +482,18 @@ public void ReportDeployments_WithNoOpSource_EmitsServiceMessageWithNullCommitSh var applicationResults = new List { new("gateway1", - new ApplicationName("app1"), + "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"}]""")],[]) ], [], []) @@ -475,7 +510,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}]"}]}]""" } }); @@ -492,27 +527,32 @@ public void ReportDeployments_WithMixedUpdatedAndNonUpdatedApplications_WritesOn var applicationResults = new List { new("gateway1", - new ApplicationName("app1"), + "gateway1Name", + QualifiedApplicationName.Create("app1", "argocd"), 2, 2, [], [], []), new("gateway2", - new ApplicationName("app2"), + "gateway2Name", + QualifiedApplicationName.Create("app2", "argocd"), 1, 1, [ - new TrackedSourceDetail("abc123", - timestamp, - 0, - [], - []) + new TrackedSourceDetail( + "https://github.com", + "abc123", + timestamp, + 0, + [], + [],[]) ], [], []), new("gateway3", - new ApplicationName("app3"), + "gateway3Name", + QualifiedApplicationName.Create("app3", "argocd"), 1, 1, [], @@ -531,7 +571,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..a16d23384a 100644 --- a/source/Calamari.Tests/ArgoCD/ArgoCDOutputVariablesWriterTests.cs +++ b/source/Calamari.Tests/ArgoCD/ArgoCDOutputVariablesWriterTests.cs @@ -1,7 +1,10 @@ using System; +using System.Collections.Generic; +using System.Linq; 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 +22,9 @@ public class ArgoCDOutputVariablesWriterTests const string GatewayName = "TestGateway"; 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; @@ -43,7 +49,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 +71,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 +100,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 +134,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(); @@ -147,19 +153,238 @@ public void WritePushResultOutput_WithMultipleSources_WritesVariablesWithCorrect AssertPullRequestCreatedServiceMessage(pullRequestCreatedServiceMessages, pushResult2); } + [Test] + public void WriteManifestUpdateOutput_SingleItems_WritesAllOutputVariables() + { + // Arrange + 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(applicationResults); + + // 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 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(applicationResults); + + // 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}, {SecondApplicationName}"); + serviceMessages.GetPropertyValue("ArgoCD.MatchingApplicationTotalSourceCounts").Should().Be("3, 1"); + serviceMessages.GetPropertyValue("ArgoCD.MatchingApplicationMatchingSourceCounts").Should().Be("2, 1"); + 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(applicationResults); + + // 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 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(applicationResults.ToList()); + + // 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 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(applicationResults.ToList()); + + // 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}, {SecondApplicationName}"); + serviceMessages.GetPropertyValue("ArgoCD.MatchingApplicationTotalSourceCounts").Should().Be("4, 2"); + serviceMessages.GetPropertyValue("ArgoCD.MatchingApplicationMatchingSourceCounts").Should().Be("3, 1"); + serviceMessages.GetPropertyValue("ArgoCD.UpdatedApplications").Should().Be($"{QualifiedApplicationName}, {SecondApplicationName}"); + serviceMessages.GetPropertyValue("ArgoCD.UpdatedApplicationSourceCounts").Should().Be("3, 1"); + serviceMessages.GetPropertyValue("ArgoCD.UpdatedImages").Should().Be("4"); + } + + [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(applicationResults.ToList()); + + // 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) { - 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 +396,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..e16d74436d 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 @@ -26,7 +27,7 @@ public ArgoCDOutputVariablesWriter(ILog log) public void WriteSourceUpdateResultOutputWhenPushResultExists( string gatewayName, - string applicationName, + QualifiedApplicationName applicationName, int sourceIndex, SourceUpdateResult sourceUpdateResult) { @@ -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)); @@ -89,62 +90,42 @@ static ServiceMessage CreatePullRequestCreatedServiceMessage(PullRequestPushResu return message; } - public void WriteImageUpdateOutput(IEnumerable gateways, - IEnumerable gitRepos, - IReadOnlyCollection<(ApplicationName ApplicationName, int TotalSourceCount, int MatchingSourceCount)> totalApplicationsWithSourceCounts, - IReadOnlyCollection<(ApplicationName ApplicationName, int SourceCount)> updatedApplicationsWithSourceCounts, - int imagesUpdatedCount) + public void WriteImageUpdateOutput(List applicationResults) { - WriteGatewayIds(gateways); - WriteGitUris(gitRepos); - WriteTotalApplicationsWithSourceCounts(totalApplicationsWithSourceCounts); - WriteUpdatedApplicationsWithSourceCounts(updatedApplicationsWithSourceCounts); - - log.SetOutputVariableButDoNotAddToVariables(SpecialVariables.Git.Output.UpdatedImages, imagesUpdatedCount.ToString()); - } - - public void WriteManifestUpdateOutput(IEnumerable gateways, - IEnumerable gitRepos, - IReadOnlyCollection<(ApplicationName ApplicationName, int TotalSourceCount, int MatchingSourceCount)> totalApplicationsWithSourceCounts, - IReadOnlyCollection<(ApplicationName ApplicationName, int SourceCount)> updatedApplicationsWithSourceCounts) - { - WriteGatewayIds(gateways); - WriteGitUris(gitRepos); - WriteTotalApplicationsWithSourceCounts(totalApplicationsWithSourceCounts); - WriteUpdatedApplicationsWithSourceCounts(updatedApplicationsWithSourceCounts); - } - - void WriteTotalApplicationsWithSourceCounts(IReadOnlyCollection<(ApplicationName 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<(ApplicationName 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); + + 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); + log.SetOutputVariableButDoNotAddToVariables(appSourceVariables.UpdatedImages, ToCommaSeparatedString(sourceDetail.imagesUpdated)); + } + } } - void WriteGatewayIds(IEnumerable gateways) + public void WriteManifestUpdateOutput(IReadOnlyCollection applicationResults) { - var gatewayIds = ToCommaSeparatedString(gateways); - log.SetOutputVariableButDoNotAddToVariables(SpecialVariables.Git.Output.GatewayIds, gatewayIds); + 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); + } + } } static string ToCommaSeparatedString(IEnumerable items) 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..900617113c 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, - applicationName.ToApplicationName(), + 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..5147631c8a 100644 --- a/source/Calamari/ArgoCD/Conventions/UpdateArgoCDAppImagesInstallConvention.cs +++ b/source/Calamari/ArgoCD/Conventions/UpdateArgoCDAppImagesInstallConvention.cs @@ -86,21 +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 - ); + 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 00de914204..c627ce54fa 100644 --- a/source/Calamari/ArgoCD/Conventions/UpdateArgoCDApplicationManifestsInstallConvention.cs +++ b/source/Calamari/ArgoCD/Conventions/UpdateArgoCDApplicationManifestsInstallConvention.cs @@ -94,16 +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 - ); + outputVariablesWriter.WriteManifestUpdateOutput(applicationResults); } IPackageRelativeFile[] GetReferencedPackageFiles(ArgoCommitToGitConfig config) 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..429e21b3a7 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, - applicationName.ToApplicationName(), + 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, 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/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 f185e88f51..08b4136daa 100644 --- a/source/Calamari/ArgoCD/ProcessApplicationResult.cs +++ b/source/Calamari/ArgoCD/ProcessApplicationResult.cs @@ -8,15 +8,18 @@ namespace Calamari.ArgoCD { public record TrackedSourceDetail( + string RepositoryUri, string? CommitSha, DateTimeOffset? CommitTimestamp, int SourceIndex, List ReplacedFiles, - List PatchedFiles); + List PatchedFiles, + HashSet imagesUpdated); public class ProcessApplicationResult( string gatewayId, - ApplicationName applicationName, + string gatewayName, + QualifiedApplicationName applicationName, int totalSourceCount, int matchingSourceCount, List trackedSourceDetails, @@ -24,7 +27,8 @@ public class ProcessApplicationResult( HashSet gitReposUpdated) { public string GatewayId { get; } = gatewayId; - public ApplicationName ApplicationName { get; } = applicationName; + public string GatewayName { get; } = gatewayName; + public QualifiedApplicationName ApplicationName { get; } = applicationName; public int TotalSourceCount { get; } = totalSourceCount; public int MatchingSourceCount { get; } = matchingSourceCount; public List TrackedSourceDetails { get; } = trackedSourceDetails; diff --git a/source/Calamari/Kubernetes/SpecialVariables.cs b/source/Calamari/Kubernetes/SpecialVariables.cs index 78ebf30226..e3d7438266 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 @@ -112,9 +114,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 +128,22 @@ 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"; + + //These are only sent for image tag updates + public string UpdatedImages => $"{qualifiedPrefix}.UpdatedImages"; } } }