Skip to content

Commit

Permalink
fix: don't modify a global map of profiles
Browse files Browse the repository at this point in the history
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 <andrey.smirnov@siderolabs.com>
  • Loading branch information
smira committed Apr 10, 2024
1 parent 6fe91ad commit 145f240
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions pkg/imager/imager.go
Expand Up @@ -39,6 +39,7 @@ type Imager struct {
prof profile.Profile

overlayInstaller overlay.Installer[overlay.ExtraOptions]
extraProfiles map[string]profile.Profile

tempDir string

Expand Down Expand Up @@ -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")

Expand All @@ -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
Expand All @@ -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)
}
Expand Down

0 comments on commit 145f240

Please sign in to comment.