Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: fix fill array with array in inputs #86

Merged
merged 2 commits into from
Nov 14, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion pkg/cue/model/value/value.go
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,16 @@ func (val *Value) fillRawByScript(x string, path string) error {
if err != nil {
return err
}
v, err := val.MakeValue(raw + "\n" + a.v)
assemblerVal, err := val.MakeValue(a.v)
if err != nil {
return errors.WithMessage(err, "remake assembler value")
}
// open the list for assembler value
assemblerRaw, err := assemblerVal.String(sets.ListOpen)
if err != nil {
return err
}
v, err := val.MakeValue(raw + "\n" + assemblerRaw)
if err != nil {
return errors.WithMessage(err, "remake value")
}
Expand Down
29 changes: 24 additions & 5 deletions pkg/cue/model/value/value_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -952,7 +952,26 @@ func TestFillByScript(t *testing.T) {
x: 100
}, {
name: "foo"
}]
}, ...]
}
`},
{
name: "insert array to array",
raw: `
a: b: c: [{x: 100}, {x: 101}, {x: 102}, ...]`,
path: "a.b.c[0].value",
v: `"foo"`,
expected: `a: {
b: {
c: [{
x: 100
value: "foo"
}, {
x: 101
}, {
x: 102
}, ...]
}
}
`,
},
Expand All @@ -967,9 +986,9 @@ func TestFillByScript(t *testing.T) {
y: [{
name: "key"
value: "foo"
}]
}, ...]
}
}]
}, ...]
}
`,
},
Expand Down Expand Up @@ -1052,7 +1071,7 @@ func TestFillByScript(t *testing.T) {
raw: `a: b: [{x: y:[{name: "key"}]}]`,
path: "a.b[0].x.y[0].value",
v: `foo`,
err: "remake value: a.b.x.y.value: reference \"foo\" not found",
err: "remake assembler value: a.b.x.y.value: reference \"foo\" not found",
},
{
name: "conflict merge",
Expand All @@ -1066,7 +1085,7 @@ func TestFillByScript(t *testing.T) {
raw: `a: b: [{x: y:[{name: "key"}]}]`,
path: "a.b[0].x.y[0].value",
v: `*+-`,
err: "remake value: expected operand, found '}'",
err: "remake assembler value: expected operand, found '}'",
},
}

Expand Down
3 changes: 2 additions & 1 deletion pkg/tasks/custom/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,8 @@ func (t *TaskLoader) makeTaskGenerator(templ string) (types.TaskGenerator, error
for _, hook := range options.PreStartHooks {
if err := hook(ctx, basicVal, wfStep); err != nil {
tracer.Error(err, "do preStartHook")
return v1alpha1.StepStatus{}, nil, errors.WithMessage(err, "do preStartHook")
exec.err(ctx, false, err, types.StatusReasonInput)
return exec.status(), exec.operation(), nil
}
}

Expand Down
10 changes: 8 additions & 2 deletions pkg/tasks/custom/task_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -263,9 +263,15 @@ close({
status, operation, err := run.Run(wfCtx, &types.TaskRunOptions{})
switch step.Name {
case "input-err":
r.Equal(err.Error(), "do preStartHook: parameter.score.x: conflicting values 100 and 101")
r.Equal(status.Message, "parameter.score.x: conflicting values 100 and 101")
r.Equal(operation.Waiting, false)
r.Equal(status.Phase, v1alpha1.WorkflowStepPhaseFailed)
r.Equal(status.Reason, types.StatusReasonInput)
case "input":
r.Equal(err.Error(), "do preStartHook: get input from [podIP]: failed to lookup value: var(path=podIP) not exist")
r.Equal(status.Message, "get input from [podIP]: failed to lookup value: var(path=podIP) not exist")
r.Equal(operation.Waiting, false)
r.Equal(status.Phase, v1alpha1.WorkflowStepPhaseFailed)
r.Equal(status.Reason, types.StatusReasonInput)
case "output-var-conflict":
r.Contains(status.Message, "conflict")
r.Equal(operation.Waiting, false)
Expand Down
2 changes: 2 additions & 0 deletions pkg/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,8 @@ const (
StatusReasonTerminate = "Terminate"
// StatusReasonParameter is the reason of the workflow progress condition which is ProcessParameter.
StatusReasonParameter = "ProcessParameter"
// StatusReasonInput is the reason of the workflow progress condition which is Input.
StatusReasonInput = "Input"
// StatusReasonOutput is the reason of the workflow progress condition which is Output.
StatusReasonOutput = "Output"
// StatusReasonFailedAfterRetries is the reason of the workflow progress condition which is FailedAfterRetries.
Expand Down