Skip to content

Commit 12530f9

Browse files
authored
Merge pull request #2429 from FabianKramm/main
fix: commands predefined variable parsing
2 parents 659fc12 + 0e145f5 commit 12530f9

2 files changed

Lines changed: 18 additions & 27 deletions

File tree

cmd/init.go

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -506,15 +506,17 @@ echo 'Anyone using this project can invoke it via "devspace run migrate-db"'`,
506506
// Add pipeline: dev
507507
config.Pipelines["dev"] = &latest.Pipeline{
508508
Run: `run_dependencies --all # 1. Deploy any projects this project needs (see "dependencies")
509-
create_deployments --all # 2. Deploy Helm charts and manifests specfied as "deployments"
510-
start_dev ` + imageName + ` # 3. Start dev mode "` + imageName + `" (see "dev" section)`,
509+
ensure_pull_secrets --all # 2. Ensure pull secrets
510+
create_deployments --all # 3. Deploy Helm charts and manifests specfied as "deployments"
511+
start_dev ` + imageName + ` # 4. Start dev mode "` + imageName + `" (see "dev" section)`,
511512
}
512513

513514
// Add pipeline: dev
514515
config.Pipelines["deploy"] = &latest.Pipeline{
515516
Run: `run_dependencies --all # 1. Deploy any projects this project needs (see "dependencies")
516-
build_images --all -t $(git describe --always) # 2. Build, tag (git commit hash) and push all images (see "images")
517-
create_deployments --all # 3. Deploy Helm charts and manifests specfied as "deployments"`,
517+
ensure_pull_secrets --all # 2. Ensure pull secrets
518+
build_images --all -t $(git describe --always) # 3. Build, tag (git commit hash) and push all images (see "images")
519+
create_deployments --all # 4. Deploy Helm charts and manifests specfied as "deployments"`,
518520
}
519521

520522
// Save config
@@ -661,19 +663,6 @@ func annotateConfig(configPath string) error {
661663
# tag: v1.0.0
662664
# ui:
663665
# path: ./ui # Path-based dependencies (for monorepos)
664-
`)...)
665-
666-
annotatedConfig = append(annotatedConfig, []byte(`
667-
# Customize local registry settings
668-
# localRegistry:
669-
# enabled: true # Always use local registry, remove to only use the local registry when required
670-
# name: registry
671-
# namespace: ${devspace.namespace} # Uses the current kube context's namespace (can be removed)
672-
# image: registry:2.8.1
673-
# port: 5000
674-
# persistence:
675-
# enabled: false
676-
# size: 5Gi
677666
`)...)
678667

679668
err = os.WriteFile(configPath, annotatedConfig, os.ModePerm)
@@ -784,7 +773,7 @@ func (cmd *InitCmd) addDevConfig(config *latest.Config, imageName, image string,
784773
Command: "helm",
785774
},
786775
{
787-
Command: "git",
776+
GitCredentials: true,
788777
},
789778
}...)
790779

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)