@@ -4,10 +4,10 @@ import (
44 "strings"
55 "time"
66
7+ "github.com/distribution/distribution/v3/reference"
8+
79 "github.com/argoproj-labs/argocd-image-updater/pkg/log"
810 "github.com/argoproj-labs/argocd-image-updater/pkg/tag"
9-
10- "github.com/distribution/distribution/v3/reference"
1111)
1212
1313type ContainerImage struct {
@@ -95,12 +95,13 @@ func (img *ContainerImage) GetFullNameWithTag() string {
9595 }
9696 str += img .ImageName
9797 if img .ImageTag != nil {
98+ if img .ImageTag .TagName != "" {
99+ str += ":"
100+ str += img .ImageTag .TagName
101+ }
98102 if img .ImageTag .TagDigest != "" {
99103 str += "@"
100104 str += img .ImageTag .TagDigest
101- } else if img .ImageTag .TagName != "" {
102- str += ":"
103- str += img .ImageTag .TagName
104105 }
105106 }
106107 return str
@@ -223,10 +224,22 @@ func getImageTagFromIdentifier(identifier string) (string, string, *tag.ImageTag
223224 imageString = strings .Join (comp [1 :], "/" )
224225 }
225226
226- // We can either have a tag name or a digest reference
227+ // We can either have a tag name or a digest reference, or both
228+ // jannfis/test-image:0.1
229+ // gcr.io/jannfis/test-image:0.1
230+ // gcr.io/jannfis/test-image@sha256:abcde
231+ // gcr.io/jannfis/test-image:test-tag@sha256:abcde
227232 if strings .Contains (imageString , "@" ) {
228233 comp = strings .SplitN (imageString , "@" , 2 )
229- return sourceName , comp [0 ], tag .NewImageTag ("" , time .Unix (0 , 0 ), comp [1 ])
234+ colonPos := strings .LastIndex (comp [0 ], ":" )
235+ slashPos := strings .LastIndex (comp [0 ], "/" )
236+ if colonPos > slashPos {
237+ // first half (before @) contains image and tag name
238+ return sourceName , comp [0 ][:colonPos ], tag .NewImageTag (comp [0 ][colonPos + 1 :], time .Unix (0 , 0 ), comp [1 ])
239+ } else {
240+ // first half contains image name without tag name
241+ return sourceName , comp [0 ], tag .NewImageTag ("" , time .Unix (0 , 0 ), comp [1 ])
242+ }
230243 } else {
231244 comp = strings .SplitN (imageString , ":" , 2 )
232245 if len (comp ) != 2 {
0 commit comments