Skip to content

Commit 26e252e

Browse files
committed
fix: several fixes in config loading
1 parent 3779ae8 commit 26e252e

File tree

7 files changed

+26
-40
lines changed

7 files changed

+26
-40
lines changed

pkg/devspace/config/loader/loader.go

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -129,28 +129,26 @@ func (l *configLoader) LoadWithParser(ctx context.Context, localCache localcache
129129
return nil, pluginErr
130130
}
131131

132+
// load the raw data
132133
data, err := l.LoadRaw()
133134
if err != nil {
134135
return nil, err
135136
}
136137

138+
// make sure name is in config
137139
name := options.OverrideName
138140
if name == "" {
139-
nameInterface, ok := data["name"]
141+
var ok bool
142+
name, ok = data["name"].(string)
140143
if !ok {
141-
name = "devspace"
142-
} else {
143-
name, ok = nameInterface.(string)
144-
if !ok || name == "" {
145-
return nil, fmt.Errorf("name property is not a string")
146-
}
144+
return nil, fmt.Errorf("name is missing in " + filepath.Base(l.absConfigPath))
147145
}
148146
}
149147

150148
// create remote cache
151149
var remoteCache remotecache.Cache
152150
if client != nil {
153-
remoteCache, err = remotecache.NewCacheLoader(name).Load(context.TODO(), client)
151+
remoteCache, err = remotecache.NewCacheLoader(name).Load(ctx, client)
154152
if err != nil {
155153
return nil, fmt.Errorf("error trying to load remote cache from current context and namespace: %v", err)
156154
}
@@ -596,7 +594,6 @@ func GetLastProfile(profiles []string) string {
596594

597595
// configExistsInPath checks whether a devspace configuration exists at a certain path
598596
func configExistsInPath(path string) bool {
599-
// check devspace.yaml
600597
_, err := os.Stat(path)
601598
return err == nil // false, no config file found
602599
}
@@ -621,6 +618,18 @@ func (l *configLoader) LoadRaw() (map[string]interface{}, error) {
621618
return nil, err
622619
}
623620

621+
name, ok := rawMap["name"].(string)
622+
if !ok || name == "" {
623+
directoryName := filepath.Base(filepath.Dir(l.absConfigPath))
624+
if directoryName != "" && len(directoryName) > 2 {
625+
name = directoryName
626+
} else {
627+
name = "devspace"
628+
}
629+
630+
rawMap["name"] = name
631+
}
632+
624633
return rawMap, nil
625634
}
626635

@@ -637,11 +646,11 @@ func (l *configLoader) SetDevSpaceRoot(log log.Logger) (bool, error) {
637646
return configExists, nil
638647
}
639648

640-
err := os.Chdir(filepath.Dir(ConfigPath(l.absConfigPath)))
649+
err := os.Chdir(filepath.Dir(l.absConfigPath))
641650
if err != nil {
642651
return false, err
643652
}
644-
l.absConfigPath = filepath.Base(ConfigPath(l.absConfigPath))
653+
645654
return true, nil
646655
}
647656

pkg/devspace/config/versions/v1beta11/upgrade.go

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ import (
88
"github.com/loft-sh/devspace/pkg/util/encoding"
99
"github.com/loft-sh/devspace/pkg/util/log"
1010
"k8s.io/apimachinery/pkg/labels"
11-
"os"
12-
"path/filepath"
1311
"strings"
1412
)
1513

@@ -28,17 +26,6 @@ func (c *Config) Upgrade(log log.Logger) (config.Config, error) {
2826
return nil, err
2927
}
3028

31-
// just guess a name here
32-
if nextConfig.Name == "" {
33-
// try to get current folder name
34-
wd, _ := os.Getwd()
35-
if wd != "" && filepath.Base(wd) != "" && len(filepath.Base(wd)) > 2 {
36-
nextConfig.Name = filepath.Base(wd)
37-
} else {
38-
nextConfig.Name = "devspace"
39-
}
40-
}
41-
4229
// use a pretty simple pipeline which was used by devspace before
4330
deployPipeline := `run_dependencies_pipelines --all
4431
build_images --all`

