Skip to content

Commit 8b51f98

Browse files
authored
Merge pull request #255 from covexo/package-fixes
Package fixes
2 parents fed4bf4 + 6d33d1e commit 8b51f98

3 files changed

Lines changed: 28 additions & 8 deletions

File tree

cmd/add.go

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -240,14 +240,25 @@ func (cmd *AddCmd) RunAddPackage(cobraCmd *cobra.Command, args []string) {
240240
log.Fatal(err)
241241
}
242242

243-
f, err := os.OpenFile(filepath.Join(cwd, "chart", "values.yaml"), os.O_APPEND|os.O_WRONLY|os.O_CREATE, 0600)
243+
// Check if key already exists
244+
valuesYaml := filepath.Join(cwd, "chart", "values.yaml")
245+
valuesYamlContents := map[interface{}]interface{}{}
246+
247+
err = yamlutil.ReadYamlFromFile(valuesYaml, valuesYamlContents)
244248
if err != nil {
245-
log.Fatal(err)
249+
log.Fatalf("Error parsing %s: %v", valuesYaml, err)
246250
}
247251

248-
defer f.Close()
249-
if _, err = f.WriteString("\n" + version.GetName() + ": {}\n"); err != nil {
250-
log.Fatal(err)
252+
if _, ok := valuesYamlContents[version.GetName()]; ok == false {
253+
f, err := os.OpenFile(valuesYaml, os.O_APPEND|os.O_WRONLY|os.O_CREATE, 0600)
254+
if err != nil {
255+
log.Fatal(err)
256+
}
257+
258+
defer f.Close()
259+
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 {
260+
log.Fatal(err)
261+
}
251262
}
252263

253264
log.Donef("Successfully added %s as chart dependency, you can configure the package in 'chart/values.yaml'", version.GetName())

cmd/init.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package cmd
33
import (
44
"io/ioutil"
55
"os"
6+
"os/exec"
67
"path/filepath"
78
"regexp"
89
"strconv"
@@ -542,11 +543,19 @@ func (cmd *InitCmd) configureRegistry() {
542543

543544
if isGoogleRegistry {
544545
if len(defaultImageNameParts) < 2 {
546+
project, err := exec.Command("gcloud", "config", "get-value", "project").Output()
547+
gcloudProject := ""
548+
549+
if err == nil {
550+
gcloudProject = strings.TrimSpace(string(project))
551+
}
552+
545553
gcloudProjectName := stdinutil.GetFromStdin(&stdinutil.GetFromStdinParams{
546-
Question: "What is the name of your Google Cloud Project? (run 'gcloud config get-value project' to get the project name)",
547-
DefaultValue: "",
554+
Question: "What Google Cloud Project should be used?",
555+
DefaultValue: gcloudProject,
548556
ValidationRegexPattern: "^.*$",
549557
})
558+
550559
cmd.defaultImage.Name = configutil.String(*gcloudProjectName + "/" + strings.TrimPrefix(defaultImageName, *gcloudProjectName))
551560
}
552561
}

cmd/status.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ func (cmd *StatusCmd) getDevspaceStatus() ([]string, error) {
238238
return nil, err
239239
}
240240

241-
if len(releases.Releases) == 0 {
241+
if releases == nil || len(releases.Releases) == 0 {
242242
return nil, errors.New("No release found")
243243
}
244244

0 commit comments

Comments
 (0)