Skip to content

Conversation

@joshbwlng
Copy link
Contributor

@joshbwlng joshbwlng commented Oct 2, 2025

Change-type: minor


See: https://balena.fibery.io/Work/Project/Mark-associated-resources-for-deletion-when-a-release-is-deleted-1779

My biggest concern is properly handling a potentially large number of images in the task - analogous to the service install task work.

Note: We can merge this before the delete images endpoint is enabled on the registry as this function is toggled via an env var. Once the delete endpoint is available we can turn this feature on with the env var.

@joshbwlng joshbwlng self-assigned this Oct 2, 2025
@joshbwlng joshbwlng force-pushed the joshbwlng/releases branch 3 times, most recently from 1aed661 to 4b9fde2 Compare October 8, 2025 05:32
@joshbwlng joshbwlng force-pushed the joshbwlng/releases branch 6 times, most recently from 0300ed4 to f3d59f1 Compare October 13, 2025 02:39
@joshbwlng
Copy link
Contributor Author

/rebase

@git-basejump git-basejump bot force-pushed the joshbwlng/releases branch from 385c7a1 to f453f27 Compare October 16, 2025 05:53
Comment on lines +117 to +124
const token = generateToken('admin', REGISTRY2_HOST, [
{
name: repo,
type: 'repository',
actions: ['delete'],
},
]);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We may instead want to generate a wildcard token with delete access to all repos

@joshbwlng joshbwlng requested a review from a team October 22, 2025 03:38
Comment on lines 18 to 35
const schema = {
type: 'object',
properties: {
images: {
type: 'array',
items: {
type: 'array',
items: {
type: 'string',
},
maxItems: 2,
minItems: 2,
},
},
},
required: ['images'],
};
Copy link
Contributor

@otaviojacobi otaviojacobi Oct 22, 2025

Choose a reason for hiding this comment

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

@joshbwlng just for my own information, is there any specific reason you chose this schema instead of

Suggested change
const schema = {
type: 'object',
properties: {
images: {
type: 'array',
items: {
type: 'array',
items: {
type: 'string',
},
maxItems: 2,
minItems: 2,
},
},
},
required: ['images'],
};
const schema = {
type: 'object',
properties: {
images: {
type: 'array',
items: {
type: 'object',
properties: {
repo: { type: 'string' },
hash: { type: 'string' },
},
required: ['repo', 'hash'],
additionalProperties: false,
},
},
},
required: ['images'],
};

where the properties have explicit naming? (slightly easier to read imo)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Having the named keys does make it easier (I had them in my initial source), but decided to drop them in favor of reducing task DB record size - especially since cascade deletions can lead to a very large number of images being processed here.

// Need to make requests one image at a time, no batch endpoint available
for (let retries = 0; retries < RATE_LIMIT_RETRIES; retries++) {
const [{ statusCode, statusMessage, headers }] = await requestAsync({
url: `https://${REGISTRY2_HOST}/v2/${repo}/manifests/${hash}`,
Copy link
Contributor

Choose a reason for hiding this comment

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

Are all repo/hashes we have here guaranteed to belong to our own registry or could these be images on custom customer registry?

Copy link
Contributor Author

@joshbwlng joshbwlng Oct 23, 2025

Choose a reason for hiding this comment

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

Why would they belong on a custom customer registry? Even if it's balenaMachine the value should point to their respective registry service (REGISTRY2_HOST).

If you're asking if the domain is always guaranteed to match the current value of REGISTRY2_HOST, then that's a no. We have images in production/staging in which the domain is registry2.resin.io for example instead of our current registry2.balena-cloud.com value.

Regardless, the idea is to attempt the deletion using the one and only registry our API has access to. If the response from the registry is 404, well then there's nothing else we can do anyway - the manifest we wanted to get rid of is already gone.

@joshbwlng
Copy link
Contributor Author

/rebase

@git-basejump git-basejump bot force-pushed the joshbwlng/releases branch from 8bc3cf7 to 60a9b3e Compare October 25, 2025 06:13
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