Skip to content

Commit

Permalink
Keep the "library" namespace if it was specified in the image identif…
Browse files Browse the repository at this point in the history
…ier.

Fixes argoproj-labs#1012.

Signed-off-by: Alessandro Zanatta <[email protected]>
  • Loading branch information
AlessandroZanatta committed Jan 17, 2025
1 parent 9affc21 commit 34807d2
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion registry-scanner/pkg/image/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func NewFromIdentifier(identifier string) *ContainerImage {
img.ImageAlias = alias
img.ImageName = reference.Path(parsed)
// if library/ was added to the image name, remove it
if !strings.HasPrefix(imgRef, "library/") {
if !strings.Contains(imgRef, "library/") {
img.ImageName = strings.TrimPrefix(img.ImageName, "library/")
}
if digested, ok := parsed.(reference.Digested); ok {
Expand Down
12 changes: 12 additions & 0 deletions registry-scanner/pkg/image/image_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,18 @@ func Test_ParseImageTags(t *testing.T) {
assert.Equal(t, "classic-web", image.ImageName)
assert.Nil(t, image.ImageTag)
})
t.Run("#1012 Parse docker.io image and keep library if present", func(t *testing.T) {
image := NewFromIdentifier("docker.io/library/postgres")
assert.Equal(t, "docker.io", image.RegistryURL)
assert.Equal(t, "library/postgres", image.ImageName)
assert.Nil(t, image.ImageTag)
})
t.Run("#1012 Parse docker.io image and do not keep library if absent", func(t *testing.T) {
image := NewFromIdentifier("docker.io/postgres")
assert.Equal(t, "docker.io", image.RegistryURL)
assert.Equal(t, "postgres", image.ImageName)
assert.Nil(t, image.ImageTag)
})
}

func Test_ImageToString(t *testing.T) {
Expand Down

0 comments on commit 34807d2

Please sign in to comment.