Skip to content

Commit

Permalink
Fix config source job does not propagate global args
Browse files Browse the repository at this point in the history
  • Loading branch information
mumoshu committed Apr 25, 2020
1 parent 2ccc99b commit 24620a9
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 8 deletions.
3 changes: 1 addition & 2 deletions examples/config/config.variant
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ job "config view" {
source job {
name = "getfoo"
args = {
app = opt.app
app = "app_override"
env = opt.env
param1 = "PARAM1"
}
Expand All @@ -64,7 +64,6 @@ job "config view" {
source job {
name = "getbar"
args = {
app = opt.app
env = opt.env
opt1 = "OPT1"
}
Expand Down
4 changes: 2 additions & 2 deletions examples/config/config_test.variant
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ test "app deploy" {
exitstatus = 0
err = ""
out = trimspace(<<EOS
{"app":"app1","bar":"OPT1","env":"prod","getfoo":"app1,prod,PARAM1","v":"app1prod"}
{"app":"app1","bar":"OPT1","env":"prod","getfoo":"app_override,prod,PARAM1","v":"app1prod"}
EOS
)
}
Expand All @@ -17,7 +17,7 @@ EOS
exitstatus = 0
err = ""
out = trimspace(<<EOS
{"app":"app2","bar":"OPT1","env":"prod","getfoo":"app2,prod,PARAM1","v":"app2"}
{"app":"app2","bar":"OPT1","env":"prod","getfoo":"app_override,prod,PARAM1","v":"app2"}
EOS
)
}
Expand Down
21 changes: 17 additions & 4 deletions pkg/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -593,7 +593,7 @@ func (app *App) Job(l *EventLogger, cmd string, args map[string]interface{}, opt
}
}

conf, err := app.getConfigs(jobEvalCtx, cc, j, "config", func(j JobSpec) []Config { return j.Configs }, nil)
conf, err := app.getConfigs(jobCtx, cc, j, "config", func(j JobSpec) []Config { return j.Configs }, nil)
if err != nil {
return nil, err
}
Expand All @@ -605,7 +605,7 @@ func (app *App) Job(l *EventLogger, cmd string, args map[string]interface{}, opt
return nil, fmt.Errorf("failed to initialize vals: %v", err)
}

sec, err := app.getConfigs(jobEvalCtx, cc, j, "secret", func(j JobSpec) []Config { return j.Secrets }, func(m map[string]interface{}) (map[string]interface{}, error) {
sec, err := app.getConfigs(jobCtx, cc, j, "secret", func(j JobSpec) []Config { return j.Secrets }, func(m map[string]interface{}) (map[string]interface{}, error) {
return secretRefsEvaluator.Eval(m)
})

Expand Down Expand Up @@ -1736,7 +1736,9 @@ func (app *App) createJobContext(cc *HCL2Config, j JobSpec, givenParams map[stri
}, nil
}

func (app *App) getConfigs(confCtx *hcl2.EvalContext, cc *HCL2Config, j JobSpec, confType string, f func(JobSpec) []Config, g func(map[string]interface{}) (map[string]interface{}, error)) (cty.Value, error) {
func (app *App) getConfigs(jobCtx *JobContext, cc *HCL2Config, j JobSpec, confType string, f func(JobSpec) []Config, g func(map[string]interface{}) (map[string]interface{}, error)) (cty.Value, error) {
confCtx := jobCtx.evalContext

confSpecs := append(append([]Config{}, f(cc.JobSpec)...), f(j)...)

confFields := map[string]cty.Value{}
Expand Down Expand Up @@ -1783,11 +1785,22 @@ func (app *App) getConfigs(confCtx *hcl2.EvalContext, cc *HCL2Config, j JobSpec,
return cty.NilVal, err
}

args, err := exprToGoMap(confCtx, source.Args)
localArgs, err := exprToGoMap(confCtx, source.Args)

if err != nil {
return cty.NilVal, err
}

args := map[string]interface{}{}

for k, v := range jobCtx.globalArgs {
args[k] = v
}

for k, v := range localArgs {
args[k] = v
}

res, err := app.run(nil, source.Name, args, args)
if err != nil {
return cty.NilVal, err
Expand Down

0 comments on commit 24620a9

Please sign in to comment.