From 145f2406307e57a6f2eb1601d4f7d542d39a9f51 Mon Sep 17 00:00:00 2001 From: Andrey Smirnov Date: Wed, 10 Apr 2024 17:52:48 +0400 Subject: [PATCH] fix: don't modify a global map of profiles This shows up in image-factory tests, where multiple images are generated at once, and the global map write access panics. This was a bad idea in general to mutate global state on image generation. Signed-off-by: Andrey Smirnov --- pkg/imager/imager.go | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/pkg/imager/imager.go b/pkg/imager/imager.go index 2f834865d0..9180b5001f 100644 --- a/pkg/imager/imager.go +++ b/pkg/imager/imager.go @@ -39,6 +39,7 @@ type Imager struct { prof profile.Profile overlayInstaller overlay.Installer[overlay.ExtraOptions] + extraProfiles map[string]profile.Profile tempDir string @@ -192,6 +193,10 @@ func (i *Imager) handleOverlay(ctx context.Context, report *reporter.Reporter) e i.overlayInstaller = executor.New(filepath.Join(i.tempDir, constants.ImagerOverlayInstallersPath, i.prof.Overlay.Name)) + if i.extraProfiles == nil { + i.extraProfiles = make(map[string]profile.Profile) + } + for _, profilePath := range profileYAMLs { profileName := strings.TrimSuffix(filepath.Base(profilePath), ".yaml") @@ -206,7 +211,7 @@ func (i *Imager) handleOverlay(ctx context.Context, report *reporter.Reporter) e return fmt.Errorf("failed to unmarshal profile: %w", err) } - profile.Default[profileName] = overlayProfile + i.extraProfiles[profileName] = overlayProfile } return nil @@ -215,7 +220,12 @@ func (i *Imager) handleOverlay(ctx context.Context, report *reporter.Reporter) e func (i *Imager) handleProf() error { // resolve the profile if it contains a base name if i.prof.BaseProfileName != "" { - baseProfile, ok := profile.Default[i.prof.BaseProfileName] + baseProfile, ok := i.extraProfiles[i.prof.BaseProfileName] + + if !ok { + baseProfile, ok = profile.Default[i.prof.BaseProfileName] + } + if !ok { return fmt.Errorf("unknown base profile: %s", i.prof.BaseProfileName) }