-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Distinguish between the nature of images
closes #1437
- Loading branch information
Showing
13 changed files
with
306 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
Incorporated a notion of container images' characteristics. Users can now filter manifests by their | ||
nature using the ``is_flatpak`` or ``is_bootable`` field on the corresponding Manifest endpoint. |
61 changes: 61 additions & 0 deletions
61
pulp_container/app/management/commands/init-image-nature.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
from json.decoder import JSONDecodeError | ||
|
||
from gettext import gettext as _ | ||
|
||
from contextlib import suppress | ||
|
||
from django.core.exceptions import ObjectDoesNotExist | ||
from django.core.management import BaseCommand | ||
from django.core.paginator import Paginator | ||
|
||
from pulp_container.app.models import Manifest | ||
|
||
from pulp_container.constants import MEDIA_TYPE | ||
|
||
PAGE_CHUNK_SIZE = 200 | ||
|
||
|
||
class Command(BaseCommand): | ||
""" | ||
A django management command to initialize flags describing the image nature. | ||
Manifests stored inside Pulp are of various natures. The nature of an image can be determined | ||
from JSON-formatted image manifest annotations or image configuration labels. These data are | ||
stored inside artifacts. | ||
This command reads data from the storage backend and populates the 'annotations', 'labels', | ||
'is_bootable', and 'is_flatpak' fields on the Manifest model. | ||
""" | ||
|
||
help = _(__doc__) | ||
|
||
def handle(self, *args, **options): | ||
manifests = Manifest.objects.exclude( | ||
media_type__in=[MEDIA_TYPE.MANIFEST_LIST, MEDIA_TYPE.INDEX_OCI] | ||
).order_by("pulp_id") | ||
self.update_manifests(manifests) | ||
|
||
manifest_lists = Manifest.objects.filter( | ||
media_type__in=[MEDIA_TYPE.MANIFEST_LIST, MEDIA_TYPE.INDEX_OCI] | ||
).order_by("pulp_id") | ||
self.update_manifests(manifest_lists) | ||
|
||
def update_manifests(self, manifests_qs): | ||
paginator = Paginator(manifests_qs, PAGE_CHUNK_SIZE) | ||
for page_num in paginator.page_range: | ||
manifests_to_update = [] | ||
|
||
page = paginator.page(page_num) | ||
for manifest in page.object_list: | ||
# suppress non-existing/already migrated artifacts and corrupted JSON files | ||
with suppress(ObjectDoesNotExist, JSONDecodeError): | ||
has_metadata = manifest.init_metadata() | ||
if has_metadata: | ||
manifests_to_update.append(manifest) | ||
|
||
if manifests_to_update: | ||
fields_to_update = ["annotations", "labels", "is_bootable", "is_flatpak"] | ||
manifests_qs.model.objects.bulk_update( | ||
manifests_to_update, | ||
fields_to_update, | ||
) |
47 changes: 47 additions & 0 deletions
47
pulp_container/app/migrations/0038_add_manifest_metadata_fields.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
# Generated by Django 4.2.10 on 2024-02-29 16:04 | ||
import warnings | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
def print_warning_for_initializing_image_nature(apps, schema_editor): | ||
warnings.warn( | ||
"Manifests containing additional metadata, like image manifest annotations and " | ||
"image configuration labels, need to be updated. Please, run 'pulpcore-manager " | ||
"init-image-nature' to extract and initiliaze the metadata from related artifacts." | ||
) | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('container', '0037_create_pull_through_cache_models'), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name='manifest', | ||
name='annotations', | ||
field=models.JSONField(default=dict), | ||
), | ||
migrations.AddField( | ||
model_name='manifest', | ||
name='is_bootable', | ||
field=models.BooleanField(default=False), | ||
), | ||
migrations.AddField( | ||
model_name='manifest', | ||
name='is_flatpak', | ||
field=models.BooleanField(default=False), | ||
), | ||
migrations.AddField( | ||
model_name='manifest', | ||
name='labels', | ||
field=models.JSONField(default=dict), | ||
), | ||
migrations.RunPython( | ||
code=print_warning_for_initializing_image_nature, | ||
reverse_code=migrations.RunPython.noop, | ||
elidable=True, | ||
) | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.