Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automated backport of #2933: Fix concurrent map write crash in logIfChanged #2934

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions pkg/images/images.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"fmt"
"os"
"strings"
"sync"

apis "github.com/submariner-io/submariner-operator/api/v1alpha1"
v1 "k8s.io/api/core/v1"
Expand Down Expand Up @@ -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 {
Expand All @@ -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
}

Expand Down
Loading