-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
closes: #1767
- Loading branch information
Showing
12 changed files
with
174 additions
and
6 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 @@ | ||
The Manifest model has been enhanced with a new `architecture` field, | ||
which specifies the CPU architecture for which the binaries in the image are designed to run. |
73 changes: 73 additions & 0 deletions
73
pulp_container/app/management/commands/container-repair-manifest-metadatas.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,73 @@ | ||
import json | ||
from json.decoder import JSONDecodeError | ||
|
||
from gettext import gettext as _ | ||
|
||
from contextlib import suppress | ||
|
||
from django.conf import settings | ||
from django.core.exceptions import ObjectDoesNotExist | ||
from django.core.management import BaseCommand | ||
|
||
from pulpcore.plugin.cache import SyncContentCache | ||
|
||
from pulp_container.app.models import ContainerDistribution, Manifest | ||
|
||
|
||
class Command(BaseCommand): | ||
""" | ||
A management command to handle the initialization of empty architecture fields for | ||
container images. | ||
This command retrieves a list of manifests that have a null architecture field and | ||
populates them with the appropriate architecture definitions sourced from the corresponding | ||
ConfigBlob. | ||
""" | ||
|
||
help = _(__doc__) | ||
|
||
def handle(self, *args, **options): | ||
manifests_updated_count = 0 | ||
|
||
manifests_v1 = Manifest.objects.filter(architecture__isnull=True) | ||
manifests_updated_count += self.update_manifests(manifests_v1) | ||
|
||
self.stdout.write( | ||
self.style.SUCCESS("Successfully updated %d manifests." % manifests_updated_count) | ||
) | ||
|
||
if settings.CACHE_ENABLED and manifests_updated_count != 0: | ||
base_paths = ContainerDistribution.objects.values_list("base_path", flat=True) | ||
if base_paths: | ||
SyncContentCache().delete(base_key=base_paths) | ||
|
||
self.stdout.write(self.style.SUCCESS("Successfully flushed the cache.")) | ||
|
||
def update_manifests(self, manifests_qs): | ||
manifests_updated_count = 0 | ||
manifests_to_update = [] | ||
for manifest in manifests_qs.iterator(): | ||
# suppress non-existing/already migrated artifacts and corrupted JSON files | ||
with suppress(ObjectDoesNotExist, JSONDecodeError): | ||
manifest_data = json.loads(manifest.data) | ||
manifest.init_metadata(manifest_data) | ||
manifests_to_update.append(manifest) | ||
|
||
if len(manifests_to_update) > 1000: | ||
fields_to_update = ["architecture"] | ||
manifests_qs.model.objects.bulk_update( | ||
manifests_to_update, | ||
fields_to_update, | ||
) | ||
manifests_updated_count += len(manifests_to_update) | ||
manifests_to_update.clear() | ||
|
||
if manifests_to_update: | ||
fields_to_update = ["architecture"] | ||
manifests_qs.model.objects.bulk_update( | ||
manifests_to_update, | ||
fields_to_update, | ||
) | ||
manifests_updated_count += len(manifests_to_update) | ||
|
||
return manifests_updated_count |
18 changes: 18 additions & 0 deletions
18
pulp_container/app/migrations/0042_add_manifest_architecture.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,18 @@ | ||
# Generated by Django 4.2.16 on 2024-09-20 17:22 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('container', '0041_add_pull_through_pull_permissions'), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name='manifest', | ||
name='architecture', | ||
field=models.TextField(null=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
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
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