Skip to content

Commit f82606f

Browse files
committed
fix: commands predefined variable parsing
1 parent 91960ce commit f82606f

1 file changed

Lines changed: 11 additions & 9 deletions

File tree

cmd/run.go

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -109,12 +109,6 @@ func (cmd *RunCmd) RunRun(f factory.Factory, args []string) error {
109109

110110
// Set config root
111111
configOptions := cmd.ToConfigOptions()
112-
configOptions.Vars = append([]string{
113-
"devspace.namespace=" + cmd.Namespace,
114-
"DEVSPACE_NAMESPACE=" + cmd.Namespace,
115-
"devspace.context=" + cmd.KubeContext,
116-
"DEVSPACE_CONTEXT=" + cmd.KubeContext,
117-
}, configOptions.Vars...)
118112
configLoader, err := f.NewConfigLoader(cmd.ConfigPath)
119113
if err != nil {
120114
return err
@@ -127,7 +121,7 @@ func (cmd *RunCmd) RunRun(f factory.Factory, args []string) error {
127121
}
128122

129123
// load the config
130-
ctx, err := LoadCommandsConfig(configLoader, configOptions, f.GetLog())
124+
ctx, err := cmd.LoadCommandsConfig(f, configLoader, configOptions, f.GetLog())
131125
if err != nil {
132126
return err
133127
}
@@ -241,21 +235,29 @@ func ParseArgs(cobraCmd *cobra.Command, globalFlags *flags.GlobalFlags, log log.
241235
}
242236

243237
// LoadCommandsConfig loads the commands config
244-
func LoadCommandsConfig(configLoader loader.ConfigLoader, configOptions *loader.ConfigOptions, log log.Logger) (devspacecontext.Context, error) {
238+
func (cmd *RunCmd) LoadCommandsConfig(f factory.Factory, configLoader loader.ConfigLoader, configOptions *loader.ConfigOptions, log log.Logger) (devspacecontext.Context, error) {
245239
// load generated
246240
localCache, err := configLoader.LoadLocalCache()
247241
if err != nil {
248242
return nil, err
249243
}
250244

245+
// try to load client
246+
client, err := f.NewKubeClientFromContext(cmd.KubeContext, cmd.Namespace)
247+
if err != nil {
248+
log.Debugf("Unable to create new kubectl client: %v", err)
249+
client = nil
250+
}
251+
251252
// Parse commands
252-
commandsInterface, err := configLoader.LoadWithParser(context.Background(), localCache, nil, loader.NewCommandsParser(), configOptions, log)
253+
commandsInterface, err := configLoader.LoadWithParser(context.Background(), localCache, client, loader.NewCommandsParser(), configOptions, log)
253254
if err != nil {
254255
return nil, err
255256
}
256257

257258
// create context
258259
return devspacecontext.NewContext(context.Background(), commandsInterface.Variables(), log).
260+
WithKubeClient(client).
259261
WithConfig(commandsInterface), nil
260262
}
261263

0 commit comments

Comments
 (0)