Skip to content

Commit 8c04a1f

Browse files
committed
fix: several fixes in config loading
1 parent 26e252e commit 8c04a1f

File tree

5 files changed

+20
-15
lines changed

5 files changed

+20
-15
lines changed

cmd/build.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package cmd
22

33
import (
4+
"context"
45
"github.com/loft-sh/devspace/cmd/flags"
56
"github.com/loft-sh/devspace/pkg/devspace/build"
67
"github.com/loft-sh/devspace/pkg/devspace/config/loader"
@@ -63,7 +64,7 @@ Builds all defined images and pushes them
6364
// Run executes the command logic
6465
func (cmd *BuildCmd) Run(f factory.Factory) error {
6566
configOptions := cmd.ToConfigOptions()
66-
ctx, err := prepare(f, configOptions, cmd.GlobalFlags, true)
67+
ctx, err := prepare(context.Background(), f, configOptions, cmd.GlobalFlags, true)
6768
if err != nil {
6869
return err
6970
}

cmd/deploy.go

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ devspace deploy --kube-context=deploy-context
115115
// Run executes the down command logic
116116
func (cmd *DeployCmd) Run(f factory.Factory) error {
117117
configOptions := cmd.ToConfigOptions()
118-
ctx, err := prepare(f, configOptions, cmd.GlobalFlags, false)
118+
ctx, err := prepare(context.Background(), f, configOptions, cmd.GlobalFlags, false)
119119
if err != nil {
120120
return err
121121
}
@@ -153,7 +153,7 @@ func (cmd *DeployCmd) runCommand(ctx *devspacecontext.Context, f factory.Factory
153153
})
154154
}
155155

156-
func prepare(f factory.Factory, configOptions *loader.ConfigOptions, globalFlags *flags.GlobalFlags, allowFailingKubeClient bool) (*devspacecontext.Context, error) {
156+
func prepare(ctx context.Context, f factory.Factory, configOptions *loader.ConfigOptions, globalFlags *flags.GlobalFlags, allowFailingKubeClient bool) (*devspacecontext.Context, error) {
157157
// start file logging
158158
logpkg.StartFileLogging()
159159

@@ -202,17 +202,14 @@ func prepare(f factory.Factory, configOptions *loader.ConfigOptions, globalFlags
202202
return nil, err
203203
}
204204

205-
// Create our parent context
206-
backgroundCtx := context.Background()
207-
208205
// load config
209-
configInterface, err := configLoader.LoadWithCache(backgroundCtx, localCache, client, configOptions, log)
206+
configInterface, err := configLoader.LoadWithCache(ctx, localCache, client, configOptions, log)
210207
if err != nil {
211208
return nil, err
212209
}
213210

214211
// create devspace context
215-
return devspacecontext.NewContext(backgroundCtx, log).
212+
return devspacecontext.NewContext(ctx, log).
216213
WithConfig(configInterface).
217214
WithKubeClient(client), nil
218215
}

cmd/dev.go

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package cmd
22

33
import (
4+
"context"
45
"github.com/loft-sh/devspace/pkg/devspace/build"
56
"github.com/loft-sh/devspace/pkg/devspace/config"
67
"github.com/loft-sh/devspace/pkg/devspace/config/localcache"
@@ -62,10 +63,10 @@ type DevCmd struct {
6263
log log.Logger
6364

6465
// used for testing to allow interruption
65-
Interrupt chan error
66-
Stdout io.Writer
67-
Stderr io.Writer
68-
Stdin io.Reader
66+
Ctx context.Context
67+
Stdout io.Writer
68+
Stderr io.Writer
69+
Stdin io.Reader
6970
}
7071

7172
// NewDevCmd creates a new devspace dev command
@@ -133,8 +134,12 @@ Open terminal instead of logs:
133134

134135
// Run executes the command logic
135136
func (cmd *DevCmd) Run(f factory.Factory, args []string) error {
137+
if cmd.Ctx == nil {
138+
cmd.Ctx = context.Background()
139+
}
140+
136141
configOptions := cmd.ToConfigOptions()
137-
ctx, err := prepare(f, configOptions, cmd.GlobalFlags, false)
142+
ctx, err := prepare(cmd.Ctx, f, configOptions, cmd.GlobalFlags, false)
138143
if err != nil {
139144
return err
140145
}

cmd/purge.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package cmd
22

33
import (
4+
"context"
45
"github.com/loft-sh/devspace/pkg/devspace/config/loader"
56
devspacecontext "github.com/loft-sh/devspace/pkg/devspace/context"
67
"github.com/loft-sh/devspace/pkg/devspace/pipeline/types"
@@ -64,7 +65,7 @@ devspace purge -d my-deployment
6465
// Run executes the purge command logic
6566
func (cmd *PurgeCmd) Run(f factory.Factory) error {
6667
configOptions := cmd.ToConfigOptions()
67-
ctx, err := prepare(f, configOptions, cmd.GlobalFlags, false)
68+
ctx, err := prepare(context.Background(), f, configOptions, cmd.GlobalFlags, false)
6869
if err != nil {
6970
return err
7071
}

cmd/render.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package cmd
22

33
import (
4+
"context"
45
devspacecontext "github.com/loft-sh/devspace/pkg/devspace/context"
56
pipelinetypes "github.com/loft-sh/devspace/pkg/devspace/pipeline/types"
67
"github.com/loft-sh/devspace/pkg/devspace/plugin"
@@ -79,7 +80,7 @@ deployment.
7980
func (cmd *RenderCmd) Run(f factory.Factory) error {
8081
f.GetLog().Warnf("This command is deprecated, please use 'devspace deploy --render' instead")
8182
configOptions := cmd.ToConfigOptions()
82-
ctx, err := prepare(f, configOptions, cmd.GlobalFlags, true)
83+
ctx, err := prepare(context.Background(), f, configOptions, cmd.GlobalFlags, true)
8384
if err != nil {
8485
return err
8586
}

0 commit comments

Comments
 (0)