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

fix: push an empty index when deleting the last referrer with SkipReferrersGC #593

Merged
merged 9 commits into from
Sep 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 22 additions & 17 deletions registry/remote/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -1425,26 +1425,25 @@ func (s *manifestStore) indexReferrersForPush(ctx context.Context, desc ocispec.
func (s *manifestStore) updateReferrersIndex(ctx context.Context, subject ocispec.Descriptor, change referrerChange) (err error) {
referrersTag := buildReferrersTag(subject)

skipDelete := s.repo.SkipReferrersGC
var oldIndexDesc ocispec.Descriptor
var referrers []ocispec.Descriptor
var oldIndexDesc *ocispec.Descriptor
var oldReferrers []ocispec.Descriptor
prepare := func() error {
// 1. pull the original referrers list using the referrers tag schema
var err error
oldIndexDesc, referrers, err = s.repo.referrersFromIndex(ctx, referrersTag)
indexDesc, referrers, err := s.repo.referrersFromIndex(ctx, referrersTag)
if err != nil {
if errors.Is(err, errdef.ErrNotFound) {
// no old index found, skip delete
skipDelete = true
// valid case: no old referrers index
return nil
}
return err
}
oldIndexDesc = &indexDesc
oldReferrers = referrers
return nil
}
update := func(referrerChanges []referrerChange) error {
// 2. apply the referrer changes on the referrers list
updatedReferrers, err := applyReferrerChanges(referrers, referrerChanges)
updatedReferrers, err := applyReferrerChanges(oldReferrers, referrerChanges)
if err != nil {
if err == errNoReferrerUpdate {
return nil
Expand All @@ -1453,7 +1452,12 @@ func (s *manifestStore) updateReferrersIndex(ctx context.Context, subject ocispe
}

// 3. push the updated referrers list using referrers tag schema
if len(updatedReferrers) > 0 {
if len(updatedReferrers) > 0 || s.repo.SkipReferrersGC {
// push a new index in either case:
// 1. the referrers list has been updated with a non-zero size
// 2. OR the updated referrers list is empty but referrers GC
// is skipped, in this case an empty index should still be pushed
// as the old index won't get deleted
newIndexDesc, newIndex, err := generateIndex(updatedReferrers)
if err != nil {
return fmt.Errorf("failed to generate referrers index for referrers tag %s: %w", referrersTag, err)
Expand All @@ -1463,14 +1467,15 @@ func (s *manifestStore) updateReferrersIndex(ctx context.Context, subject ocispe
}
}

// 4. delete the dangling original referrers index
if !skipDelete {
if err := s.repo.delete(ctx, oldIndexDesc, true); err != nil {
return &ReferrersError{
Op: opDeleteReferrersIndex,
Err: fmt.Errorf("failed to delete dangling referrers index %s for referrers tag %s: %w", oldIndexDesc.Digest.String(), referrersTag, err),
Subject: subject,
}
// 4. delete the dangling original referrers index, if applicable
if s.repo.SkipReferrersGC || oldIndexDesc == nil {
return nil
}
if err := s.repo.delete(ctx, *oldIndexDesc, true); err != nil {
return &ReferrersError{
Op: opDeleteReferrersIndex,
Err: fmt.Errorf("failed to delete dangling referrers index %s for referrers tag %s: %w", oldIndexDesc.Digest.String(), referrersTag, err),
Subject: subject,
}
}
return nil
Expand Down
Loading
Loading