mirror of https://github.com/kubernetes/kops.git
Merge pull request #249 from justinsb/fix_235
Fix concurrent map write bug in TF creation
This commit is contained in:
commit
13388fc4de
|
|
@ -10,6 +10,7 @@ import (
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
"strings"
|
"strings"
|
||||||
|
"sync"
|
||||||
)
|
)
|
||||||
|
|
||||||
type TerraformTarget struct {
|
type TerraformTarget struct {
|
||||||
|
|
@ -17,10 +18,14 @@ type TerraformTarget struct {
|
||||||
Region string
|
Region string
|
||||||
Project string
|
Project string
|
||||||
|
|
||||||
resources []*terraformResource
|
|
||||||
|
|
||||||
files map[string][]byte
|
|
||||||
outDir string
|
outDir string
|
||||||
|
|
||||||
|
// mutex protects the following items (resources & files)
|
||||||
|
mutex sync.Mutex
|
||||||
|
// resources is a list of TF items that should be created
|
||||||
|
resources []*terraformResource
|
||||||
|
// files is a map of TF resource files that should be created
|
||||||
|
files map[string][]byte
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewTerraformTarget(cloud fi.Cloud, region, project string, outDir string) *TerraformTarget {
|
func NewTerraformTarget(cloud fi.Cloud, region, project string, outDir string) *TerraformTarget {
|
||||||
|
|
@ -57,6 +62,9 @@ func (t *TerraformTarget) AddFile(resourceType string, resourceName string, key
|
||||||
return nil, fmt.Errorf("error rending resource %s %v", id, err)
|
return nil, fmt.Errorf("error rending resource %s %v", id, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
t.mutex.Lock()
|
||||||
|
defer t.mutex.Unlock()
|
||||||
|
|
||||||
p := path.Join("data", id)
|
p := path.Join("data", id)
|
||||||
t.files[p] = d
|
t.files[p] = d
|
||||||
|
|
||||||
|
|
@ -71,6 +79,9 @@ func (t *TerraformTarget) RenderResource(resourceType string, resourceName strin
|
||||||
Item: e,
|
Item: e,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
t.mutex.Lock()
|
||||||
|
defer t.mutex.Unlock()
|
||||||
|
|
||||||
t.resources = append(t.resources, res)
|
t.resources = append(t.resources, res)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue