-
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
change ResultRef.ResultsIndex from int to *int #7460
Conversation
6ad3693
to
42f0847
Compare
The following is the coverage report on the affected files.
|
The following is the coverage report on the affected files.
|
if looksLikeResultRef(substitutionExpression) { | ||
subExpressions := strings.Split(substitutionExpression, ".") | ||
// For string result: tasks.<taskName>.results.<stringResultName> | ||
// For array result: tasks.<taskName>.results.<arrayResultName>[index] | ||
if len(subExpressions) == 4 { | ||
resultName, stringIdx := ParseResultName(subExpressions[3]) | ||
if stringIdx != "" { | ||
if stringIdx != "" && stringIdx != "*" { |
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.
(just checking my understanding here 🤔 ) Is this fully related with the pointer change?
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.
It is related. 😂
We only want to set non-nil value of result index for the case of array indexing. Otherwise we will return 0
in the case of [*]
reference.That's the cause of the linked bug
// Valid Example 3: | ||
// - Input: tasks.myTask.results.anArrayResult[1] | ||
// - Output: "myTask", "anArrayResult", 1, "", nil | ||
// Valid Example 4: | ||
// - Input: tasks.myTask.results.Result[*] |
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.
Maybe out call here that the this ouput is when the input references an empty array?
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, this is the case of referencing a whole array or object results, they may not be empty. I can clarify this in the docstring
@@ -28,6 +28,7 @@ import ( | |||
) | |||
|
|||
func TestNewResultReference(t *testing.T) { | |||
idx := 1 |
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.
Does this really covers the change? IIUC we need a test case that references an empty array with [*] and test the ResultIndex
is 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.
Oh thanks, I think I forgot to add a test case here
Sorry I just recalled that it is included in the current test, I will update a bit to show that we will return nil
// Valid Example 3: | ||
// - Input: tasks.myTask.results.anArrayResult[1] | ||
// - Output: "myTask", "anArrayResult", 1, "", nil | ||
// Valid Example 4: | ||
// - Input: tasks.myTask.results.Result[*] |
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.
same as above
This commit closes 7392. When we introduced array results, we added validation funciton to check if the result reference is out of the array bound, in the cases of refercing a whole array and that array is empty, the resolved array index is 0, so the validation will error. Since the resolved index is only used when array indexing references exist, it is an optional field for ResultRef so we should change it to a pointer. Signed-off-by: Yongxuan Zhang [email protected]
42f0847
to
238f101
Compare
/lgtm |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: JeromeJu 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 |
Changes
This commit closes #7392. When we introduced array results, we added validation funciton to check if the result reference is out of the array bound, in the cases of refercing a whole array and that array is empty, the resolved array index is 0, so the validation will error. Since the resolved index is only used when array indexing references exist, it is an optional field for ResultRef so we should change it to a pointer.
This is not an API change although ResultRef is in our API pkg, but it is not used in any of our APIs and it is only used in controller code.
/kind bug
Signed-off-by: Yongxuan Zhang [email protected]
Submitter Checklist
As the author of this PR, please check off the items in this checklist:
/kind <type>
. Valid types are bug, cleanup, design, documentation, feature, flake, misc, question, tepRelease Notes