Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -96,20 +96,13 @@ ProcessApplicationResult ProcessApplication(ArgoCDApplicationDto application,
UpdateArgoCDAppDeploymentConfig deploymentConfig)
{
log.InfoFormat("Processing application {0}", application.Name);

var result = new ProcessApplicationResult(application.Name.ToApplicationName());

var applicationFromYaml = argoCdApplicationManifestParser.ParseManifest(application.Manifest);

var containsMultipleSources = applicationFromYaml.Spec.Sources.Count > 1;
var applicationName = applicationFromYaml.Metadata.Name;

var validationResult = ApplicationValidator.Validate(applicationFromYaml);
validationResult.Action(log);

var containsMultipleSources = applicationFromYaml.Spec.Sources.Count > 1;

result.TotalSourceCount = applicationFromYaml.Spec.Sources.Count;

result.MatchingSourceCount = applicationFromYaml.Spec.Sources.Count(s => deploymentScope.Matches(ScopingAnnotationReader.GetScopeForApplicationSource(s.Name.ToApplicationSourceName(), applicationFromYaml.Metadata.Annotations, containsMultipleSources)));

var updatedSourcesResults = applicationFromYaml.GetSourcesWithMetadata()
.Select(applicationSource => new
{
Expand All @@ -122,25 +115,31 @@ ProcessApplicationResult ProcessApplication(ArgoCDApplicationDto application,
deploymentConfig,
application.DefaultRegistry),
applicationSource,
}).Where(r => r.Updated.Any()).ToList();
})
.Where(r => r.Updated.Any())
.ToList();

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

//if we have links, use that to generate a link, otherwise just put the name there
var instanceLinks = application.InstanceWebUiUrl != null ? new ArgoCDInstanceLinks(application.InstanceWebUiUrl) : null;
var linkifiedAppName = instanceLinks != null
? log.FormatLink(instanceLinks.ApplicationDetails(application.Name, application.KubernetesNamespace), application.Name)
: application.Name;
? log.FormatLink(instanceLinks.ApplicationDetails(applicationName, application.KubernetesNamespace), applicationName)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was just updated to be similar to the manifest convention. Im hoping to consolidate some of this shared logic later

: applicationName;

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

log.InfoFormat(message, linkifiedAppName);

return result;
return new ProcessApplicationResult(applicationName.ToApplicationName())
{
UpdatedSourceCount = updatedSourcesResults.Count,
TotalSourceCount = applicationFromYaml.Spec.Sources.Count,
MatchingSourceCount = applicationFromYaml.Spec.Sources.Count(s => deploymentScope.Matches(ScopingAnnotationReader.GetScopeForApplicationSource(s.Name.ToApplicationSourceName(), applicationFromYaml.Metadata.Annotations, containsMultipleSources))),
GitReposUpdated = updatedSourcesResults.Select(r => r.applicationSource.Source.RepoUrl.AbsoluteUri).ToHashSet(),
UpdatedImages = updatedSourcesResults.SelectMany(r => r.Updated).ToHashSet()
};
}

/// <returns>Images that were updated</returns>
Expand Down Expand Up @@ -468,6 +467,7 @@ RepositoryWrapper CreateRepository(Dictionary<string, GitCredentialDto> gitCrede
return Update(rootPath, imagesToUpdate, filesToUpdate, imageReplacerFactory);
}


