Skip to content

Commit e11abb7

Browse files
committed
fix: fixed context selection issue
1 parent 1ff15dd commit e11abb7

2 files changed

Lines changed: 16 additions & 23 deletions

File tree

cmd/run_pipeline.go

Lines changed: 3 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import (
66
"github.com/loft-sh/devspace/cmd/flags"
77
"github.com/loft-sh/devspace/pkg/devspace/build"
88
"github.com/loft-sh/devspace/pkg/devspace/config/loader"
9-
"github.com/loft-sh/devspace/pkg/devspace/config/localcache"
109
"github.com/loft-sh/devspace/pkg/devspace/config/versions/latest"
1110
devspacecontext "github.com/loft-sh/devspace/pkg/devspace/context"
1211
"github.com/loft-sh/devspace/pkg/devspace/context/values"
@@ -350,34 +349,15 @@ func initialize(ctx context.Context, f factory.Factory, options *CommandOptions,
350349
}
351350
devCtx = devCtx.WithDependencies(dependencies)
352351

353-
// update last used kube context & save generated yaml
354-
err = updateLastKubeContext(devCtx)
352+
// save local cache
353+
err = localCache.Save()
355354
if err != nil {
356-
return nil, errors.Wrap(err, "update last kube context")
355+
return nil, errors.Wrap(err, "save cache")
357356
}
358357

359358
return devCtx, nil
360359
}
361360

362-
func updateLastKubeContext(ctx devspacecontext.Context) error {
363-
// Update generated if we deploy the application
364-
if ctx.KubeClient() != nil {
365-
if ctx.Config() != nil && ctx.Config().LocalCache() != nil {
366-
ctx.Config().LocalCache().SetLastContext(&localcache.LastContextConfig{
367-
Context: ctx.KubeClient().CurrentContext(),
368-
Namespace: ctx.KubeClient().Namespace(),
369-
})
370-
371-
err := ctx.Config().LocalCache().Save()
372-
if err != nil {
373-
return errors.Wrap(err, "save generated")
374-
}
375-
}
376-
}
377-
378-
return nil
379-
}
380-
381361
func runWithHooks(ctx devspacecontext.Context, command string, fn func() error) (err error) {
382362
err = hook.ExecuteHooks(ctx, nil, command+":before:execute")
383363
if err != nil {

pkg/devspace/kubectl/client.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,19 @@ func CheckKubeContext(client Client, localCache localcache.Cache, noWarning, aut
294294
}
295295
}
296296

297+
// Save changes to cache
298+
if localCache != nil {
299+
// Save changes to cache
300+
localCache.SetLastContext(&localcache.LastContextConfig{
301+
Context: currentConfigContext.Context,
302+
Namespace: currentConfigContext.Namespace,
303+
})
304+
err := localCache.Save()
305+
if err != nil {
306+
log.Warnf("Error saving cache: %v", err)
307+
}
308+
}
309+
297310
// Info messages
298311
log.Infof("Using namespace '%s'", ansi.Color(currentConfigContext.Namespace, "white+b"))
299312
log.Infof("Using kube context '%s'", ansi.Color(currentConfigContext.Context, "white+b"))

0 commit comments

Comments
 (0)