From 4ed15fc9b4e240fc0c88a30554b0d0e86e8f20e8 Mon Sep 17 00:00:00 2001 From: Toms Ozolins Date: Fri, 15 Sep 2023 13:43:45 +0300 Subject: [PATCH] fix: managed images annotation whitespace handling (#186) --- internal/models/argo.go | 2 +- internal/models/argo_test.go | 30 ++++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/internal/models/argo.go b/internal/models/argo.go index aaf6566f..ca4821bd 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] } } diff --git a/internal/models/argo_test.go b/internal/models/argo_test.go index 24a0a3cd..1fa68259 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{