Skip to content

Commit

Permalink
fix: handle annotations for resources with ':' in the name (argoproj#…
Browse files Browse the repository at this point in the history
…15101) (argoproj#15380)

* fix: handle annotations for resources with ':' in the name

Signed-off-by: Oreon Lothamer <oreon.lothamer@softrams.com>

* fix: switch to using splitN for handling annotation splitting

Signed-off-by: Oreon Lothamer <oreon.lothamer@softrams.com>

* fix: check len(parts) !=3

Signed-off-by: Oreon Lothamer <oreon.lothamer@softrams.com>

* Retrigger CI pipeline

Signed-off-by: Oreon Lothamer <oreon.lothamer@softrams.com>

---------

Signed-off-by: Oreon Lothamer <oreon.lothamer@softrams.com>
  • Loading branch information
oreonl authored and vladfr committed Dec 13, 2023
1 parent 545cace commit c92fa61
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion util/argo/resource_tracking.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ func (rt *resourceTracking) BuildAppInstanceValue(value AppInstanceValue) string
// ParseAppInstanceValue parse resource tracking id from format <application-name>:<group>/<kind>:<namespace>/<name> to struct
func (rt *resourceTracking) ParseAppInstanceValue(value string) (*AppInstanceValue, error) {
var appInstanceValue AppInstanceValue
parts := strings.Split(value, ":")
parts := strings.SplitN(value, ":", 3)
appInstanceValue.ApplicationName = parts[0]
if len(parts) != 3 {
return nil, WrongResourceTrackingFormat
Expand Down
13 changes: 13 additions & 0 deletions util/argo/resource_tracking_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,19 @@ func TestParseAppInstanceValue(t *testing.T) {
assert.Equal(t, appInstanceValue.Name, "<name>")
}

func TestParseAppInstanceValueColon(t *testing.T) {
resourceTracking := NewResourceTracking()
appInstanceValue, err := resourceTracking.ParseAppInstanceValue("app:<group>/<kind>:<namespace>/<name>:<colon>")
if !assert.NoError(t, err) {
t.Fatal()
}
assert.Equal(t, appInstanceValue.ApplicationName, "app")
assert.Equal(t, appInstanceValue.Group, "<group>")
assert.Equal(t, appInstanceValue.Kind, "<kind>")
assert.Equal(t, appInstanceValue.Namespace, "<namespace>")
assert.Equal(t, appInstanceValue.Name, "<name>:<colon>")
}

func TestParseAppInstanceValueWrongFormat1(t *testing.T) {
resourceTracking := NewResourceTracking()
_, err := resourceTracking.ParseAppInstanceValue("app")
Expand Down

0 comments on commit c92fa61

Please sign in to comment.