From 957638061f40d06b5c9ccde6044eea66c3094f5c Mon Sep 17 00:00:00 2001 From: Tom Pantelis Date: Wed, 10 Jan 2024 09:24:18 -0500 Subject: [PATCH] Fix concurrent map write crash in logIfChanged The loggedImages map needs to be synchronized. Fixes https://github.com/submariner-io/submariner/issues/2872 Signed-off-by: Tom Pantelis --- pkg/images/images.go | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/pkg/images/images.go b/pkg/images/images.go index 6b6cf193a..4f790d703 100644 --- a/pkg/images/images.go +++ b/pkg/images/images.go @@ -22,6 +22,7 @@ import ( "fmt" "os" "strings" + "sync" apis "github.com/submariner-io/submariner-operator/api/v1alpha1" v1 "k8s.io/api/core/v1" @@ -60,7 +61,7 @@ type imageParameters struct { var ( log = logf.Log.WithName("images") - loggedImages = make(map[imageParameters]string) + loggedImages = sync.Map{} ) func logIfChanged(repo, version, image, component, result, explanation string) string { @@ -70,15 +71,13 @@ func logIfChanged(repo, version, image, component, result, explanation string) s image: image, component: component, } - previous, ok := loggedImages[imageParams] + previous, ok := loggedImages.Swap(imageParams, result) if !ok || result != previous { log.Info("New GetImagePath result", "repo", repo, "version", version, "image", image, "component", component, "previous", previous, "result", result, "explanation", explanation) } - loggedImages[imageParams] = result - return result }