Skip to content

Commit 14f80a0

Browse files
committed
feat: reintroduce --switch-context
1 parent 229a4d3 commit 14f80a0

File tree

11 files changed

+71
-58
lines changed

11 files changed

+71
-58
lines changed

cmd/analyze.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ func (cmd *AnalyzeCmd) RunAnalyze(f factory.Factory, cobraCmd *cobra.Command, ar
8686

8787
// If the current kube context or namespace is different than old,
8888
// show warnings and reset kube client if necessary
89-
client, err = kubectl.CheckKubeContext(client, localCache, cmd.NoWarn, log)
89+
client, err = kubectl.CheckKubeContext(client, localCache, cmd.NoWarn, cmd.SwitchContext, log)
9090
if err != nil {
9191
return err
9292
}

cmd/deploy.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ func prepare(ctx context.Context, f factory.Factory, configOptions *loader.Confi
213213

214214
// If the current kube context or namespace is different than old,
215215
// show warnings and reset kube client if necessary
216-
client, err = kubectl.CheckKubeContext(client, localCache, globalFlags.NoWarn, log)
216+
client, err = kubectl.CheckKubeContext(client, localCache, globalFlags.NoWarn, globalFlags.SwitchContext, log)
217217
if err != nil {
218218
return nil, err
219219
}

cmd/flags/flags.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ type GlobalFlags struct {
1717
Profiles []string
1818
ProfileRefresh bool
1919
DisableProfileActivation bool
20+
SwitchContext bool
2021
ConfigPath string
2122
Vars []string
2223

@@ -54,6 +55,7 @@ func SetGlobalFlags(flags *flag.FlagSet) *GlobalFlags {
5455
flags.StringSliceVarP(&globalFlags.Profiles, "profile", "p", []string{}, "The DevSpace profiles to apply. Multiple profiles are applied in the order they are specified")
5556
flags.BoolVar(&globalFlags.ProfileRefresh, "profile-refresh", false, "If true will pull and re-download profile parent sources")
5657
flags.BoolVar(&globalFlags.DisableProfileActivation, "disable-profile-activation", false, "If true will ignore all profile activations")
58+
flags.BoolVarP(&globalFlags.SwitchContext, "switch-context", "s", false, "Switches and uses the last kube context and namespace that was used to deploy the DevSpace project")
5759
flags.StringVarP(&globalFlags.Namespace, "namespace", "n", "", "The kubernetes namespace to use")
5860
flags.StringVar(&globalFlags.KubeContext, "kube-context", "", "The kubernetes context to use")
5961
flags.StringSliceVar(&globalFlags.Vars, "var", []string{}, "Variables to override during execution (e.g. --var=MYVAR=MYVALUE)")

cmd/list/deployments.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ func (cmd *deploymentsCmd) RunDeploymentsStatus(f factory.Factory, cobraCmd *cob
8080

8181
// If the current kube context or namespace is different than old,
8282
// show warnings and reset kube client if necessary
83-
client, err = kubectl.CheckKubeContext(client, localCache, cmd.NoWarn, logger)
83+
client, err = kubectl.CheckKubeContext(client, localCache, cmd.NoWarn, cmd.SwitchContext, logger)
8484
if err != nil {
8585
return err
8686
}

cmd/list/namespaces.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ func (cmd *namespacesCmd) RunListNamespaces(f factory.Factory, cobraCmd *cobra.C
7171

7272
// If the current kube context or namespace is different than old,
7373
// show warnings and reset kube client if necessary
74-
client, err = kubectl.CheckKubeContext(client, localCache, cmd.NoWarn, logger)
74+
client, err = kubectl.CheckKubeContext(client, localCache, cmd.NoWarn, cmd.SwitchContext, logger)
7575
if err != nil {
7676
return err
7777
}

cmd/open.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ func (cmd *OpenCmd) RunOpen(f factory.Factory) error {
129129

130130
// If the current kube context or namespace is different than old,
131131
// show warnings and reset kube client if necessary
132-
client, err = kubectl.CheckKubeContext(client, localCache, cmd.NoWarn, cmd.log)
132+
client, err = kubectl.CheckKubeContext(client, localCache, cmd.NoWarn, cmd.SwitchContext, cmd.log)
133133
if err != nil {
134134
return err
135135
}

cmd/reset/pods.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ func (cmd *podsCmd) RunResetPods(f factory.Factory, cobraCmd *cobra.Command, arg
7878

7979
// If the current kube context or namespace is different than old,
8080
// show warnings and reset kube client if necessary
81-
client, err = kubectl.CheckKubeContext(client, localCache, cmd.NoWarn, cmd.log)
81+
client, err = kubectl.CheckKubeContext(client, localCache, cmd.NoWarn, cmd.SwitchContext, cmd.log)
8282
if err != nil {
8383
return err
8484
}

cmd/restart.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ func (cmd *RestartCmd) Run(f factory.Factory) error {
108108

109109
// If the current kube context or namespace is different than old,
110110
// show warnings and reset kube client if necessary
111-
client, err = kubectl.CheckKubeContext(client, localCache, cmd.NoWarn, cmd.log)
111+
client, err = kubectl.CheckKubeContext(client, localCache, cmd.NoWarn, cmd.SwitchContext, cmd.log)
112112
if err != nil {
113113
return err
114114
}

cmd/sync.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ func (cmd *SyncCmd) Run(f factory.Factory) error {
163163

164164
// If the current kube context or namespace is different than old,
165165
// show warnings and reset kube client if necessary
166-
client, err = kubectl.CheckKubeContext(client, localCache, cmd.NoWarn, logger)
166+
client, err = kubectl.CheckKubeContext(client, localCache, cmd.NoWarn, cmd.SwitchContext, logger)
167167
if err != nil {
168168
return err
169169
}

cmd/ui.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ func (cmd *UICmd) RunUI(f factory.Factory) error {
156156

157157
// If the current kube context or namespace is different than old,
158158
// show warnings and reset kube client if necessary
159-
client, err = kubectl.CheckKubeContext(client, localCache, cmd.NoWarn, cmd.log)
159+
client, err = kubectl.CheckKubeContext(client, localCache, cmd.NoWarn, cmd.SwitchContext, cmd.log)
160160
if err != nil {
161161
return err
162162
}

0 commit comments

Comments
 (0)