Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add cascadeDelete option to the Image and Build objects #1742

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

pbusko
Copy link
Contributor

@pbusko pbusko commented Oct 28, 2024

When cascadeDelete is set to true on a Build object, the produced image by the build will be removed from the registry upon object deletion. If the cascadeDelete is set on the Image object, it will be propagated to Builds

@pbusko pbusko requested a review from a team as a code owner October 28, 2024 15:01
@pbusko pbusko changed the title Add cascadeDelete option to the Image and Build objects Add cascadeDelete option to the Image and Build objects Oct 29, 2024
return err
}

if err := c.RegistryClient.Delete(keychain, build.Status.LatestImage); err != nil {
Copy link

Choose a reason for hiding this comment

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

We would also need to delete all of the additional tags as well.

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 was under the assumption that a Build object produces exactly one image, while Image can produce multiple Build's. If each Build cleans up it's own image, would there be any leftovers? Or the assumption is incorrect?

Copy link
Collaborator

Choose a reason for hiding this comment

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

A build can push multiple images (see additionalTags). There is also the signed images and image attestations but that might be too much to try to delete and we probably don’t want to delete the attestations

Copy link
Contributor

Choose a reason for hiding this comment

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

According to docs, the status.latestImage field contain the image's digest. It should be enough to delete just this (no necessity to delete all tags individually): https://github.com/opencontainers/distribution-spec/blob/main/spec.md#deleting-manifests.

Once deleted, a GET to /v2//manifests/ and any tag pointing to that digest will return a 404.

}

if err := c.RegistryClient.Delete(keychain, build.Status.LatestImage); err != nil {
return err
Copy link
Collaborator

Choose a reason for hiding this comment

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

Returning error might mean that builds get stuck if the finalized can't delete the image due to immutability rules in the registry. I think this should be a best effort cleanup

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Isn't it fair to keep the build if the desired outcome is not reached? The solution is not to enable the cleanup when the registry forbids objects deletion is used. If I set the cleanup to true but the image is still present, it should be considered an error, not a warning message

}

if err := c.RegistryClient.Delete(keychain, build.Status.LatestImage); err != nil {
//logger.Printf(errors.Wrapf(err, "Could not delete image %q", build.Status.LatestImage))

Choose a reason for hiding this comment

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

How should we handle the error in that case? It seems like error logging is not supposed to happen at the reconciliation stage.

Copy link
Collaborator

Choose a reason for hiding this comment

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

You can log and it will print to the controller logs

@codecov-commenter
Copy link

codecov-commenter commented Dec 1, 2024

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

Attention: Patch coverage is 40.32258% with 37 lines in your changes missing coverage. Please review.

Project coverage is 66.97%. Comparing base (49014e2) to head (6ee3a13).
Report is 62 commits behind head on main.

Files with missing lines Patch % Lines
pkg/reconciler/build/build.go 45.28% 24 Missing and 5 partials ⚠️
pkg/registry/client.go 0.00% 6 Missing ⚠️
pkg/apis/build/v1alpha2/build.go 0.00% 2 Missing ⚠️

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1742      +/-   ##
==========================================
- Coverage   67.34%   66.97%   -0.38%     
==========================================
  Files         140      144       +4     
  Lines        8886     9104     +218     
==========================================
+ Hits         5984     6097     +113     
- Misses       2393     2482      +89     
- Partials      509      525      +16     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@modulo11 modulo11 force-pushed the add-image-delete-flag branch from e4f074b to 6ee3a13 Compare December 9, 2024 12:47
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.

7 participants