Skip to content

Refactor Template Step to use App and AppSource Updates#1829

Merged
rain-on merged 57 commits intomainfrom
tmm/refactor_other_step
Mar 19, 2026
Merged

Refactor Template Step to use App and AppSource Updates#1829
rain-on merged 57 commits intomainfrom
tmm/refactor_other_step

Conversation

@rain-on
Copy link
Contributor

@rain-on rain-on commented Mar 12, 2026

This splits up the UpdateArgoCDApplicationManifestsInstallConvention into 2 extra classes:

  • UpdateArgoCDApplicationManifestsInstallConvention
    • Responsible for parsing in put data, and spawning the applicationUpdater
  • ApplicationUpdater
    • Validating application content, and triggering the update of each internal source
  • ApplicationSourceUpdater
    • Create repository
    • Copy templates files into repository
    • Purge files if necessary
    • Raise output variables

This should be reviewed when prior refactoring is merged (is built atop).

⚠️ Does this change require a corresponding Server Change?
⚠️ If so - please add a "Requires Server Change" label to this PR!


public void StageFiles(string[] filesToStage)
public void UnstageFiles(string[] filesToRemove)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggest we rename StageFiles/UnstageFiles to AddFiles/RemoveFiles

Unstage means you have local changes but you are excluding them from the commit

Image

namespace Calamari.ArgoCD.Conventions.UpdateImageTag;

public record FileUpdateResult(HashSet<string> UpdatedImages, List<FilePathContent> PatchedFileContent); No newline at end of file
public record FileUpdateResult(bool hasChanges, HashSet<string> UpdatedImages, List<FilePathContent> PatchedFileContent, string[]? FilesRemoved = null); No newline at end of file
Copy link
Contributor

Choose a reason for hiding this comment

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

The HasChanges flag should be computed right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

🤔 Prior to this, if there were UpdatedImages - then we determined that a change was made and should be commited.
Except that doesn't work for templating step (which will never results in changed images) - but maybe we could just say "if either of the files-changed list is non-empty)... which would make this much cleaner.

namespace Calamari.ArgoCD.Conventions.UpdateImageTag;

public record FileUpdateResult(HashSet<string> UpdatedImages, List<FilePathContent> PatchedFileContent); No newline at end of file
public record FileUpdateResult(bool hasChanges, HashSet<string> UpdatedImages, List<FilePathContent> PatchedFileContent, string[]? FilesRemoved = null); No newline at end of file
Copy link
Contributor

Choose a reason for hiding this comment

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

Also should we be sharing FileUpdateResult ? UpdatedImages will never be populated for the manifest step etc.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It was really useful to find a common type so that we could use for both steps :/ Maybe I can find a nicer solution 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So turns out - the UpdatedImages ends up in Octopus, to be added to an event in AMplitude - and defaults to "0" if the UpdatedImages Variable is not populated.

Copy link
Contributor

@flin-8 flin-8 left a comment

Choose a reason for hiding this comment

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

LGTM

log.Info($"Removing files recursively from {outputDirectory}");
//TODO(tmm): Knowing we're in a git repository is a bit of a smell :(
var gitDir = Path.Combine(cleansedSubPath, ".git");
// var gitDir = Path.Combine(cleansedSubPath, ".git");
Copy link
Contributor

Choose a reason for hiding this comment

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

Commented code

Copy link
Contributor Author

Choose a reason for hiding this comment

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

cleanedup

namespace Calamari.ArgoCD.Conventions.UpdateImageTag;

public record FileUpdateResult(bool hasChanges, HashSet<string> UpdatedImages, List<FilePathContent> PatchedFileContent, string[]? FilesRemoved = null); No newline at end of file
public record FileUpdateResult(HashSet<string> UpdatedImages, List<FilePathContent> PatchedFileContent, string[]? FilesRemoved = null)
Copy link
Contributor

Choose a reason for hiding this comment

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

Might as well make FilesRemoved non-nullable

Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe create static factory methods to aid creating this record for image-tag vs. manifest use

Copy link
Contributor Author

Choose a reason for hiding this comment

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

going to avoid the factory method for now - being explicit in the "no files removed" is not a bad thin to have.
The field was nullable to minimise the files changed - but its probably sensible to make it explicit.

{
var fileTreeEntry = repo.Branches[branchName.Value].Tip[filename];
//filename will always be posix-compliant
var fileTreeEntry = repo.Branches[branchName.Value].Tip[filename.Replace(Path.DirectorySeparatorChar, '/')];
Copy link
Contributor

Choose a reason for hiding this comment

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

Do you know if this filename also needs to be stripped of the leading "./"?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think, the way we're using it in the tests - the answer is "no" - but that's luck.
The reason we have a problem in production code is when the argo app's path is "./" :(

@rain-on rain-on merged commit c8522f8 into main Mar 19, 2026
33 checks passed
@rain-on rain-on deleted the tmm/refactor_other_step branch March 19, 2026 02:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants