Skip to content

Commit 6f46733

Browse files
fix: prevent concurrent Helm configuration races (#688)
Signed-off-by: Aleksei Igrychev <aleksei.igrychev@palark.com>
1 parent f5a2103 commit 6f46733

2 files changed

Lines changed: 20 additions & 12 deletions

File tree

pkg/helm/pkg/action/action.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -724,6 +724,9 @@ func (cfg *Configuration) Init(getter genericclioptions.RESTClientGetter, namesp
724724

725725
// SetHookOutputFunc sets the HookOutputFunc on the Configuration.
726726
func (cfg *Configuration) SetHookOutputFunc(hookOutputFunc func(_, _, _ string) io.Writer) {
727+
cfg.mutex.Lock()
728+
defer cfg.mutex.Unlock()
729+
727730
cfg.HookOutputFunc = hookOutputFunc
728731
}
729732

pkg/helm/pkg/action/configuration_ai_test.go

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,32 +3,37 @@
33
package action
44

55
import (
6+
"io"
67
"sync"
78
"testing"
89

910
"github.com/stretchr/testify/require"
1011
"k8s.io/cli-runtime/pkg/genericclioptions"
1112
)
1213

13-
func TestAIConfigurationInitConcurrent(t *testing.T) {
14+
func TestAIConfigurationInitAndSetHookOutputFuncConcurrent(t *testing.T) {
1415
cfg := NewConfiguration()
1516
getter := genericclioptions.NewConfigFlags(true)
16-
errs := make(chan error, 2)
17+
start := make(chan struct{})
18+
errs := make(chan error, 1)
1719
var wg sync.WaitGroup
1820
wg.Add(2)
1921

20-
for range 2 {
21-
go func() {
22-
defer wg.Done()
23-
errs <- cfg.Init(getter, "default", "memory")
24-
}()
25-
}
22+
go func() {
23+
defer wg.Done()
24+
<-start
25+
errs <- cfg.Init(getter, "default", "memory")
26+
}()
27+
go func() {
28+
defer wg.Done()
29+
<-start
30+
cfg.SetHookOutputFunc(func(_, _, _ string) io.Writer { return io.Discard })
31+
}()
2632

33+
close(start)
2734
wg.Wait()
28-
close(errs)
2935

30-
for err := range errs {
31-
require.NoError(t, err)
32-
}
36+
require.NoError(t, <-errs)
3337
require.NotNil(t, cfg.Releases)
38+
require.NotNil(t, cfg.HookOutputFunc)
3439
}

0 commit comments

Comments
 (0)