Skip to content
This repository was archived by the owner on Apr 29, 2024. It is now read-only.

Fix concurrent map writes #927

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
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
3 changes: 2 additions & 1 deletion internal/executables/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ func build(debug bool, gitCommit, version, githubClientID, githubClientSecret st

builtTuple := builtTupleFunc(bin)

args := []string{"build", "-o", bin.OutDir}
args := []string{"build", "-race", "-o", bin.OutDir}

ldflags := "-s -w "
if debug {
Expand All @@ -107,6 +107,7 @@ func build(debug bool, gitCommit, version, githubClientID, githubClientSecret st
for k, v := range bin.Env {
cmdEnv = append(cmdEnv, fmt.Sprintf("%s=%s", k, v))
}
cmdEnv = append(cmdEnv, "CGO_ENABLED=1")

cmd := exec.Command("go", append(args, "-ldflags", ldflags, bin.MainDir)...)
cmd.Env = cmdEnv
Expand Down
19 changes: 17 additions & 2 deletions internal/operator/orbiter/kinds/clusters/kubernetes/machines.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ func alignMachines(
}).Debug("Ensuring scale")

var machines []*initializedMachine
upscalingDone := true

upscalingUndone := make(chan bool)
var (
wg sync.WaitGroup
err error
Expand All @@ -33,7 +34,7 @@ func alignMachines(
defer wg.Done()

if pool.upscaling > 0 {
upscalingDone = false
upscalingUndone <- true
machines, alignErr := newMachines(pool.infra, pool.upscaling, pool.desired.Nodes)
if alignErr != nil {
err = helpers.Concat(err, alignErr)
Expand Down Expand Up @@ -62,7 +63,21 @@ func alignMachines(
wg.Add(1)
go alignPool(workerPool)
}

upscalingDone := true
go func() {
for {
select {
case undone := <-upscalingUndone:
if upscalingDone {
upscalingDone = undone
}
}
}
}()

wg.Wait()
close(upscalingUndone)
if err != nil {
return false, machines, err
}
Expand Down
9 changes: 5 additions & 4 deletions internal/operator/orbiter/kinds/providers/core/nodeagent.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"os"
"strings"
"sync"
"time"

"github.com/caos/orbos/internal/executables"
Expand Down Expand Up @@ -96,11 +97,11 @@ func NodeAgentFuncs(

systemdEntry := "node-agentd"
systemdPath := fmt.Sprintf("/lib/systemd/system/%s.service", systemdEntry)
systemdUnitCache := make(map[string]string)
systemdUnitCache := sync.Map{}
systemdUnitFile := func(machine infra.Machine) string {

if cached, ok := systemdUnitCache[machine.ID()]; ok {
return cached
if cached, ok := systemdUnitCache.Load(machine.ID()); ok {
return cached.(string)
}

newFile := fmt.Sprintf(`[Unit]
Expand All @@ -122,7 +123,7 @@ KillMode=mixed
[Install]
WantedBy=multi-user.target
`, binary, machine.ID(), pprofStr, verboseStr, sentryEnvironment)
systemdUnitCache[machine.ID()] = newFile
systemdUnitCache.Store(machine.ID(), newFile)
return newFile
}

Expand Down