Skip to content

Commit b6cb684

Browse files
committed
Light shuffling of response object
1 parent bad97c9 commit b6cb684

File tree

2 files changed

+46
-54
lines changed

2 files changed

+46
-54
lines changed

source/Calamari/ArgoCD/Conventions/UpdateArgoCDAppImagesInstallConvention.cs

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -96,20 +96,13 @@ ProcessApplicationResult ProcessApplication(ArgoCDApplicationDto application,
9696
UpdateArgoCDAppDeploymentConfig deploymentConfig)
9797
{
9898
log.InfoFormat("Processing application {0}", application.Name);
99-
100-
var result = new ProcessApplicationResult(application.Name.ToApplicationName());
101-
10299
var applicationFromYaml = argoCdApplicationManifestParser.ParseManifest(application.Manifest);
103-
100+
var containsMultipleSources = applicationFromYaml.Spec.Sources.Count > 1;
101+
var applicationName = applicationFromYaml.Metadata.Name;
102+
104103
var validationResult = ApplicationValidator.Validate(applicationFromYaml);
105104
validationResult.Action(log);
106105

107-
var containsMultipleSources = applicationFromYaml.Spec.Sources.Count > 1;
108-
109-
result.TotalSourceCount = applicationFromYaml.Spec.Sources.Count;
110-
111-
result.MatchingSourceCount = applicationFromYaml.Spec.Sources.Count(s => deploymentScope.Matches(ScopingAnnotationReader.GetScopeForApplicationSource(s.Name.ToApplicationSourceName(), applicationFromYaml.Metadata.Annotations, containsMultipleSources)));
112-
113106
var updatedSourcesResults = applicationFromYaml.GetSourcesWithMetadata()
114107
.Select(applicationSource => new
115108
{
@@ -122,25 +115,30 @@ ProcessApplicationResult ProcessApplication(ArgoCDApplicationDto application,
122115
deploymentConfig,
123116
application.DefaultRegistry),
124117
applicationSource,
125-
}).Where(r => r.Updated.Any()).ToList();
118+
})
119+
.Where(r => r.Updated.Any())
120+
.ToList();
126121

127-
result.UpdatedSourceCount = updatedSourcesResults.Count;
128-
result.GitReposUpdated.AddRange(updatedSourcesResults.Select(r => r.applicationSource.Source.RepoUrl.AbsoluteUri));
129-
result.UpdatedImages.AddRange(updatedSourcesResults.SelectMany(r => r.Updated));
130122

131123
//if we have links, use that to generate a link, otherwise just put the name there
132124
var instanceLinks = application.InstanceWebUiUrl != null ? new ArgoCDInstanceLinks(application.InstanceWebUiUrl) : null;
133125
var linkifiedAppName = instanceLinks != null
134-
? log.FormatLink(instanceLinks.ApplicationDetails(application.Name, application.KubernetesNamespace), application.Name)
135-
: application.Name;
126+
? log.FormatLink(instanceLinks.ApplicationDetails(applicationName, application.KubernetesNamespace), applicationName)
127+
: applicationName;
136128

137129
var message = updatedSourcesResults.Any()
138130
? "Updated Application {0}"
139131
: "Nothing to update for Application {0}";
140132

141133
log.InfoFormat(message, linkifiedAppName);
142134

143-
return result;
135+
return new ProcessApplicationResult(applicationName.ToApplicationName())
136+
{
137+
TotalSourceCount = applicationFromYaml.Spec.Sources.Count,
138+
MatchingSourceCount = applicationFromYaml.Spec.Sources.Count(s => deploymentScope.Matches(ScopingAnnotationReader.GetScopeForApplicationSource(s.Name.ToApplicationSourceName(), applicationFromYaml.Metadata.Annotations, containsMultipleSources))),
139+
GitReposUpdated = updatedSourcesResults.Select(r => r.applicationSource.Source.RepoUrl.AbsoluteUri).ToHashSet(),
140+
UpdatedImages = updatedSourcesResults.SelectMany(r => r.Updated).ToHashSet()
141+
};
144142
}
145143

146144
/// <returns>Images that were updated</returns>
@@ -468,6 +466,7 @@ RepositoryWrapper CreateRepository(Dictionary<string, GitCredentialDto> gitCrede
468466
return Update(rootPath, imagesToUpdate, filesToUpdate, imageReplacerFactory);
469467
}
470468

469+
471470
(HashSet<string>, HashSet<string>) UpdateKustomizeYaml(string rootPath,
472471
string subFolder,
473472
string defaultRegistry,
@@ -594,11 +593,11 @@ public ProcessApplicationResult(ApplicationName applicationName)
594593

595594
public int TotalSourceCount { get; set; }
596595
public int MatchingSourceCount { get; set; }
597-
public int UpdatedSourceCount { get; set; }
598-
public HashSet<string> GitReposUpdated { get; } = new HashSet<string>();
596+
public HashSet<string> GitReposUpdated { get; set; } = new HashSet<string>();
599597
public ApplicationName ApplicationName { get; }
600-
public HashSet<string> UpdatedImages { get; } = new HashSet<string>();
598+
public HashSet<string> UpdatedImages { get; set; } = new HashSet<string>();
601599

600+
public int UpdatedSourceCount => GitReposUpdated.Count;
602601
public bool Updated => UpdatedSourceCount > 0;
603602
}
604603
}

