diff --git a/cmd/add.go b/cmd/add.go index 7b9a4af79f..cf578ac509 100644 --- a/cmd/add.go +++ b/cmd/add.go @@ -240,14 +240,25 @@ func (cmd *AddCmd) RunAddPackage(cobraCmd *cobra.Command, args []string) { log.Fatal(err) } - f, err := os.OpenFile(filepath.Join(cwd, "chart", "values.yaml"), os.O_APPEND|os.O_WRONLY|os.O_CREATE, 0600) + // Check if key already exists + valuesYaml := filepath.Join(cwd, "chart", "values.yaml") + valuesYamlContents := map[interface{}]interface{}{} + + err = yamlutil.ReadYamlFromFile(valuesYaml, valuesYamlContents) if err != nil { - log.Fatal(err) + log.Fatalf("Error parsing %s: %v", valuesYaml, err) } - defer f.Close() - if _, err = f.WriteString("\n" + version.GetName() + ": {}\n"); err != nil { - log.Fatal(err) + if _, ok := valuesYamlContents[version.GetName()]; ok == false { + f, err := os.OpenFile(valuesYaml, os.O_APPEND|os.O_WRONLY|os.O_CREATE, 0600) + if err != nil { + log.Fatal(err) + } + + defer f.Close() + if _, err = f.WriteString("\n# Here you can specify the subcharts values (for more information see: https://github.com/helm/helm/blob/master/docs/chart_template_guide/subcharts_and_globals.md#overriding-values-from-a-parent-chart)\n" + version.GetName() + ": {}\n"); err != nil { + log.Fatal(err) + } } log.Donef("Successfully added %s as chart dependency, you can configure the package in 'chart/values.yaml'", version.GetName()) diff --git a/cmd/init.go b/cmd/init.go index d3978c6ef9..66646483cf 100644 --- a/cmd/init.go +++ b/cmd/init.go @@ -3,6 +3,7 @@ package cmd import ( "io/ioutil" "os" + "os/exec" "path/filepath" "regexp" "strconv" @@ -542,11 +543,19 @@ func (cmd *InitCmd) configureRegistry() { if isGoogleRegistry { if len(defaultImageNameParts) < 2 { + project, err := exec.Command("gcloud", "config", "get-value", "project").Output() + gcloudProject := "" + + if err == nil { + gcloudProject = strings.TrimSpace(string(project)) + } + gcloudProjectName := stdinutil.GetFromStdin(&stdinutil.GetFromStdinParams{ - Question: "What is the name of your Google Cloud Project? (run 'gcloud config get-value project' to get the project name)", - DefaultValue: "", + Question: "What Google Cloud Project should be used?", + DefaultValue: gcloudProject, ValidationRegexPattern: "^.*$", }) + cmd.defaultImage.Name = configutil.String(*gcloudProjectName + "/" + strings.TrimPrefix(defaultImageName, *gcloudProjectName)) } } diff --git a/cmd/status.go b/cmd/status.go index c43b946691..0f4112b0e0 100644 --- a/cmd/status.go +++ b/cmd/status.go @@ -238,7 +238,7 @@ func (cmd *StatusCmd) getDevspaceStatus() ([]string, error) { return nil, err } - if len(releases.Releases) == 0 { + if releases == nil || len(releases.Releases) == 0 { return nil, errors.New("No release found") }