pkg/devspace/dependency/resolver.go

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -272,16 +272,9 @@ func GetDependencyConfigName(configPath string, config *latest.DependencyConfig)
272272
return "", errors.Wrapf(err, "load dependency config %s", configPath)
273273
}
274274

275-
name, ok := rawConfig["name"]
275+
nameString, ok := rawConfig["name"].(string)
276276
if !ok {
277-
// no name present, we will just call it by the dependency path
278-
return filepath.Base(configPath), nil
279-
}
280-
281-
nameString, ok := name.(string)
282-
if !ok {
283-
// no name present, we will just call it by the dependency path
284-
return filepath.Base(configPath), nil
277+
return "", fmt.Errorf("devspace.yaml name is missing")
285278
}
286279

287280
return nameString, nil

pkg/devspace/deploy/deployer/helm/deploy.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ func (d *DeployConfig) internalDeploy(ctx *devspacecontext.Context, overwriteVal
162162
// Deploy chart
163163
appRelease, err := d.Helm.InstallChart(ctx, releaseName, releaseNamespace, overwriteValues, d.DeploymentConfig.Helm)
164164
if err != nil {
165-
return nil, errors.Errorf("Unable to deploy helm chart: %v", err)
165+
return nil, errors.Errorf("unable to deploy helm chart: %v", err)
166166
}
167167

168168
// Print revision

pkg/devspace/helm/generic/generic.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,10 @@ func (c *client) Exec(ctx *devspacecontext.Context, args []string, helmConfig *l
9090
result, err := command.Output(ctx.Context, ctx.WorkingDir, c.helmPath, args...)
9191
if err != nil {
9292
if exitError, ok := err.(*exec.ExitError); ok {
93-
return nil, fmt.Errorf("error during '%s %s': %s%s => %v", c.helmPath, strings.Join(args, " "), string(result), string(exitError.Stderr), err)
93+
return nil, fmt.Errorf("error during '%s %s':\n %s%s => %v", c.helmPath, strings.Join(args, " "), string(result), string(exitError.Stderr), err)
9494
}
9595

96-
return nil, fmt.Errorf("error during '%s %s': %s => %v", c.helmPath, strings.Join(args, " "), string(result), err)
96+
return nil, fmt.Errorf("error during '%s %s':\n %s => %v %s", c.helmPath, strings.Join(args, " "), string(result), err)
9797
}
9898

9999
return result, nil

pkg/devspace/helm/v3/client.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,13 +119,11 @@ func (c *client) InstallChart(ctx *devspacecontext.Context, releaseName string,
119119
}
120120
args = append(args, helmConfig.UpgradeArgs...)
121121
output, err := c.genericHelm.Exec(ctx, args, helmConfig)
122-
123122
if helmConfig.DisplayOutput {
124123
writer := ctx.Log.Writer(logrus.InfoLevel)
125124
_, _ = writer.Write(output)
126125
_ = writer.Close()
127126
}
128-
129127
if err != nil {
130128
return nil, err
131129
}

pkg/util/command/command.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,7 @@ func CombinedOutputWithEnv(ctx context.Context, dir string, extraEnvVars map[str
144144

145145
func Output(ctx context.Context, dir string, cmd string, args ...string) ([]byte, error) {
146146
stdout := &bytes.Buffer{}
147-
stderr := &bytes.Buffer{}
148-
err := CommandWithEnv(ctx, dir, stdout, stderr, nil, nil, cmd, args...)
147+
err := CommandWithEnv(ctx, dir, stdout, nil, nil, nil, cmd, args...)
149148
return stdout.Bytes(), err
150149
}
151150

0 commit comments

Comments
 (0)