source/Calamari/ArgoCD/Conventions/UpdateArgoCDApplicationManifestsInstallConvention.cs

Lines changed: 27 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -98,60 +98,53 @@ ProcessApplicationResult ProcessApplication(ArgoCDApplicationDto application,
9898
IPackageRelativeFile[] packageFiles)
9999
{
100100
log.InfoFormat("Processing application {0}", application.Name);
101-
102-
ProcessApplicationResult result = new ProcessApplicationResult(application.Name.ToApplicationName());
103-
104101
var applicationFromYaml = argoCdApplicationManifestParser.ParseManifest(application.Manifest);
105102
var containsMultipleSources = applicationFromYaml.Spec.Sources.Count > 1;
106103
var applicationName = applicationFromYaml.Metadata.Name;
107104

108-
109-
result.TotalSourceCount = applicationFromYaml.Spec.Sources.Count;
110-
result.MatchingSourceCount = applicationFromYaml.Spec.Sources.Count(s => deploymentScope.Matches(ScopingAnnotationReader.GetScopeForApplicationSource(s.Name.ToApplicationSourceName(), applicationFromYaml.Metadata.Annotations, containsMultipleSources)));
111105
LogWarningIfUpdatingMultipleSources(applicationFromYaml.Spec.Sources,
112106
applicationFromYaml.Metadata.Annotations,
113107
containsMultipleSources,
114108
deploymentScope);
115-
116109
var validationResult = ApplicationValidator.Validate(applicationFromYaml);
117110
validationResult.Action(log);
118111

119-
var sourceResults = applicationFromYaml
120-
.GetSourcesWithMetadata()
121-
.Select(sourceWithMetadata => new
122-
{
123-
Updated = ProcessSource(deploymentScope,
124-
gitCredentials,
125-
repositoryFactory,
126-
deploymentConfig,
127-
packageFiles,
128-
sourceWithMetadata,
129-
applicationFromYaml,
130-
containsMultipleSources,
131-
applicationName),
132-
sourceWithMetadata
133-
})
134-
.Where(u => u.Updated)
135-
.Select(u => u.sourceWithMetadata.Source.RepoUrl.AbsoluteUri)
136-
.ToList();
137-
138-
var didUpdateSomething = sourceResults.Any();
139-
result.UpdatedSourceCount = sourceResults.Count();
140-
result.GitReposUpdated.AddRange(sourceResults.Select(r => r));
141-
112+
var updatedSourcesResults = applicationFromYaml
113+
.GetSourcesWithMetadata()
114+
.Select(applicationSource => new
115+
{
116+
Updated = ProcessSource(deploymentScope,
117+
gitCredentials,
118+
repositoryFactory,
119+
deploymentConfig,
120+
packageFiles,
121+
applicationSource,
122+
applicationFromYaml,
123+
containsMultipleSources,
124+
applicationName),
125+
applicationSource
126+
})
127+
.Where(u => u.Updated)
128+
.ToList();
129+
142130
//if we have links, use that to generate a link, otherwise just put the name there
143131
var instanceLinks = application.InstanceWebUiUrl != null ? new ArgoCDInstanceLinks(application.InstanceWebUiUrl) : null;
144132
var linkifiedAppName = instanceLinks != null
145133
? log.FormatLink(instanceLinks.ApplicationDetails(applicationName, applicationFromYaml.Metadata.Namespace), applicationName)
146134
: applicationName;
147135

148-
var message = didUpdateSomething
136+
var message = updatedSourcesResults.Any()
149137
? "Updated Application {0}"
150138
: "Nothing to update for Application {0}";
151139

152140
log.InfoFormat(message, linkifiedAppName);
153141

154-
return result;
142+
return new ProcessApplicationResult(applicationName.ToApplicationName())
143+
{
144+
TotalSourceCount = applicationFromYaml.Spec.Sources.Count,
145+
MatchingSourceCount = applicationFromYaml.Spec.Sources.Count(s => deploymentScope.Matches(ScopingAnnotationReader.GetScopeForApplicationSource(s.Name.ToApplicationSourceName(), applicationFromYaml.Metadata.Annotations, containsMultipleSources))),
146+
GitReposUpdated = updatedSourcesResults.Select(r => r.applicationSource.Source.RepoUrl.AbsoluteUri).ToHashSet(),
147+
};
155148
}
156149

157150
bool ProcessSource(DeploymentScope deploymentScope,
@@ -303,8 +296,8 @@ public ProcessApplicationResult(ApplicationName applicationName)
303296

304297
public int TotalSourceCount { get; set; }
305298
public int MatchingSourceCount { get; set; }
306-
public int UpdatedSourceCount { get; set; }
307-
public HashSet<string> GitReposUpdated { get; } = new HashSet<string>();
299+
public int UpdatedSourceCount => GitReposUpdated.Count;
300+
public HashSet<string> GitReposUpdated { get; set; } = new HashSet<string>();
308301
public ApplicationName ApplicationName { get; }
309302
}
310303
}

0 commit comments

Comments
 (0)