From 98ead5674814c1fa586c59eef81156cf9ae8c784 Mon Sep 17 00:00:00 2001 From: Oreon Lothamer <73498677+oreonl@users.noreply.github.com> Date: Thu, 7 Sep 2023 11:41:05 -1000 Subject: [PATCH] fix: handle annotations for resources with ':' in the name (#15101) (#15380) * fix: handle annotations for resources with ':' in the name Signed-off-by: Oreon Lothamer * fix: switch to using splitN for handling annotation splitting Signed-off-by: Oreon Lothamer * fix: check len(parts) !=3 Signed-off-by: Oreon Lothamer * Retrigger CI pipeline Signed-off-by: Oreon Lothamer --------- Signed-off-by: Oreon Lothamer --- util/argo/resource_tracking.go | 2 +- util/argo/resource_tracking_test.go | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/util/argo/resource_tracking.go b/util/argo/resource_tracking.go index a0ec6b302a9aa0..bc58172397ffe9 100644 --- a/util/argo/resource_tracking.go +++ b/util/argo/resource_tracking.go @@ -178,7 +178,7 @@ func (rt *resourceTracking) BuildAppInstanceValue(value AppInstanceValue) string // ParseAppInstanceValue parse resource tracking id from format :/:/ 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 diff --git a/util/argo/resource_tracking_test.go b/util/argo/resource_tracking_test.go index 36f94747ffd787..479dcb98da098b 100644 --- a/util/argo/resource_tracking_test.go +++ b/util/argo/resource_tracking_test.go @@ -89,6 +89,19 @@ func TestParseAppInstanceValue(t *testing.T) { assert.Equal(t, appInstanceValue.Name, "") } +func TestParseAppInstanceValueColon(t *testing.T) { + resourceTracking := NewResourceTracking() + appInstanceValue, err := resourceTracking.ParseAppInstanceValue("app:/:/:") + if !assert.NoError(t, err) { + t.Fatal() + } + assert.Equal(t, appInstanceValue.ApplicationName, "app") + assert.Equal(t, appInstanceValue.Group, "") + assert.Equal(t, appInstanceValue.Kind, "") + assert.Equal(t, appInstanceValue.Namespace, "") + assert.Equal(t, appInstanceValue.Name, ":") +} + func TestParseAppInstanceValueWrongFormat1(t *testing.T) { resourceTracking := NewResourceTracking() _, err := resourceTracking.ParseAppInstanceValue("app")