update hauler store remove to handle registry reference as part of string (#705)

This commit is contained in:
Camryn Carter
2026-07-31 19:58:31 -04:00
committed by GitHub
parent 744f1b1b8d
commit e3764e8378
2 changed files with 40 additions and 1 deletions
+6 -1
View File
@@ -91,7 +91,12 @@ func RemoveCmd(ctx context.Context, o *flags.RemoveOpts, s *store.Layout, ref st
var matches []match
if err := s.Walk(func(reference string, desc ocispec.Descriptor) error {
if !strings.Contains(reference, ref) {
registryRef := desc.Annotations[consts.ContainerdImageNameKey]
if registryRef == "" {
registryRef = desc.Annotations[ocispec.AnnotationRefName]
}
if !strings.Contains(reference, ref) && !strings.Contains(registryRef, ref) {
return nil
}
+34
View File
@@ -125,6 +125,40 @@ func TestRemoveCmd_NotFound(t *testing.T) {
}
}
// TestRemoveCmd_ContainerdImageName confirms that a
// registry-prefixed ref (which only appears in the io.containerd.image.name
// annotation, not the registry-stripped org.opencontainers.image.ref.name
// used to key the store's nameMap) still matches for removal.
func TestRemoveCmd_ContainerdImageName(t *testing.T) {
ctx := newTestContext(t)
s := newTestStore(t)
host, rOpts := newLocalhostRegistry(t)
seedImage(t, host, "test/repo", "v1", rOpts...)
rso := defaultRootOpts(s.Root)
ro := defaultCliOpts()
if err := storeImage(ctx, s, v1.Image{Name: host + "/test/repo:v1"}, "", false, rso, ro, ""); err != nil {
t.Fatalf("storeImage: %v", err)
}
if n := countArtifactsInStore(t, s); n == 0 {
t.Fatal("expected at least 1 artifact after storeImage, got 0")
}
// The registry-qualified ref only lives in io.containerd.image.name;
// org.opencontainers.image.ref.name (and the nameMap key derived from it)
// only holds the registry-stripped short form "test/repo:v1".
fullRef := host + "/test/repo:v1"
if err := RemoveCmd(ctx, &flags.RemoveOpts{Force: true}, s, fullRef, ro, rso); err != nil {
t.Fatalf("RemoveCmd with fully-qualified ref: %v", err)
}
if n := countArtifactsInStore(t, s); n != 0 {
t.Errorf("expected 0 artifacts after removal by containerd image name, got %d", n)
}
}
func TestRemoveCmd_Force_MultipleMatches(t *testing.T) {
ctx := newTestContext(t)
s := newTestStore(t)