Skip to content

Remove force annotate option#1364

Merged
mthalman merged 8 commits intodotnet:mainfrom
mthalman:remove-force-annotate
Jul 24, 2024
Merged

Remove force annotate option#1364
mthalman merged 8 commits intodotnet:mainfrom
mthalman:remove-force-annotate

Conversation

@mthalman
Copy link
Member

The annotateEolDigests command provides a --force option that will always create an EOL annotation even if one already exists. This was intended to handle scenarios where we essentially want to overwrite an incorrectly defined annotation. However, this causes multiple such annotations to exist in the registry. We don't want obsolete annotations to continue to be around.

The correct thing to do here is to delete the existing annotation before pushing the new one. But it's not as simple as just applying those operations to the manifests in the ACR. That gets applied to the ACR, but the deletion does not propagate to MAR. So if you did that, you'd effectively still be left with multiple annotations in MAR. Deletions in MAR need to be done through a separate workflow that is not automated.

So there isn't a way to fully automate this scenario. For that reason, the command is being modified here to do away with the --force option entirely. In addition, it will report on image digests which have existing annotations. There is logic to check whether the existing annotation already matches the EOL date to be set. If so, it simply skips the annotation. If it differs, it will be skipped but logged as an error as it will need to be addressed through the manual steps described above.

@mthalman mthalman requested a review from a team as a code owner July 18, 2024 19:29
Comment on lines 48 to 49
Parallel.ForEach(eolAnnotations.EolDigests, digestData =>
{
Copy link
Member

Choose a reason for hiding this comment

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

You can use expression body without the curly braces here.

if (!eolDigests.IsEmpty)
{
_loggerService.WriteMessage(message);
_loggerService.WriteMessage("");
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
_loggerService.WriteMessage("");
_loggerService.WriteMessage();

_loggerService.WriteMessage("");
_loggerService.WriteMessage(JsonConvert.SerializeObject(new EolAnnotationsData(eolDigests: [.. _failedAnnotations])));
_loggerService.WriteMessage(JsonConvert.SerializeObject(new EolAnnotationsData(eolDigests: [.. eolDigests])));
_loggerService.WriteMessage("");
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
_loggerService.WriteMessage("");
_loggerService.WriteMessage();

public interface IOrasService
{
bool IsDigestAnnotatedForEol(string digest, ILoggerService loggerService, bool isDryRun);
bool IsDigestAnnotatedForEol(string digest, ILoggerService loggerService, bool isDryRun, [MaybeNullWhen(false)] out OciManifest lifecycleArtifactManifest);
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
bool IsDigestAnnotatedForEol(string digest, ILoggerService loggerService, bool isDryRun, [MaybeNullWhen(false)] out OciManifest lifecycleArtifactManifest);
bool IsDigestAnnotatedForEol(string digest, ILoggerService loggerService, bool isDryRun, [NotNullWhen(true)] out OciManifest? lifecycleArtifactManifest);

Copy link
Member Author

Choose a reason for hiding this comment

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

This is correct as it is. It's modeled after the Dictionary.TryGetValue method.

@mthalman mthalman requested a review from lbussell July 23, 2024 19:48
Copy link
Member

@lbussell lbussell left a comment

Choose a reason for hiding this comment

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

Just a couple of nits

private readonly ConcurrentBag<string> _existingAnnotationDigests = [];

private ConcurrentBag<EolDigestData> _failedAnnotations = new ();
private static readonly JsonSerializerOptions _jsonSerializerOptions = new()
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
private static readonly JsonSerializerOptions _jsonSerializerOptions = new()
private static readonly JsonSerializerOptions s_jsonSerializerOptions = new()

Comment on lines 9 to 13
internal class BulkDeletionDescription
{
public string RegistryType { get; set; } = "public";
public List<string> Digests { get; set;} = [];
}
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
internal class BulkDeletionDescription
{
public string RegistryType { get; set; } = "public";
public List<string> Digests { get; set;} = [];
}
internal record BulkDeletionDescription
{
public string RegistryType { get; init; } = "public";
public List<string> Digests { get; init; } = [];
}

@mthalman mthalman requested a review from lbussell July 24, 2024 12:56
@mthalman mthalman enabled auto-merge (squash) July 24, 2024 13:59
@mthalman mthalman merged commit 82e0377 into dotnet:main Jul 24, 2024
@mthalman mthalman deleted the remove-force-annotate branch July 24, 2024 14:11
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