fix(helm): helm create will not overwrite existing files

It will ignore files if they exist, and create files if they were
missing.

Closes #1515
pull/1538/head
Matt Butcher 8 years ago
parent e4bbe33e92
commit 0a163a2a3a
No known key found for this signature in database
GPG Key ID: DCD5F5E5EF32C345

@ -209,18 +209,11 @@ func Create(chartfile *chart.Metadata, dir string) (string, error) {
return cdir, err return cdir, err
} }
if err := SaveChartfile(filepath.Join(cdir, ChartfileName), chartfile); err != nil { cf := filepath.Join(cdir, ChartfileName)
return cdir, err if _, err := os.Stat(cf); err != nil {
} if err := SaveChartfile(cf, chartfile); err != nil {
return cdir, err
val := []byte(fmt.Sprintf(defaultValues, chartfile.Name)) }
if err := ioutil.WriteFile(filepath.Join(cdir, ValuesfileName), val, 0644); err != nil {
return cdir, err
}
val = []byte(defaultIgnore)
if err := ioutil.WriteFile(filepath.Join(cdir, IgnorefileName), val, 0644); err != nil {
return cdir, err
} }
for _, d := range []string{TemplatesDir, ChartsDir} { for _, d := range []string{TemplatesDir, ChartsDir} {
@ -229,25 +222,50 @@ func Create(chartfile *chart.Metadata, dir string) (string, error) {
} }
} }
// Write out deployment.yaml files := []struct {
val = []byte(defaultDeployment) path string
if err := ioutil.WriteFile(filepath.Join(cdir, TemplatesDir, DeploymentName), val, 0644); err != nil { content []byte
return cdir, err }{
{
// values.yaml
path: filepath.Join(cdir, ValuesfileName),
content: []byte(fmt.Sprintf(defaultValues, chartfile.Name)),
},
{
// .helmignore
path: filepath.Join(cdir, IgnorefileName),
content: []byte(defaultIgnore),
},
{
// deployment.yaml
path: filepath.Join(cdir, TemplatesDir, DeploymentName),
content: []byte(defaultDeployment),
},
{
// service.yaml
path: filepath.Join(cdir, TemplatesDir, ServiceName),
content: []byte(defaultService),
},
{
// NOTES.txt
path: filepath.Join(cdir, TemplatesDir, NotesName),
content: []byte(defaultNotes),
},
{
// _helpers.tpl
path: filepath.Join(cdir, TemplatesDir, HelpersName),
content: []byte(defaultHelpers),
},
} }
// Write out service.yaml for _, file := range files {
val = []byte(defaultService) if _, err := os.Stat(file.path); err == nil {
if err := ioutil.WriteFile(filepath.Join(cdir, TemplatesDir, ServiceName), val, 0644); err != nil { // File exists and is okay. Skip it.
return cdir, err continue
} }
if err := ioutil.WriteFile(file.path, file.content, 0644); err != nil {
// Write out NOTES.txt return cdir, err
val = []byte(defaultNotes) }
if err := ioutil.WriteFile(filepath.Join(cdir, TemplatesDir, NotesName), val, 0644); err != nil {
return cdir, err
} }
return cdir, nil
// Write out _helpers.tpl
val = []byte(defaultHelpers)
return cdir, ioutil.WriteFile(filepath.Join(cdir, TemplatesDir, HelpersName), val, 0644)
} }

Loading…
Cancel
Save