-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
[TEP-0076]Support Results Array Indexing #4911
[TEP-0076]Support Results Array Indexing #4911
Conversation
The following is the coverage report on the affected files.
|
dc30ce8
to
f41d7ea
Compare
The following is the coverage report on the affected files.
|
/assign ywluogg |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mostly LGTM. Please fix those comments for test cases
// variableSubstitutionFormat matches format like $result.resultname, $result.resultname[int] and $result.resultname[*] | ||
variableSubstitutionFormat = `\$\([_a-zA-Z0-9.-]+(\.[_a-zA-Z0-9.-]+)*(\[([0-9])*\*?\])?\)` | ||
// excludeArrayIndexing will replace all `[int]` and `[*]` for parseExpression to extract result name | ||
excludeArrayIndexing = `\[([0-9])*\*?\]` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Discussed offline about renaming
The following is the coverage report on the affected files.
|
222b662
to
9286433
Compare
The following is the coverage report on the affected files.
|
9286433
to
04e815a
Compare
The following is the coverage report on the affected files.
|
04e815a
to
4d2896c
Compare
The following is the coverage report on the affected files.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you also add examples into the release notes?
}, { | ||
name: "Test array indexing result substitution out of bound - params", | ||
resolvedResultRefs: ResolvedResultRefs{{ | ||
Value: *v1beta1.NewArrayOrString("arrayResultValueOne", "arrayResultValueTwo"), | ||
ResultReference: v1beta1.ResultRef{ | ||
PipelineTask: "aTask", | ||
Result: "a.Result", | ||
}, | ||
FromTaskRun: "aTaskRun", | ||
}}, | ||
targets: PipelineRunState{{ | ||
PipelineTask: &v1beta1.PipelineTask{ | ||
Name: "bTask", | ||
TaskRef: &v1beta1.TaskRef{Name: "bTask"}, | ||
Params: []v1beta1.Param{{ | ||
Name: "bParam", | ||
Value: *v1beta1.NewArrayOrString(`$(tasks.aTask.results["a.Result"][3])`), | ||
}}, | ||
}, | ||
}}, | ||
want: PipelineRunState{{ | ||
PipelineTask: &v1beta1.PipelineTask{ | ||
Name: "bTask", | ||
TaskRef: &v1beta1.TaskRef{Name: "bTask"}, | ||
Params: []v1beta1.Param{{ | ||
Name: "bParam", | ||
// index validation is done in ResolveResultRefs() before ApplyTaskResults() | ||
Value: *v1beta1.NewArrayOrString(`$(tasks.aTask.results["a.Result"][3])`), | ||
}}, | ||
}, | ||
}}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah adding the tests in resultresolution_test should be good enough. But this test case makes it clear that out of bound cases here are handled in this specific way. I think keeping this case is fine. You can resolve this comment
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: vdemeester, ywluogg The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
/lgtm |
@ywluogg: changing LGTM is restricted to collaborators In response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
Yes! I will add release notes soon |
taskSpec: | ||
results: | ||
- name: array-results | ||
description: The array resluts |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there's a typo here and in the name of this file
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
isn't specifying type
necessary here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there's a typo here and in the name of this file
Thank you!
isn't specifying type necessary here?
Yes, I will add this, thanks for catching! It is not failing in this pr because the validation we discussed is implemented in this pr #4920
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
filename still needs to be fixed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh sorry my bad!
@@ -306,8 +306,10 @@ func (t *ResolvedPipelineRunTask) skipBecauseResultReferencesAreMissing(facts *P | |||
if t.checkParentsDone(facts) && t.hasResultReferences() { | |||
resolvedResultRefs, pt, err := ResolveResultRefs(facts.State, PipelineRunState{t}) | |||
rprt := facts.State.ToMap()[pt] | |||
if err != nil && (t.IsFinalTask(facts) || rprt.Skip(facts).SkippingReason == v1beta1.WhenExpressionsSkip) { | |||
return true | |||
if rprt != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what's the reason for this change? it doesn't look related to results
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes it is not so straightforward, not sure if I'm doing here is correct or there could be better solutions.
We need to validate if the referred index is out of bound of results array, and it is done in ResolveResultRefs
, so the ResolveResultRefs
will return err when out of bound and there are cases that the rprt is nil, so it will fail here if I don't add this check.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And in this case of this function we will still return true even we got err here. But it will return our err in another function runNextSchedulableTask
examples/v1beta1/pipelineruns/alpha/pipelinerun-array-resluts-indexing.yaml
Outdated
Show resolved
Hide resolved
@@ -22,6 +22,9 @@ For instructions on using variable substitutions see the relevant section of [th | |||
| `tasks.<taskName>.results.<resultName>` | The value of the `Task's` result. Can alter `Task` execution order within a `Pipeline`.) | | |||
| `tasks.<taskName>.results['<resultName>']` | (see above)) | | |||
| `tasks.<taskName>.results["<resultName>"]` | (see above)) | | |||
| `tasks.<taskName>.results.<resultName>[i]` | The ith value of the `Task's` array result. Can alter `Task` execution order within a `Pipeline`.) | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about start notation - tasks.<taskName>.results.<resultName>[*]
? is that something supported in this context?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
star notation is not supported in this pr, it is in this one #4908
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
star notation is used to refer the whole array while this pr focus on the reference of array elements via index
4d2896c
to
0dcdf25
Compare
The following is the coverage report on the affected files.
|
/retest |
1 similar comment
/retest |
happy to LGTM but @pritidesai just want to make sure your concerns are addressed first |
Yeah sure! I will wait for @pritidesai's reviews |
0dcdf25
to
2e0298a
Compare
The following is the coverage report on the affected files.
|
/retest |
Link this to #4723 |
/lgtm |
/retest |
1 similar comment
/retest |
This is part of work in TEP-0076. This commit provides the support to refer array indexing results. Previous this commit we support emitting array results so users can write array results to task level, but we cannot pass array results via index between tasks within one pipeline. This commit adds the support for this.
2e0298a
to
2ebdbff
Compare
The following is the coverage report on the affected files.
|
/lgtm |
func parseExpression(substitutionExpression string) (string, string, int, error) { | ||
subExpressions := strings.Split(substitutionExpression, ".") | ||
if len(subExpressions) != 4 || subExpressions[0] != ResultTaskPart || subExpressions[2] != ResultResultPart { | ||
return "", "", fmt.Errorf("Must be of the form %q", resultExpressionFormat) | ||
return "", "", 0, fmt.Errorf("Must be of the form %q", resultExpressionFormat) | ||
} | ||
return subExpressions[1], subExpressions[3], nil | ||
|
||
stringIdx := strings.TrimSuffix(strings.TrimPrefix(arrayIndexingRegex.FindString(subExpressions[3]), "["), "]") | ||
subExpressions[3] = arrayIndexingRegex.ReplaceAllString(subExpressions[3], "") | ||
if stringIdx != "" { | ||
intIdx, _ := strconv.Atoi(stringIdx) | ||
return subExpressions[1], subExpressions[3], intIdx, nil | ||
} | ||
return subExpressions[1], subExpressions[3], 0, nil |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When the index part in bracket for array or the whole expression is invalid, or it's a reference to a string result, wouldn't it make more sense if we set the third return value to be -1
to indicate it's not array or invalid value for index?
/kind feature |
Changes
This is part of work in TEP-0076.
This commit provides the support to refer array indexing results.
Previous this commit we support emitting array results so users can
write array results to task level, but we cannot pass array results via
index between tasks within one pipeline. This commit adds the support for this.
Submitter Checklist
As the author of this PR, please check off the items in this checklist:
functionality, content, code)
(if there are no user facing changes, use release note "NONE")
Release Notes