Skip to content

Commit

Permalink
gc: fix fk constraint violation tag delete (PROJQUAY-8006) (quay#3271)
Browse files Browse the repository at this point in the history
* gc: fix fk constraint violation tag delete (PROJQUAY-8006)

* revert fix and call delete tag notifications

* add test
  • Loading branch information
Sunandadadi authored Oct 2, 2024
1 parent ec61139 commit d28d2b0
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
2 changes: 2 additions & 0 deletions data/model/gc.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
db_for_update,
)
from data.model import _basequery, blob, config, db_transaction, storage
from data.model.notification import delete_tag_notifications_for_tag
from data.model.oci import tag as oci_tag
from data.model.quota import QuotaOperation, update_quota
from data.secscan_model import secscan_model
Expand Down Expand Up @@ -315,6 +316,7 @@ def _purge_oci_tag(tag, context, allow_non_expired=False):
return False

# Delete the tag.
delete_tag_notifications_for_tag(tag)
tag.delete_instance()

gc_table_rows_deleted.labels(table="Tag").inc()
Expand Down
33 changes: 33 additions & 0 deletions data/model/test/test_gc.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,22 @@
from data import database, model
from data.database import (
ApprBlob,
ExternalNotificationMethod,
ImageStorage,
ImageStorageLocation,
Label,
Manifest,
ManifestBlob,
ManifestLabel,
Tag,
TagNotificationSuccess,
UploadedBlob,
)
from data.model.oci.test.test_oci_manifest import create_manifest_for_testing
from data.registry_model import registry_model
from data.registry_model.datatypes import RepositoryReference
from digest.digest_tools import sha256_digest
from endpoints.api.repositorynotification_models_pre_oci import pre_oci_model
from image.docker.schema1 import DockerSchema1ManifestBuilder
from image.oci.config import OCIConfig
from image.oci.manifest import OCIManifestBuilder
Expand Down Expand Up @@ -703,3 +706,33 @@ def generate_random_data_for_layer():
# These are kept alive with a "non-temporary" hidden tag.
# In order to clean these up, they need to be manually deleted for now.
assert model.gc._check_manifest_used(manifest2_created.manifest.id)


def test_tag_cleanup_with_autoprune_policy(default_tag_policy, initialized_db):
repo1 = model.repository.create_repository("devtable", "newrepo", None)
slack = ExternalNotificationMethod.get(ExternalNotificationMethod.name == "slack")
notification = pre_oci_model.create_repo_notification(
namespace_name="devtable",
repository_name="newrepo",
event_name="repo_image_expiry",
method_name=slack.name,
method_config={"url": "http://example.com"},
event_config={"days": 5},
title="Image(s) will expire in 5 days",
)
notification = model.notification.get_repo_notification(notification.uuid)
manifest1, built1 = create_manifest_for_testing(
repo1, differentiation_field="1", include_shared_blob=True
)
model.oci.tag.retarget_tag("tag1", manifest1)
tag = Tag.select().where(Tag.name == "tag1", Tag.manifest == manifest1.id).get()

TagNotificationSuccess.create(notification=notification.id, tag=tag.id, method=slack.id)

with assert_gc_integrity(expect_storage_removed=True):
delete_tag(repo1, "tag1", expect_gc=True)

tag_notification_count = (
TagNotificationSuccess.select().where(TagNotificationSuccess.tag == tag.id).count()
)
assert tag_notification_count == 0

0 comments on commit d28d2b0

Please sign in to comment.