Skip to content

Commit c5aa51b

Browse files
authored
Merge pull request #2400 from mahendrabagul/pass-on-devspace-vars-to-plugin-env
Pass on devspace vars to plugin env
2 parents a644a99 + 8c65e47 commit c5aa51b

2 files changed

Lines changed: 25 additions & 1 deletion

File tree

cmd/root.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,9 @@ Additional run commands:
294294
rootCmd.AddCommand(NewPurgeCmd(f, globalFlags, rawConfig))
295295

296296
// Add plugin commands
297+
if rawConfig != nil && rawConfig.OriginalRawConfig != nil {
298+
plugin.AddDevspaceVarsToPluginEnv(rawConfig.OriginalRawConfig["vars"])
299+
}
297300
plugin.AddPluginCommands(rootCmd, plugins, "")
298301
variable.AddPredefinedVars(plugins)
299302
return rootCmd

pkg/devspace/plugin/plugin.go

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"github.com/ghodss/yaml"
99
"github.com/loft-sh/devspace/pkg/devspace/config/constants"
1010
"github.com/loft-sh/devspace/pkg/util/log"
11+
"sync"
1112

1213
"io"
1314
"os"
@@ -34,6 +35,9 @@ func init() {
3435
}
3536
}
3637

38+
var devspaceVars = map[string]string{}
39+
var devspaceVarsOnce sync.Once
40+
3741
type NewestVersionError struct {
3842
version string
3943
}
@@ -355,6 +359,23 @@ func Decode(encoded string) ([]byte, error) {
355359
return encoding.DecodeString(encoded)
356360
}
357361

362+
func AddDevspaceVarsToPluginEnv(vars interface{}) {
363+
devspaceVarsOnce.Do(func() {
364+
if vars != nil {
365+
devspaceVar, isMapStringInterface := vars.(map[string]interface{})
366+
if isMapStringInterface {
367+
for key, value := range devspaceVar {
368+
// only map[string]string will be processed, map[string]Variable will be skipped
369+
vString, isString := value.(string)
370+
if isString {
371+
devspaceVars[key] = vString
372+
}
373+
}
374+
}
375+
}
376+
})
377+
}
378+
358379
func AddPluginCommands(base *cobra.Command, plugins []Metadata, subCommand string) {
359380
for _, plugin := range plugins {
360381
pluginFolder := plugin.PluginFolder
@@ -373,7 +394,7 @@ func AddPluginCommands(base *cobra.Command, plugins []Metadata, subCommand strin
373394
newArgs := []string{}
374395
newArgs = append(newArgs, md.BaseArgs...)
375396
newArgs = append(newArgs, args...)
376-
return CallPluginExecutable(filepath.Join(pluginFolder, PluginBinary), newArgs, nil, os.Stdout)
397+
return CallPluginExecutable(filepath.Join(pluginFolder, PluginBinary), newArgs, devspaceVars, os.Stdout)
377398
},
378399
// This passes all the flags to the subcommand.
379400
DisableFlagParsing: true,

0 commit comments

Comments
 (0)