Repository: shini4i/argo-watcher (go)

Issue:
incorrect alias detection when there is a whitespace after comma
During our testing, we discovered that using a similar annotation approach as the one used in the ArgoCD Image Updater results in improper alias handling in our project. Specifically, it fails to identify the relevant Helm annotations.

Working version: `app=example/example,app2=example2/example2`
Not working version: `app=example/example, app2=example2/example2` (whitespace after comma)

We should probably strip the leading space here https://github.com/shini4i/argo-watcher/blob/main/internal/models/argo.go#L279-L280

Pull request description:
fix: managed images annotation whitespace handling (#186)
Closes #186 

Patch:
diff --git a/internal/models/argo.go b/internal/models/argo.go
index aaf6566..ca4821b 100644
--- a/internal/models/argo.go
+++ b/internal/models/argo.go
@@ -276,7 +276,7 @@ func extractManagedImages(annotations map[string]string) (map[string]string, err
 				if !strings.Contains(image, "=") {
 					return nil, fmt.Errorf("invalid format for %s annotation", managedImagesAnnotation)
 				}
-				managedImage := strings.Split(image, "=")
+				managedImage := strings.Split(strings.TrimSpace(image), "=")
 				managedImages[managedImage[0]] = managedImage[1]
 			}
 		}


Test patch:
diff --git a/internal/models/argo_test.go b/internal/models/argo_test.go
index 24a0a3c..1fa6825 100644
--- a/internal/models/argo_test.go
+++ b/internal/models/argo_test.go
@@ -275,6 +275,36 @@ func TestExtractManagedImages(t *testing.T) {
 				"alias2": "image2",
 			},
 		},
+		{
+			name: "Extracts multiple managed images with whitespace in alias",
+			annotation: map[string]string{
+				managedImagesAnnotation: "alias1=image1, alias2=image2",
+			},
+			expected: map[string]string{
+				"alias1": "image1",
+				"alias2": "image2",
+			},
+		},
+		{
+			name: "Extracts multiple managed images with whitespace in image",
+			annotation: map[string]string{
+				managedImagesAnnotation: "alias1=image1 ,alias2=image2",
+			},
+			expected: map[string]string{
+				"alias1": "image1",
+				"alias2": "image2",
+			},
+		},
+		{
+			name: "Extracts multiple managed images with whitespace in alias and image",
+			annotation: map[string]string{
+				managedImagesAnnotation: "alias1=image1 , alias2=image2",
+			},
+			expected: map[string]string{
+				"alias1": "image1",
+				"alias2": "image2",
+			},
+		},
 		{
 			name: "Extracts single managed image",
 			annotation: map[string]string{