Skip to content

Commit 0faaa5e

Browse files
committed
Add mutex Lock and Unlock in NewClientFromConf functio
1 parent 8514bc3 commit 0faaa5e

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

pkg/cloud/client.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"bytes"
2121
"io"
2222
"os"
23+
"sync"
2324

2425
corev1 "k8s.io/api/core/v1"
2526

@@ -67,6 +68,7 @@ type SecretConfig struct {
6768
}
6869

6970
var clientCache = map[Config]*client{}
71+
var cacheMutex sync.Mutex
7072

7173
// UnmarshalAllSecretConfigs parses a yaml document for each secret.
7274
func UnmarshalAllSecretConfigs(in []byte, out *[]SecretConfig) error {
@@ -136,6 +138,9 @@ func NewClientFromYamlPath(confPath string, secretName string) (Client, error) {
136138

137139
// Creates a new Cloud Client form a map of strings to strings.
138140
func NewClientFromConf(conf Config) (Client, error) {
141+
cacheMutex.Lock()
142+
defer cacheMutex.Unlock()
143+
139144
if client, exists := clientCache[conf]; exists {
140145
return client, nil
141146
}

0 commit comments

Comments
 (0)