(HashSet<string>, HashSet<string>) UpdateKustomizeYaml(string rootPath,
string subFolder,
string defaultRegistry,
Expand Down Expand Up @@ -594,11 +594,11 @@ public ProcessApplicationResult(ApplicationName applicationName)

public int TotalSourceCount { get; set; }
public int MatchingSourceCount { get; set; }
public int UpdatedSourceCount { get; set; }
public HashSet<string> GitReposUpdated { get; } = new HashSet<string>();
public HashSet<string> GitReposUpdated { get; set; } = new HashSet<string>();
public ApplicationName ApplicationName { get; }
public HashSet<string> UpdatedImages { get; } = new HashSet<string>();
public HashSet<string> UpdatedImages { get; set; } = new HashSet<string>();

public int UpdatedSourceCount { get; set; }
public bool Updated => UpdatedSourceCount > 0;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,60 +98,54 @@ ProcessApplicationResult ProcessApplication(ArgoCDApplicationDto application,
IPackageRelativeFile[] packageFiles)
{
log.InfoFormat("Processing application {0}", application.Name);

ProcessApplicationResult result = new ProcessApplicationResult(application.Name.ToApplicationName());

var applicationFromYaml = argoCdApplicationManifestParser.ParseManifest(application.Manifest);
var containsMultipleSources = applicationFromYaml.Spec.Sources.Count > 1;
var applicationName = applicationFromYaml.Metadata.Name;


result.TotalSourceCount = applicationFromYaml.Spec.Sources.Count;
result.MatchingSourceCount = applicationFromYaml.Spec.Sources.Count(s => deploymentScope.Matches(ScopingAnnotationReader.GetScopeForApplicationSource(s.Name.ToApplicationSourceName(), applicationFromYaml.Metadata.Annotations, containsMultipleSources)));
LogWarningIfUpdatingMultipleSources(applicationFromYaml.Spec.Sources,
applicationFromYaml.Metadata.Annotations,
containsMultipleSources,
deploymentScope);

var validationResult = ApplicationValidator.Validate(applicationFromYaml);
validationResult.Action(log);

var sourceResults = applicationFromYaml
.GetSourcesWithMetadata()
.Select(sourceWithMetadata => new
{
Updated = ProcessSource(deploymentScope,
gitCredentials,
repositoryFactory,
deploymentConfig,
packageFiles,
sourceWithMetadata,
applicationFromYaml,
containsMultipleSources,
applicationName),
sourceWithMetadata
})
.Where(u => u.Updated)
.Select(u => u.sourceWithMetadata.Source.RepoUrl.AbsoluteUri)
.ToList();

var didUpdateSomething = sourceResults.Any();
result.UpdatedSourceCount = sourceResults.Count();
result.GitReposUpdated.AddRange(sourceResults.Select(r => r));

var updatedSourcesResults = applicationFromYaml
.GetSourcesWithMetadata()
.Select(applicationSource => new
{
Updated = ProcessSource(deploymentScope,
gitCredentials,
repositoryFactory,
deploymentConfig,
packageFiles,
applicationSource,
applicationFromYaml,
containsMultipleSources,
applicationName),
applicationSource
})
.Where(u => u.Updated)
.ToList();

//if we have links, use that to generate a link, otherwise just put the name there
var instanceLinks = application.InstanceWebUiUrl != null ? new ArgoCDInstanceLinks(application.InstanceWebUiUrl) : null;
var linkifiedAppName = instanceLinks != null
? log.FormatLink(instanceLinks.ApplicationDetails(applicationName, applicationFromYaml.Metadata.Namespace), applicationName)
: applicationName;

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

log.InfoFormat(message, linkifiedAppName);

return result;
return new ProcessApplicationResult(applicationName.ToApplicationName())
{
TotalSourceCount = applicationFromYaml.Spec.Sources.Count,
MatchingSourceCount = applicationFromYaml.Spec.Sources.Count(s => deploymentScope.Matches(ScopingAnnotationReader.GetScopeForApplicationSource(s.Name.ToApplicationSourceName(), applicationFromYaml.Metadata.Annotations, containsMultipleSources))),
GitReposUpdated = updatedSourcesResults.Select(r => r.applicationSource.Source.RepoUrl.AbsoluteUri).ToHashSet(),
UpdatedSourceCount = updatedSourcesResults.Count,
};
}

bool ProcessSource(DeploymentScope deploymentScope,
Expand Down Expand Up @@ -304,7 +298,7 @@ public ProcessApplicationResult(ApplicationName applicationName)
public int TotalSourceCount { get; set; }
public int MatchingSourceCount { get; set; }
public int UpdatedSourceCount { get; set; }
public HashSet<string> GitReposUpdated { get; } = new HashSet<string>();
public HashSet<string> GitReposUpdated { get; set; } = new HashSet<string>();
public ApplicationName ApplicationName { get; }
}
}
Expand Down